summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2026-08-20 06:18:05 +0200
committerMel <mel@rnrd.eu>2026-08-20 06:18:05 +0200
commitb52c860a7b1d3f57abc442bb8c1257f228d49536 (patch)
tree524865405ba3b972d684ded62d7ab67547bb9040 /config.go
downloadddnnss-b52c860a7b1d3f57abc442bb8c1257f228d49536.tar.zst
ddnnss-b52c860a7b1d3f57abc442bb8c1257f228d49536.zip
ddnnss
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'config.go')
-rw-r--r--config.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/config.go b/config.go
new file mode 100644
index 0000000..9cd614d
--- /dev/null
+++ b/config.go
@@ -0,0 +1,53 @@
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+ "os"
+
+ "git.rnrd.eu/ddnnss/provider"
+ "git.rnrd.eu/ddnnss/source"
+)
+
+// a record target which we will try to update
+// via the provider!
+type Record struct {
+ Zone string `json:"zone"`
+ Name string `json:"name"`
+ Type provider.RecordType `json:"type"`
+ Provider string `json:"provider"`
+ Source string `json:"source"`
+}
+
+type Config struct {
+ Records []Record `json:"records"`
+ Providers map[string]provider.Config `json:"providers"`
+ Sources map[string]source.Config `json:"sources"`
+}
+
+func LoadConfig(path string) (*Config, error) {
+ raw, err := os.ReadFile(path)
+ if err != nil {
+ return nil, err
+ }
+
+ var cfg Config
+ if err := json.Unmarshal(raw, &cfg); err != nil {
+ return nil, fmt.Errorf("%s: %w", path, err)
+ }
+
+ for i, r := range cfg.Records {
+ switch r.Type {
+ case provider.TypeA, provider.TypeAAAA:
+ default:
+ return nil, fmt.Errorf("record %d: type must be A or AAAA", i)
+ }
+ if _, ok := cfg.Providers[r.Provider]; !ok {
+ return nil, fmt.Errorf("record %d: unknown provider %q", i, r.Provider)
+ }
+ if _, ok := cfg.Sources[r.Source]; !ok {
+ return nil, fmt.Errorf("record %d: unknown source %q", i, r.Source)
+ }
+ }
+ return &cfg, nil
+}