weldr: Check source POST for valid distros
This commit is contained in:
parent
2b56e4d8e9
commit
e2b170e754
2 changed files with 19 additions and 1 deletions
|
|
@ -802,7 +802,6 @@ func (api *API) sourceNewHandler(writer http.ResponseWriter, request *http.Reque
|
||||||
err = errors_package.New("'url' field is missing from request")
|
err = errors_package.New("'url' field is missing from request")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors := responseError{
|
errors := responseError{
|
||||||
ID: "ProjectsError",
|
ID: "ProjectsError",
|
||||||
|
|
@ -812,6 +811,22 @@ func (api *API) sourceNewHandler(writer http.ResponseWriter, request *http.Reque
|
||||||
return
|
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?
|
// Is there an existing System Repo using this id?
|
||||||
for _, n := range api.systemRepoNames() {
|
for _, n := range api.systemRepoNames() {
|
||||||
if n == source.GetKey() {
|
if n == source.GetKey() {
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,7 @@ func NewSourceConfigV1(id string, s store.SourceConfig) SourceConfigV1 {
|
||||||
sc.CheckGPG = s.CheckGPG
|
sc.CheckGPG = s.CheckGPG
|
||||||
sc.CheckSSL = s.CheckSSL
|
sc.CheckSSL = s.CheckSSL
|
||||||
sc.System = s.System
|
sc.System = s.System
|
||||||
|
sc.Distros = s.Distros
|
||||||
|
|
||||||
return sc
|
return sc
|
||||||
}
|
}
|
||||||
|
|
@ -201,6 +202,7 @@ type SourceConfigV1 struct {
|
||||||
System bool `json:"system" toml:"system"`
|
System bool `json:"system" toml:"system"`
|
||||||
Proxy string `json:"proxy,omitempty" toml:"proxy,omitempty"`
|
Proxy string `json:"proxy,omitempty" toml:"proxy,omitempty"`
|
||||||
GPGUrls []string `json:"gpgkey_urls,omitempty" toml:"gpgkey_urls,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
|
// Key returns the key, .ID in this case
|
||||||
|
|
@ -226,6 +228,7 @@ func (s SourceConfigV1) SourceConfig() (ssc store.SourceConfig) {
|
||||||
ssc.URL = s.URL
|
ssc.URL = s.URL
|
||||||
ssc.CheckGPG = s.CheckGPG
|
ssc.CheckGPG = s.CheckGPG
|
||||||
ssc.CheckSSL = s.CheckSSL
|
ssc.CheckSSL = s.CheckSSL
|
||||||
|
ssc.Distros = s.Distros
|
||||||
|
|
||||||
return ssc
|
return ssc
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue