diff --git a/internal/weldr/api.go b/internal/weldr/api.go index e45ef120b..bbb3e22d9 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -802,7 +802,6 @@ func (api *API) sourceNewHandler(writer http.ResponseWriter, request *http.Reque err = errors_package.New("'url' field is missing from request") } } - if err != nil { errors := responseError{ ID: "ProjectsError", @@ -812,6 +811,22 @@ func (api *API) sourceNewHandler(writer http.ResponseWriter, request *http.Reque return } + // If there is a list of distros, check to make sure they are valid + invalid := []string{} + for _, d := range source.SourceConfig().Distros { + if !common.IsStringInSortedSlice(api.distros.List(), d) { + invalid = append(invalid, d) + } + } + if len(invalid) > 0 { + errors := responseError{ + ID: "ProjectsError", + Msg: "Invalid distributions: " + strings.Join(invalid, ","), + } + statusResponseError(writer, http.StatusBadRequest, errors) + return + } + // Is there an existing System Repo using this id? for _, n := range api.systemRepoNames() { if n == source.GetKey() { diff --git a/internal/weldr/json.go b/internal/weldr/json.go index 669b93f8b..6514ffc8e 100644 --- a/internal/weldr/json.go +++ b/internal/weldr/json.go @@ -186,6 +186,7 @@ func NewSourceConfigV1(id string, s store.SourceConfig) SourceConfigV1 { sc.CheckGPG = s.CheckGPG sc.CheckSSL = s.CheckSSL sc.System = s.System + sc.Distros = s.Distros return sc } @@ -201,6 +202,7 @@ type SourceConfigV1 struct { System bool `json:"system" toml:"system"` Proxy string `json:"proxy,omitempty" toml:"proxy,omitempty"` GPGUrls []string `json:"gpgkey_urls,omitempty" toml:"gpgkey_urls,omitempty"` + Distros []string `json:"distros,omitempty" toml:"distros,omitempty"` } // Key returns the key, .ID in this case @@ -226,6 +228,7 @@ func (s SourceConfigV1) SourceConfig() (ssc store.SourceConfig) { ssc.URL = s.URL ssc.CheckGPG = s.CheckGPG ssc.CheckSSL = s.CheckSSL + ssc.Distros = s.Distros return ssc }