cloudapi: separate target selection from initialisation
Separate the target selection in GetTarget() into two steps. First determine the default target name for the image type and then use the name to initialise the target object. This is a bit more work (and double switching) but will be needed to support selecting targets externally.
This commit is contained in:
parent
8a6e0e3862
commit
9d990ea5da
1 changed files with 40 additions and 10 deletions
|
|
@ -220,10 +220,10 @@ func newOCITarget(ir *ImageRequest, imageType distro.ImageType) (*target.Target,
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetImageTarget returns the target for the selected image type
|
// Returns the name of the default target for a given image type name or error
|
||||||
func (ir *ImageRequest) GetTarget(request *ComposeRequest, imageType distro.ImageType) (irTarget *target.Target, err error) {
|
// if the image type name is unknown.
|
||||||
// oneOf is not supported by the openapi generator so marshal and unmarshal the uploadrequest based on the type
|
func getDefaultTarget(imageType ImageTypes) (UploadTypes, error) {
|
||||||
switch ir.ImageType {
|
switch imageType {
|
||||||
case ImageTypesAws:
|
case ImageTypesAws:
|
||||||
fallthrough
|
fallthrough
|
||||||
case ImageTypesAwsRhui:
|
case ImageTypesAwsRhui:
|
||||||
|
|
@ -231,7 +231,7 @@ func (ir *ImageRequest) GetTarget(request *ComposeRequest, imageType distro.Imag
|
||||||
case ImageTypesAwsHaRhui:
|
case ImageTypesAwsHaRhui:
|
||||||
fallthrough
|
fallthrough
|
||||||
case ImageTypesAwsSapRhui:
|
case ImageTypesAwsSapRhui:
|
||||||
irTarget, err = newAWSTarget(ir, imageType)
|
return UploadTypesAws, nil
|
||||||
|
|
||||||
case ImageTypesGuestImage:
|
case ImageTypesGuestImage:
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
@ -254,17 +254,17 @@ func (ir *ImageRequest) GetTarget(request *ComposeRequest, imageType distro.Imag
|
||||||
case ImageTypesIotCommit:
|
case ImageTypesIotCommit:
|
||||||
fallthrough
|
fallthrough
|
||||||
case ImageTypesIotRawImage:
|
case ImageTypesIotRawImage:
|
||||||
irTarget, err = newAWSS3Target(ir, imageType)
|
return UploadTypesAwsS3, nil
|
||||||
|
|
||||||
case ImageTypesEdgeContainer:
|
case ImageTypesEdgeContainer:
|
||||||
fallthrough
|
fallthrough
|
||||||
case ImageTypesIotContainer:
|
case ImageTypesIotContainer:
|
||||||
irTarget, err = newContainerTarget(ir, request, imageType)
|
return UploadTypesContainer, nil
|
||||||
|
|
||||||
case ImageTypesGcp:
|
case ImageTypesGcp:
|
||||||
fallthrough
|
fallthrough
|
||||||
case ImageTypesGcpRhui:
|
case ImageTypesGcpRhui:
|
||||||
irTarget, err = newGCPTarget(ir, imageType)
|
return UploadTypesGcp, nil
|
||||||
|
|
||||||
case ImageTypesAzure:
|
case ImageTypesAzure:
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
@ -273,13 +273,43 @@ func (ir *ImageRequest) GetTarget(request *ComposeRequest, imageType distro.Imag
|
||||||
case ImageTypesAzureEap7Rhui:
|
case ImageTypesAzureEap7Rhui:
|
||||||
fallthrough
|
fallthrough
|
||||||
case ImageTypesAzureSapRhui:
|
case ImageTypesAzureSapRhui:
|
||||||
irTarget, err = newAzureTarget(ir, imageType)
|
return UploadTypesAzure, nil
|
||||||
|
|
||||||
case ImageTypesOci:
|
case ImageTypesOci:
|
||||||
|
return UploadTypesOciObjectstorage, nil
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "", HTTPError(ErrorUnsupportedImageType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTarget returns the target for the selected image type.
|
||||||
|
func (ir *ImageRequest) GetTarget(request *ComposeRequest, imageType distro.ImageType) (irTarget *target.Target, err error) {
|
||||||
|
uploadTarget, err := getDefaultTarget(ir.ImageType)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch uploadTarget {
|
||||||
|
case UploadTypesAws:
|
||||||
|
irTarget, err = newAWSTarget(ir, imageType)
|
||||||
|
|
||||||
|
case UploadTypesAwsS3:
|
||||||
|
irTarget, err = newAWSS3Target(ir, imageType)
|
||||||
|
|
||||||
|
case UploadTypesContainer:
|
||||||
|
irTarget, err = newContainerTarget(ir, request, imageType)
|
||||||
|
|
||||||
|
case UploadTypesGcp:
|
||||||
|
irTarget, err = newGCPTarget(ir, imageType)
|
||||||
|
|
||||||
|
case UploadTypesAzure:
|
||||||
|
irTarget, err = newAzureTarget(ir, imageType)
|
||||||
|
|
||||||
|
case UploadTypesOciObjectstorage:
|
||||||
irTarget, err = newOCITarget(ir, imageType)
|
irTarget, err = newOCITarget(ir, imageType)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, HTTPError(ErrorUnsupportedImageType)
|
return nil, HTTPError(ErrorInvalidUploadTarget)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue