ostree: ostree parameter validation and resolve function
Validates the ostree parameters and resolves the parent ID.
This commit is contained in:
parent
4d31c8e69d
commit
c60c54aa43
1 changed files with 31 additions and 0 deletions
|
|
@ -9,6 +9,8 @@ import (
|
|||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
)
|
||||
|
||||
var ostreeRefRE = regexp.MustCompile(`^(?:[\w\d][-._\w\d]*\/)*[\w\d][-._\w\d]*$`)
|
||||
|
|
@ -51,3 +53,32 @@ func ResolveRef(location, ref string) (string, error) {
|
|||
}
|
||||
return parent, nil
|
||||
}
|
||||
|
||||
func ResolveParams(params OSTreeRequest, imageType distro.ImageType) (OSTreeRequest, error) {
|
||||
resolved := OSTreeRequest{}
|
||||
resolved.Ref = params.Ref
|
||||
// if ref is not provided, use distro default
|
||||
if resolved.Ref == "" {
|
||||
resolved.Ref = imageType.OSTreeRef()
|
||||
} else if !VerifyRef(params.Ref) { // only verify if specified in params
|
||||
return resolved, fmt.Errorf("Invalid ostree ref")
|
||||
}
|
||||
|
||||
resolved.URL = params.URL
|
||||
// Fetch parent ostree commit from ref + url if commit is not
|
||||
// provided. The parameter name "parent" is perhaps slightly misleading
|
||||
// as it represent whatever commit sha the image type requires, not
|
||||
// strictly speaking just the parent commit.
|
||||
if resolved.Ref != "" && resolved.URL != "" {
|
||||
if params.Parent != "" {
|
||||
return resolved, fmt.Errorf("Supply at most one of Parent and URL")
|
||||
}
|
||||
|
||||
parent, err := ResolveRef(resolved.URL, resolved.Ref)
|
||||
if err != nil {
|
||||
return resolved, err
|
||||
}
|
||||
resolved.Parent = parent
|
||||
}
|
||||
return resolved, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue