Skip to content

Commit

Permalink
Restore validate DDNS provider function
Browse files Browse the repository at this point in the history
  • Loading branch information
uubulb committed Apr 25, 2024
1 parent f607362 commit d5f5d57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions service/singleton/ddns.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,15 @@ func GetDDNSProviderFromProfile(profileName string) (ddns2.Provider, error) {
}
return ddns2.ProviderDummy{}, errors.New(fmt.Sprintf("无法找到配置的DDNS提供者%s", profile.Provider))
}

func ValidateDDNSProvidersFromProfiles() error {
validProviders := map[string]bool{"webhook": true, "dummy": true, "cloudflare": true, "tencentcloud": true}
providers := make(map[string]string)
for profileName, profile := range Conf.DDNS.Profiles {
if _, ok := validProviders[profile.Provider]; !ok {
return errors.New(fmt.Sprintf("无法找到配置的DDNS提供者%s", profile.Provider))
}
providers[profileName] = profile.Provider
}
return nil
}
9 changes: 9 additions & 0 deletions service/singleton/singleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ func InitConfigFromPath(path string) {

// ValidateConfig 验证配置文件有效性
func ValidateConfig() {
var err error
if Conf.DDNS.Provider == "" {
err = ValidateDDNSProvidersFromProfiles()
} else {
_, err = GetDDNSProviderFromString(Conf.DDNS.Provider)
}
if err != nil {
panic(err)
}
if Conf.DDNS.Enable {
if Conf.DDNS.MaxRetries < 1 || Conf.DDNS.MaxRetries > 10 {
panic(fmt.Errorf("DDNS.MaxRetries值域为[1, 10]的整数, 当前为 %d", Conf.DDNS.MaxRetries))
Expand Down

0 comments on commit d5f5d57

Please sign in to comment.