weldr: Check source POST for valid distros

This commit is contained in:
Brian C. Lane 2021-05-20 15:24:44 -07:00 committed by Ondřej Budai
parent 2b56e4d8e9
commit e2b170e754
2 changed files with 19 additions and 1 deletions

View file

@ -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() {