mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 20:38:08 +08:00
Raise error when adding a new zot config with an existed saved name
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user