From d62e813e75d8fad25fd222b90647351cc8098d68 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Wed, 27 Jan 2021 11:54:35 -0800 Subject: [PATCH] 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 --- internal/weldr/api.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/weldr/api.go b/internal/weldr/api.go index cbbfd2062..166a86661 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -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)