Weldr API: rename checkImageTypeDenylist() and return bool
Rename the `checkImageTypeDenylist()` method to `isImageTypeAllowed()` and return boolean value instead of error. Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
b150d57c18
commit
dc8a93b3f6
1 changed files with 10 additions and 10 deletions
|
|
@ -385,11 +385,11 @@ func (api *API) openImageFile(composeId uuid.UUID, compose store.Compose) (io.Re
|
||||||
return reader, size, nil
|
return reader, size, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkImageTypeDenylist checks the given ImageType and Distro names against
|
// isImageTypeAllowed checks the given ImageType and Distro names against
|
||||||
//the distro-specific ImageType Denylist provided to the API from configuration.
|
// the distro-specific ImageType Denylist provided to the API from configuration.
|
||||||
// If the given ImageType is not allowed the method returns an `error`.
|
// If the given ImageType is not allowed the method returns an `false`.
|
||||||
// Otherwise `nil` is returned.
|
// Otherwise `true` is returned.
|
||||||
func (api *API) checkImageTypeDenylist(distroName, imageType string) error {
|
func (api *API) isImageTypeAllowed(distroName, imageType string) bool {
|
||||||
anyImageType := "*"
|
anyImageType := "*"
|
||||||
anyDistro := "*"
|
anyDistro := "*"
|
||||||
|
|
||||||
|
|
@ -397,20 +397,20 @@ func (api *API) checkImageTypeDenylist(distroName, imageType string) error {
|
||||||
if distroName == deniedDistro || deniedDistro == anyDistro {
|
if distroName == deniedDistro || deniedDistro == anyDistro {
|
||||||
for _, deniedImgType := range deniedImgTypes {
|
for _, deniedImgType := range deniedImgTypes {
|
||||||
if imageType == deniedImgType || deniedImgType == anyImageType {
|
if imageType == deniedImgType || deniedImgType == anyImageType {
|
||||||
return fmt.Errorf("image type denied by configuration: %q", imageType)
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// getImageType returns the ImageType for the selected distro
|
// getImageType returns the ImageType for the selected distro
|
||||||
// This is necessary because different distros support different image types, and the image
|
// This is necessary because different distros support different image types, and the image
|
||||||
// type may have a different package set than other distros.
|
// type may have a different package set than other distros.
|
||||||
func (api *API) getImageType(distroName, imageType string) (distro.ImageType, error) {
|
func (api *API) getImageType(distroName, imageType string) (distro.ImageType, error) {
|
||||||
if err := api.checkImageTypeDenylist(distroName, imageType); err != nil {
|
if !api.isImageTypeAllowed(distroName, imageType) {
|
||||||
return nil, err
|
return nil, fmt.Errorf("image type %q for distro %q is denied by configuration", imageType, distroName)
|
||||||
}
|
}
|
||||||
|
|
||||||
distro := api.getDistro(distroName)
|
distro := api.getDistro(distroName)
|
||||||
|
|
@ -2522,7 +2522,7 @@ func (api *API) composeTypesHandler(writer http.ResponseWriter, request *http.Re
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, format := range arch.ListImageTypes() {
|
for _, format := range arch.ListImageTypes() {
|
||||||
if err := api.checkImageTypeDenylist(distroName, format); err != nil {
|
if !api.isImageTypeAllowed(distroName, format) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
reply.Types = append(reply.Types, composeType{format, true})
|
reply.Types = append(reply.Types, composeType{format, true})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue