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 26, 2023
1 parent 74a64aa commit a1ae531
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 153 deletions.
7 changes: 6 additions & 1 deletion internal/cloudapi/v2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,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 @@ -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) (UploadTargetType, error) {
Expand Down Expand Up @@ -321,6 +350,10 @@ func targetSupportMap() map[UploadTargetType]map[ImageTypes]bool {
UploadTargetTypeOrgOsbuildOci: {
ImageTypesOci: true,
},
UploadTargetTypeOrgOsbuildPulpOstree: {
ImageTypesEdgeCommit: true,
ImageTypesIotCommit: true,
},
}
}

Expand Down Expand Up @@ -379,6 +412,9 @@ func getTarget(targetType UploadTargetType, options UploadOptions, request *Comp
case UploadTargetTypeOrgOsbuildOci:
irTarget, err = newOCITarget(options, imageType)

case UploadTargetTypeOrgOsbuildPulpOstree:
irTarget, err = newPulpOSTreeTarget(options, imageType)

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

0 comments on commit a1ae531

Please sign in to comment.