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

Method Create

app/controlplane/pkg/data/apitoken.go:48–71  ·  view source on GitHub ↗

Persist the APIToken to the database.

(ctx context.Context, name string, description *string, expiresAt *time.Time, organizationID *uuid.UUID, projectID *uuid.UUID, workflowID *uuid.UUID, policies []*authz.Policy, isSystem bool)

Source from the content-addressed store, hash-verified

46
47// Persist the APIToken to the database.
48func (r *APITokenRepo) Create(ctx context.Context, name string, description *string, expiresAt *time.Time, organizationID *uuid.UUID, projectID *uuid.UUID, workflowID *uuid.UUID, policies []*authz.Policy, isSystem bool) (*biz.APIToken, error) {
49 ctx, span := otelx.Start(ctx, apiTokenRepoTracer, "APITokenRepo.Create")
50 defer span.End()
51
52 token, err := r.data.DB.APIToken.Create().
53 SetName(name).
54 SetNillableDescription(description).
55 SetNillableExpiresAt(expiresAt).
56 SetNillableOrganizationID(organizationID).
57 SetNillableProjectID(projectID).
58 SetNillableWorkflowID(workflowID).
59 SetPolicies(policies).
60 SetIsSystem(isSystem).
61 Save(ctx)
62 if err != nil {
63 if ent.IsConstraintError(err) {
64 return nil, biz.NewErrAlreadyExists(err)
65 }
66
67 return nil, fmt.Errorf("saving APIToken: %w", err)
68 }
69
70 return r.FindByID(ctx, token.ID)
71}
72
73func (r *APITokenRepo) FindByID(ctx context.Context, id uuid.UUID) (*biz.APIToken, error) {
74 ctx, span := otelx.Start(ctx, apiTokenRepoTracer, "APITokenRepo.FindByID")

Callers

nothing calls this directly

Implementers 3

APITokenRepoapp/controlplane/pkg/biz/mocks/APIToke
APITokenRepo_Expecterapp/controlplane/pkg/biz/mocks/APIToke
APITokenRepoapp/controlplane/pkg/data/apitoken.go

Calls 14

FindByIDMethod · 0.95
StartFunction · 0.92
IsConstraintErrorFunction · 0.92
NewErrAlreadyExistsFunction · 0.92
SaveMethod · 0.65
CreateMethod · 0.65
SetIsSystemMethod · 0.45
SetPoliciesMethod · 0.45
SetNillableWorkflowIDMethod · 0.45
SetNillableProjectIDMethod · 0.45
SetNillableExpiresAtMethod · 0.45

Tested by

no test coverage detected