weldr: Return error if source name matches system repo

System repos cannot be overridden by users, return an error if they try
to push a source with the same name/id as a system source.

Resolves: rhbz#1915359
This commit is contained in:
Brian C. Lane 2021-01-27 11:54:35 -08:00 committed by Brian C. Lane
parent 3e510ffc99
commit d62e813e75

View file

@ -666,6 +666,19 @@ func (api *API) sourceNewHandler(writer http.ResponseWriter, request *http.Reque
return
}
// Is there an existing System Repo using this id?
for _, n := range api.systemRepoNames() {
if n == source.GetKey() {
// Users cannot replace system repos
errors := responseError{
ID: "SystemSource",
Msg: fmt.Sprintf("%s is a system source, it cannot be changed.", source.GetKey()),
}
statusResponseError(writer, http.StatusBadRequest, errors)
return
}
}
api.store.PushSource(source.GetKey(), source.SourceConfig())
statusResponseOK(writer)