You've already forked ddns-updater
Refactor: Moved all under internal.
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
FEAT: Directadmin provider is now working
This commit is contained in:
@@ -12,29 +12,32 @@ const (
|
||||
defaultCheckInterval = 5 * 60
|
||||
envKeyDnsToCheck = "DNS_NAMES"
|
||||
envKeyPublicIpResolverTag = "PUBLIC_IP_RESOLVER"
|
||||
envKeyDNSProviderTag = "DNS_PROVIDER"
|
||||
envKeyPublicDNSServer = "PUBLIC_DNS_SERVER"
|
||||
envKeyCloudflareApiKey = "CLOUDFLARE_API_KEY"
|
||||
envKeyCloudflareZone = "CLOUDFLARE_ZONE"
|
||||
envKeyDirectadminUser = "DA_USER"
|
||||
envKeyDirectadminKey = "DA_LOGIN_KEY"
|
||||
envKeyDirectadminUrl = "DA_LOGIN_URL"
|
||||
envKeyDirectadminKey = "DA_KEY"
|
||||
envKeyDirectadminUrl = "DA_URL"
|
||||
envKeyOnChangeComment = "ON_CHANGE_COMMENT"
|
||||
envKeyCheckIntervalSeconds = "CHECK_INTERVAL_SECONDS"
|
||||
envKeyNotifiers = "NOTIFIERS"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DnsRecordsToCheck []string
|
||||
PublicIpResolverTag string
|
||||
DNSProviderTag string
|
||||
DirectadminUsername string
|
||||
DirectadminKey string
|
||||
DirectadminUrl string
|
||||
ApiToken string
|
||||
WebhookToken string
|
||||
CloudflareZone string
|
||||
OnChangeComment string
|
||||
Notifiers []string
|
||||
CheckInterval time.Duration
|
||||
DnsRecordsToCheck []string
|
||||
PublicIpResolverTag string
|
||||
PublicDNSServer string
|
||||
DNSProviderTag string
|
||||
DirectadminUsername string
|
||||
DirectadminKey string
|
||||
DirectadminUrl string
|
||||
ApiToken string
|
||||
WebhookToken string
|
||||
CloudflareZone string
|
||||
CloudflareOnChangeComment string
|
||||
Notifiers []string
|
||||
CheckInterval time.Duration
|
||||
}
|
||||
|
||||
func (c Config) Validate() error {
|
||||
@@ -44,21 +47,17 @@ func (c Config) Validate() error {
|
||||
return fmt.Errorf("empty api token env key %s", envKeyCloudflareApiKey)
|
||||
}
|
||||
|
||||
// if c.CloudflareZone == "" {
|
||||
// return fmt.Errorf("empty zone in env key %s", envKeyCloudflareZone)
|
||||
// }
|
||||
|
||||
case "directadmin":
|
||||
if c.DirectadminUrl == "" {
|
||||
return fmt.Errorf("empty DirectAdmin URL env key %s", envKeyDirectadminUrl)
|
||||
}
|
||||
|
||||
if c.DirectadminUsername == "" {
|
||||
return fmt.Errorf("empty Username in env key %s", envKeyDirectadminUser)
|
||||
return fmt.Errorf("empty DirectAdmin Username in env key %s", envKeyDirectadminUser)
|
||||
}
|
||||
|
||||
if c.DirectadminKey == "" {
|
||||
return fmt.Errorf("empty Login Key in env key %s", envKeyDirectadminKey)
|
||||
return fmt.Errorf("empty DirectAdmin Login Key in env key %s", envKeyDirectadminKey)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,16 +76,26 @@ func NewConfig() Config {
|
||||
}
|
||||
|
||||
return Config{
|
||||
DnsRecordsToCheck: parseCommaDelimited(os.Getenv(envKeyDnsToCheck)),
|
||||
PublicIpResolverTag: os.Getenv(envKeyPublicIpResolverTag),
|
||||
ApiToken: os.Getenv(envKeyCloudflareApiKey),
|
||||
DirectadminUsername: os.Getenv(envKeyDirectadminUser),
|
||||
DirectadminKey: os.Getenv(envKeyDirectadminKey),
|
||||
DirectadminUrl: os.Getenv(envKeyDirectadminUrl),
|
||||
CloudflareZone: os.Getenv(envKeyCloudflareZone),
|
||||
OnChangeComment: os.Getenv(envKeyOnChangeComment),
|
||||
Notifiers: parseCommaDelimited(os.Getenv(envKeyNotifiers)),
|
||||
CheckInterval: time.Duration(checkInterval) * time.Second,
|
||||
WebhookToken: os.Getenv("WEBHOOK_TOKEN"),
|
||||
DnsRecordsToCheck: parseCommaDelimited(os.Getenv(envKeyDnsToCheck)),
|
||||
DNSProviderTag: getEnvDefault(envKeyDNSProviderTag, "cloudflare"),
|
||||
PublicDNSServer: getEnvDefault(envKeyPublicDNSServer, "1.1.1.1"),
|
||||
PublicIpResolverTag: getEnvDefault(envKeyPublicIpResolverTag, "icanhazip"),
|
||||
ApiToken: os.Getenv(envKeyCloudflareApiKey),
|
||||
CloudflareZone: os.Getenv(envKeyCloudflareZone),
|
||||
CloudflareOnChangeComment: os.Getenv(envKeyOnChangeComment),
|
||||
DirectadminUsername: os.Getenv(envKeyDirectadminUser),
|
||||
DirectadminKey: os.Getenv(envKeyDirectadminKey),
|
||||
DirectadminUrl: os.Getenv(envKeyDirectadminUrl),
|
||||
Notifiers: parseCommaDelimited(os.Getenv(envKeyNotifiers)),
|
||||
CheckInterval: time.Duration(checkInterval) * time.Second,
|
||||
WebhookToken: os.Getenv("WEBHOOK_TOKEN"),
|
||||
}
|
||||
}
|
||||
|
||||
func getEnvDefault(key, fallback string) string {
|
||||
value, exists := os.LookupEnv(key)
|
||||
if !exists {
|
||||
value = fallback
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user