Raise error when adding a new zot config with an existed saved name

This commit is contained in:
Ionut Costin Craciun
2020-10-29 14:47:27 +02:00
parent 429a689ace
commit dad884ddeb
3 changed files with 30 additions and 0 deletions
+15
View File
@@ -204,6 +204,10 @@ func addConfig(configPath, configName, url string) error {
return zotErrors.ErrInvalidURL
}
if configNameExists(configs, configName) {
return zotErrors.ErrDuplicateConfigName
}
configMap := make(map[string]interface{})
configMap["url"] = url
configMap[nameKey] = configName
@@ -361,6 +365,17 @@ func getAllConfig(configPath, configName string) (string, error) {
return "", zotErrors.ErrConfigNotFound
}
func configNameExists(configs []interface{}, configName string) bool {
for _, val := range configs {
configMap := val.(map[string]interface{})
if configMap[nameKey] == configName {
return true
}
}
return false
}
const (
examples = ` zot config add main https://zot-foo.com:8080
zot config main url