From 47c8e31687dc66029879a4675217faef4aa29f36 Mon Sep 17 00:00:00 2001 From: Jonathan Holloway Date: Tue, 26 Nov 2024 22:02:04 -0600 Subject: [PATCH] add pulp ostree import commit Signed-off-by: Jonathan Holloway --- pkg/clients/pulp/repositories.go | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pkg/clients/pulp/repositories.go b/pkg/clients/pulp/repositories.go index a7edbf922..1ded03246 100644 --- a/pkg/clients/pulp/repositories.go +++ b/pkg/clients/pulp/repositories.go @@ -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, @@ -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)