You've already forked dyndns-client
Initial Commit
This commit is contained in:
42
pkg/types/config.go
Normal file
42
pkg/types/config.go
Normal file
@ -0,0 +1,42 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Ifaces []string `json:"interfaces"`
|
||||
Zones map[string]*Zone `json:"zones"`
|
||||
TSIGKeys map[string]*TSIGKey `json:"tsig-keys"`
|
||||
}
|
||||
|
||||
func (c *Config) Validate() error {
|
||||
if len(c.Zones) <= 0 {
|
||||
return fmt.Errorf("no dns zones configured")
|
||||
}
|
||||
|
||||
if len(c.Ifaces) <= 0 {
|
||||
return fmt.Errorf("no interfaces configured")
|
||||
}
|
||||
|
||||
ZONE_LOOP:
|
||||
for _, zone := range c.Zones {
|
||||
if !govalidator.IsIP(zone.DNSServer) && !govalidator.IsDNSName(zone.DNSServer) {
|
||||
return fmt.Errorf("invalid dns server %v", zone.DNSServer)
|
||||
}
|
||||
|
||||
if !govalidator.IsDNSName(zone.Name) {
|
||||
return fmt.Errorf("invalid dns zone name %v", zone.Name)
|
||||
}
|
||||
|
||||
for _, tsigkey := range c.TSIGKeys {
|
||||
if tsigkey.Name == zone.TSIGKeyName {
|
||||
continue ZONE_LOOP
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("no matching tsigkey found for zone %v", zone.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
7
pkg/types/tsigkey.go
Normal file
7
pkg/types/tsigkey.go
Normal file
@ -0,0 +1,7 @@
|
||||
package types
|
||||
|
||||
type TSIGKey struct {
|
||||
Algorithm string `json:"algorithm"`
|
||||
Name string `json:"name"`
|
||||
Secret string `json:"secret"`
|
||||
}
|
7
pkg/types/zone.go
Normal file
7
pkg/types/zone.go
Normal file
@ -0,0 +1,7 @@
|
||||
package types
|
||||
|
||||
type Zone struct {
|
||||
DNSServer string `json:"dns-server"`
|
||||
Name string `json:"name"`
|
||||
TSIGKeyName string `json:"tsig-key"`
|
||||
}
|
Reference in New Issue
Block a user