MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / Create

Method Create

app/controlplane/pkg/data/casmapping.go:51–78  ·  view source on GitHub ↗
(ctx context.Context, digest string, casBackendID uuid.UUID, opts *biz.CASMappingCreateOpts)

Source from the content-addressed store, hash-verified

49}
50
51func (r *CASMappingRepo) Create(ctx context.Context, digest string, casBackendID uuid.UUID, opts *biz.CASMappingCreateOpts) (*biz.CASMapping, error) {
52 ctx, span := otelx.Start(ctx, casMappingRepoTracer, "CASMappingRepo.Create")
53 defer span.End()
54
55 casBackend, err := r.casBackendrepo.FindByID(ctx, casBackendID)
56 if err != nil {
57 return nil, fmt.Errorf("failed to find cas backend: %w", err)
58 } else if casBackend == nil {
59 return nil, fmt.Errorf("cas backend not found")
60 }
61
62 query := r.data.DB.CASMapping.Create().
63 SetDigest(digest).
64 SetCasBackendID(casBackendID).
65 SetOrganizationID(casBackend.OrganizationID)
66
67 if opts != nil {
68 query.SetNillableProjectID(opts.ProjectID).SetNillableWorkflowRunID(opts.WorkflowRunID)
69 }
70
71 mapping, err := query.Save(ctx)
72 if err != nil {
73 return nil, fmt.Errorf("failed to create casMapping: %w", err)
74 }
75
76 // reload to get the edges
77 return r.findByID(ctx, mapping.ID)
78}
79
80// FindByDigestInOrgs returns a single CAS mapping for the digest that is reachable through one of
81// the given organizations, honouring project-level RBAC when projectIDs is provided for an org. The

Callers

nothing calls this directly

Implementers 3

CASMappingRepoapp/controlplane/pkg/biz/mocks/CASMapp
CASMappingRepo_Expecterapp/controlplane/pkg/biz/mocks/CASMapp
CASMappingRepoapp/controlplane/pkg/data/casmapping.g

Calls 10

findByIDMethod · 0.95
StartFunction · 0.92
FindByIDMethod · 0.65
CreateMethod · 0.65
SaveMethod · 0.65
SetOrganizationIDMethod · 0.45
SetCasBackendIDMethod · 0.45
SetDigestMethod · 0.45
SetNillableProjectIDMethod · 0.45

Tested by

no test coverage detected