weldr: Add optional distro selection to projects/list route
This commit is contained in:
parent
453d2dfd5f
commit
d1d2f6d491
1 changed files with 25 additions and 1 deletions
|
|
@ -370,6 +370,19 @@ func (api *API) getImageType(distroName, imageType string) (distro.ImageType, er
|
|||
return arch.GetImageType(imageType)
|
||||
}
|
||||
|
||||
func (api *API) parseDistro(query url.Values) (string, error) {
|
||||
distros := api.distros.List()
|
||||
sort.Strings(distros)
|
||||
|
||||
if distro := query.Get("distro"); distro != "" {
|
||||
if common.IsStringInSortedSlice(distros, distro) {
|
||||
return distro, nil
|
||||
}
|
||||
return "", errors_package.New("Invalid distro: " + distro)
|
||||
}
|
||||
return api.hostDistroName, nil
|
||||
}
|
||||
|
||||
func verifyRequestVersion(writer http.ResponseWriter, params httprouter.Params, minVersion uint) bool {
|
||||
versionString := params.ByName("version")
|
||||
|
||||
|
|
@ -972,7 +985,18 @@ func (api *API) projectsListHandler(writer http.ResponseWriter, request *http.Re
|
|||
return
|
||||
}
|
||||
|
||||
availablePackages, err := api.fetchPackageList(api.hostDistroName)
|
||||
// Optional distro parameter
|
||||
// If it is empty it will return api.hostDistroName
|
||||
distroName, err := api.parseDistro(request.URL.Query())
|
||||
if err != nil {
|
||||
errors := responseError{
|
||||
ID: "DistroError",
|
||||
Msg: err.Error(),
|
||||
}
|
||||
statusResponseError(writer, http.StatusBadRequest, errors)
|
||||
return
|
||||
}
|
||||
availablePackages, err := api.fetchPackageList(distroName)
|
||||
|
||||
if err != nil {
|
||||
errors := responseError{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue