internal/ostree: offload using default ostree ref to caller
If params.Ref is an empty string, it's set to the distro's default ref. The only difference here is that the default ref also gets verified. It makes splitting out resolving ostree refs to a new job easier. In the weldr and cloud apis, ostree.ResolveParams always got executed, also for non-ostree image types. Make it more explicit by only resolving if the image type is actually an ostree image.
This commit is contained in:
parent
ae04c56c32
commit
b01792d9dd
3 changed files with 48 additions and 42 deletions
|
|
@ -286,37 +286,45 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
|
|||
}
|
||||
}
|
||||
|
||||
ostreeOptions := ostree.RequestParams{}
|
||||
if ir.Ostree != nil {
|
||||
if ir.Ostree.Ref != nil {
|
||||
ostreeOptions.Ref = *ir.Ostree.Ref
|
||||
// assume it's an ostree image if the type has a default ostree ref
|
||||
if imageType.OSTreeRef() != "" && ir.Ostree != nil {
|
||||
ostreeOptions := ostree.RequestParams{}
|
||||
if ir.Ostree != nil {
|
||||
if ir.Ostree.Ref != nil {
|
||||
ostreeOptions.Ref = *ir.Ostree.Ref
|
||||
}
|
||||
if ir.Ostree.Url != nil {
|
||||
ostreeOptions.URL = *ir.Ostree.Url
|
||||
}
|
||||
if ir.Ostree.Parent != nil {
|
||||
ostreeOptions.Parent = *ir.Ostree.Parent
|
||||
}
|
||||
}
|
||||
if ir.Ostree.Url != nil {
|
||||
ostreeOptions.URL = *ir.Ostree.Url
|
||||
|
||||
if ostreeOptions.Ref == "" {
|
||||
ostreeOptions.Ref = imageType.OSTreeRef()
|
||||
}
|
||||
if ir.Ostree.Parent != nil {
|
||||
ostreeOptions.Parent = *ir.Ostree.Parent
|
||||
|
||||
ref, checksum, err := ostree.ResolveParams(ostreeOptions)
|
||||
if err != nil {
|
||||
switch v := err.(type) {
|
||||
case ostree.RefError:
|
||||
return HTTPError(ErrorInvalidOSTreeRef)
|
||||
case ostree.ResolveRefError:
|
||||
return HTTPErrorWithInternal(ErrorInvalidOSTreeRepo, v)
|
||||
case ostree.ParameterComboError:
|
||||
return HTTPError(ErrorInvalidOSTreeParams)
|
||||
default:
|
||||
// general case
|
||||
return HTTPError(ErrorInvalidOSTreeParams)
|
||||
}
|
||||
}
|
||||
}
|
||||
ref, checksum, err := ostree.ResolveParams(ostreeOptions, imageType.OSTreeRef())
|
||||
if err != nil {
|
||||
switch v := err.(type) {
|
||||
case ostree.RefError:
|
||||
return HTTPError(ErrorInvalidOSTreeRef)
|
||||
case ostree.ResolveRefError:
|
||||
return HTTPErrorWithInternal(ErrorInvalidOSTreeRepo, v)
|
||||
case ostree.ParameterComboError:
|
||||
return HTTPError(ErrorInvalidOSTreeParams)
|
||||
default:
|
||||
// general case
|
||||
return HTTPError(ErrorInvalidOSTreeParams)
|
||||
imageOptions.OSTree = distro.OSTreeImageOptions{
|
||||
ImageRef: ref,
|
||||
FetchChecksum: checksum,
|
||||
URL: ostreeOptions.URL,
|
||||
}
|
||||
}
|
||||
imageOptions.OSTree = distro.OSTreeImageOptions{
|
||||
ImageRef: ref,
|
||||
FetchChecksum: checksum,
|
||||
URL: ostreeOptions.URL,
|
||||
}
|
||||
|
||||
var irTarget *target.Target
|
||||
if ir.UploadOptions == nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue