Skip to content

Commit

Permalink
cloudapi: add pulp upload target
Browse files Browse the repository at this point in the history
Add the pulp.ostree upload target to the cloud API and enable it for
edge/iot commits.

Co-Authored-By: Achilleas Koutsou <[email protected]>
  • Loading branch information
kingsleyzissou and achilleas-k committed Oct 17, 2023
1 parent 77eb1a4 commit ed3c4dc
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 151 deletions.
7 changes: 6 additions & 1 deletion internal/cloudapi/v2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,12 @@ func targetResultToUploadStatus(t *target.TargetResult) (*UploadStatus, error) {
uploadOptions = OCIUploadStatus{
Url: ociOptions.URL,
}

case target.TargetNamePulpOSTree:
uploadType = UploadTypesPulp
pulpOSTreeOptions := t.Options.(*target.PulpOSTreeTargetResultOptions)
uploadOptions = PulpOSTreeUploadStatus{
RepoUrl: pulpOSTreeOptions.RepoURL,
}
default:
return nil, fmt.Errorf("unknown upload target: %s", t.Name)
}
Expand Down
36 changes: 36 additions & 0 deletions internal/cloudapi/v2/imagerequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,35 @@ func newOCITarget(ir *ImageRequest, imageType distro.ImageType) (*target.Target,
return t, nil
}

func newPulpOSTreeTarget(ir *ImageRequest, imageType distro.ImageType) (*target.Target, error) {
var pulpUploadOptions PulpOSTreeUploadOptions
jsonUploadOptions, err := json.Marshal(*ir.UploadOptions)
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) (ImageRequestUploadTarget, error) {
Expand Down Expand Up @@ -318,6 +347,10 @@ func targetSupportMap() map[ImageRequestUploadTarget]map[ImageTypes]bool {
ImageRequestUploadTargetOrgOsbuildOci: {
ImageTypesOci: true,
},
ImageRequestUploadTargetOrgOsbuildPulpOstree: {
ImageTypesEdgeCommit: true,
ImageTypesIotCommit: true,
},
}
}

Expand Down Expand Up @@ -364,6 +397,9 @@ func (ir *ImageRequest) GetTarget(request *ComposeRequest, imageType distro.Imag
case ImageRequestUploadTargetOrgOsbuildOci:
irTarget, err = newOCITarget(ir, imageType)

case ImageRequestUploadTargetOrgOsbuildPulpOstree:
irTarget, err = newPulpOSTreeTarget(ir, imageType)

default:
return nil, HTTPError(ErrorInvalidUploadTarget)
}
Expand Down
Loading

0 comments on commit ed3c4dc

Please sign in to comment.