From 135cd684fc612d4737fab86ebba5ce5f99aaec18 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Tue, 18 Jan 2022 15:12:14 +0100 Subject: [PATCH] ostree: new ostree parameter rules All parameters can now be specified at the same time. See https://github.com/osbuild/osbuild-composer/issues/2131 for a description of how the parameters are meant to interact. In brief, the only invalid parameter combination is specifying a Parent without a URL. All other error conditions are for malformed URLs, invalid characters in a ref, or error responses from the server. --- internal/ostree/ostree.go | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/internal/ostree/ostree.go b/internal/ostree/ostree.go index 8e4e028db..9d7e8dab9 100644 --- a/internal/ostree/ostree.go +++ b/internal/ostree/ostree.go @@ -65,17 +65,29 @@ func ResolveParams(params RequestParams, defaultRef string) (RequestParams, erro return resolved, NewInvalidParameterError("Invalid ostree ref %q", params.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, NewInvalidParameterError("Supply at most one of Parent and URL") + if params.Parent != "" { + // parent must also be a valid ref + if !VerifyRef(params.Parent) { + return resolved, NewInvalidParameterError("Invalid ostree parent ref %q", params.Parent) } + if params.URL == "" { + // specifying parent ref also requires URL + return resolved, NewInvalidParameterError("ostree parent ref specified, but no URL to retrieve it") + } + } - parent, err := ResolveRef(resolved.URL, resolved.Ref) + resolved.URL = params.URL + if resolved.URL != "" { + // if a URL is specified, we need to fetch the commit at the URL + // the reference to resolve is the parent commit which is defined by + // the 'parent' argument + // if the parent argument is not specified, we use the specified ref + // if neither is specified, we use the default ref + parentRef := params.Parent + if parentRef == "" { + parentRef = resolved.Ref + } + parent, err := ResolveRef(resolved.URL, parentRef) if err != nil { return resolved, err // ResolveRefError }