Skip to content

Commit

Permalink
add pulp ostree import commit
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Holloway <[email protected]>
  • Loading branch information
loadtheaccumulator authored and ezr-ondrej committed Dec 2, 2024
1 parent c5347e2 commit 47c8e31
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pkg/clients/pulp/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (ps *PulpService) RepositoriesCreate(ctx context.Context, name string) (*Os
return resp.JSON201, nil
}

// RepositoriesImport imports an initial commit into a repo
func (ps *PulpService) RepositoriesImport(ctx context.Context, id uuid.UUID, repoName, artifactHref string) (*OstreeOstreeRepositoryResponse, error) {
body := OstreeImportAll{
Artifact: artifactHref,
Expand Down Expand Up @@ -58,6 +59,43 @@ func (ps *PulpService) RepositoriesImport(ctx context.Context, id uuid.UUID, rep
return result, nil
}

// RepositoriesImportCommit updates an existing repo containing one or more commits
func (ps *PulpService) RepositoriesImportCommit(ctx context.Context, id uuid.UUID, repoName, artifactHref string, ostreeRef string) (*OstreeOstreeRepositoryResponse, error) {
body := OstreeImportCommitsToRef{
Artifact: artifactHref,
Ref: ostreeRef,
RepositoryName: repoName,
}

// OstreeImportCommits includes the OSTree ref for updating a tree that has at least one commit
// Use OstreeImportAll for the initial commit
// see https://pulpproject.org/pulp_ostree/docs/user/guides/import-commit/
resp, err := ps.cwr.RepositoriesOstreeOstreeImportCommitsWithResponse(ctx, ps.dom, id, body, addAuthenticationHeader)
if err != nil {
return nil, err
}

if resp.JSON202 == nil {
return nil, fmt.Errorf("unexpected response: %d, body: %s", resp.StatusCode(), string(resp.Body))
}

hrefs, err := ps.WaitForTask(ctx, resp.JSON202.Task)
if err != nil {
return nil, err
}
if len(hrefs) != 1 {
return nil, fmt.Errorf("unexpected number of created resources: %d", len(hrefs))
}
href := hrefs[0]

result, err := ps.RepositoriesRead(ctx, ScanUUID(&href))
if err != nil {
return nil, err
}

return result, nil
}

func (ps *PulpService) RepositoriesRead(ctx context.Context, id uuid.UUID) (*OstreeOstreeRepositoryResponse, error) {
req := RepositoriesOstreeOstreeReadParams{}
resp, err := ps.cwr.RepositoriesOstreeOstreeReadWithResponse(ctx, ps.dom, id, &req, addAuthenticationHeader)
Expand Down

0 comments on commit 47c8e31

Please sign in to comment.