Initial Notifiers implementation

This commit is contained in:
mkelcik
2023-05-04 11:44:27 +02:00
parent 2d52cbe920
commit ffd5253f59
7 changed files with 211 additions and 8 deletions

View File

@@ -17,6 +17,7 @@ const (
envKeyCloudflareZone = "CLOUDFLARE_ZONE"
envKeyOnChangeComment = "ON_CHANGE_COMMENT"
envKeyCheckIntervalSeconds = "CHECK_INTERVAL_SECONDS"
envKeyNotifiers = "NOTIFIERS"
)
type Config struct {
@@ -25,6 +26,7 @@ type Config struct {
ApiToken string
CloudflareZone string
OnChangeComment string
Notifiers []string
CheckInterval time.Duration
}
@@ -52,11 +54,12 @@ func NewConfig() Config {
}
return Config{
DnsRecordsToCheck: parseDNSToCheck(os.Getenv(envKeyDnsToCheck)),
DnsRecordsToCheck: parseCommaDelimited(os.Getenv(envKeyDnsToCheck)),
PublicIpResolverTag: os.Getenv(envKeyPublicIpResolverTag),
ApiToken: os.Getenv(envKeyCloudflareApiKey),
CloudflareZone: os.Getenv(envKeyCloudflareZone),
OnChangeComment: os.Getenv(envKeyOnChangeComment),
Notifiers: parseCommaDelimited(os.Getenv(envKeyNotifiers)),
CheckInterval: time.Duration(checkInterval) * time.Second,
}
}

View File

@@ -2,10 +2,10 @@ package internal
import "strings"
func parseDNSToCheck(data string) []string {
func parseCommaDelimited(data string) []string {
out := make([]string, 0, strings.Count(data, ",")+1)
for _, dns := range strings.Split(data, ",") {
if w := strings.TrimSpace(dns); w != "" {
for _, item := range strings.Split(data, ",") {
if w := strings.TrimSpace(item); w != "" {
out = append(out, w)
}
}

View File

@@ -38,8 +38,8 @@ func Test_parseDNSToCheck(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := parseDNSToCheck(tt.args.data); !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseDNSToCheck() = %v, want %v", got, tt.want)
if got := parseCommaDelimited(tt.args.data); !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseCommaDelimited() = %v, want %v", got, tt.want)
}
})
}