diff options
author | Janos Guljas <janos@resenje.org> | 2017-12-19 18:47:26 +0800 |
---|---|---|
committer | Janos Guljas <janos@resenje.org> | 2017-12-19 18:47:26 +0800 |
commit | dd5ae4fd8e28d1ce618668d213e81781ef59f067 (patch) | |
tree | ce60d5360d86e373b70e22626fa81635f3e8bb6a /cmd/swarm/config.go | |
parent | 0d6a735a72340130acd6b7e536dad5d8bee40d84 (diff) | |
download | go-tangerine-dd5ae4fd8e28d1ce618668d213e81781ef59f067.tar go-tangerine-dd5ae4fd8e28d1ce618668d213e81781ef59f067.tar.gz go-tangerine-dd5ae4fd8e28d1ce618668d213e81781ef59f067.tar.bz2 go-tangerine-dd5ae4fd8e28d1ce618668d213e81781ef59f067.tar.lz go-tangerine-dd5ae4fd8e28d1ce618668d213e81781ef59f067.tar.xz go-tangerine-dd5ae4fd8e28d1ce618668d213e81781ef59f067.tar.zst go-tangerine-dd5ae4fd8e28d1ce618668d213e81781ef59f067.zip |
cmd/swarm: add validation for EnsAPIs configuration parameter
Diffstat (limited to 'cmd/swarm/config.go')
-rw-r--r-- | cmd/swarm/config.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/cmd/swarm/config.go b/cmd/swarm/config.go index c66a2a4fe..566b00f48 100644 --- a/cmd/swarm/config.go +++ b/cmd/swarm/config.go @@ -102,6 +102,8 @@ func buildConfig(ctx *cli.Context) (config *bzzapi.Config, err error) { config = envVarsOverride(config) //override settings provided by command line config = cmdLineOverride(config, ctx) + //validate configuration parameters + err = validateConfig(config) return } @@ -319,6 +321,39 @@ func checkDeprecated(ctx *cli.Context) { } } +//validate configuration parameters +func validateConfig(cfg *bzzapi.Config) (err error) { + for _, ensAPI := range cfg.EnsAPIs { + if ensAPI != "" { + if err := validateEnsAPIs(ensAPI); err != nil { + return fmt.Errorf("invalid format [tld:][contract-addr@]url for ENS API endpoint configuration %q: %v", ensAPI, err) + } + } + } + return nil +} + +//validate EnsAPIs configuration parameter +func validateEnsAPIs(s string) (err error) { + // missing contract address + if strings.HasPrefix(s, "@") { + return errors.New("missing contract address") + } + // missing url + if strings.HasSuffix(s, "@") { + return errors.New("missing url") + } + // missing tld + if strings.HasPrefix(s, ":") { + return errors.New("missing tld") + } + // missing url + if strings.HasSuffix(s, ":") { + return errors.New("missing url") + } + return nil +} + //print a Config as string func printConfig(config *bzzapi.Config) string { out, err := tomlSettings.Marshal(&config) |