cloudapi: add pulp upload target

Add the pulp.ostree upload target to the cloud API and enable it for
edge/iot commits.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
This commit is contained in:
Gianluca Zuccarelli 2023-10-16 20:13:46 +02:00 committed by Sanne Raymaekers
parent 5a93166f6b
commit b711e302ba
4 changed files with 149 additions and 64 deletions

View file

@ -220,6 +220,35 @@ func newOCITarget(options UploadOptions, imageType distro.ImageType) (*target.Ta
return t, nil
}
func newPulpOSTreeTarget(options UploadOptions, imageType distro.ImageType) (*target.Target, error) {
var pulpUploadOptions PulpOSTreeUploadOptions
jsonUploadOptions, err := json.Marshal(options)
if err != nil {
return nil, HTTPError(ErrorJSONMarshallingError)
}
err = json.Unmarshal(jsonUploadOptions, &pulpUploadOptions)
if err != nil {
return nil, HTTPError(ErrorJSONUnMarshallingError)
}
serverAddress := ""
if pulpUploadOptions.ServerAddress != nil {
serverAddress = *pulpUploadOptions.ServerAddress
}
repository := ""
if pulpUploadOptions.Repository != nil {
repository = *pulpUploadOptions.Repository
}
t := target.NewPulpOSTreeTarget(&target.PulpOSTreeTargetOptions{
ServerAddress: serverAddress,
Repository: repository,
BasePath: pulpUploadOptions.Basepath,
})
t.ImageName = fmt.Sprintf("composer-api-%s", uuid.New().String())
t.OsbuildArtifact.ExportFilename = imageType.Filename()
return t, nil
}
// Returns the name of the default target for a given image type name or error
// if the image type name is unknown.
func getDefaultTarget(imageType ImageTypes) (UploadTypes, error) {
@ -321,6 +350,10 @@ func targetSupportMap() map[UploadTypes]map[ImageTypes]bool {
UploadTypesOciObjectstorage: {
ImageTypesOci: true,
},
UploadTypesPulpOstree: {
ImageTypesEdgeCommit: true,
ImageTypesIotCommit: true,
},
}
}
@ -380,6 +413,9 @@ func getTarget(targetType UploadTypes, options UploadOptions, request *ComposeRe
case UploadTypesOciObjectstorage:
irTarget, err = newOCITarget(options, imageType)
case UploadTypesPulpOstree:
irTarget, err = newPulpOSTreeTarget(options, imageType)
default:
return nil, HTTPError(ErrorInvalidUploadTarget)
}