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)
| 46 | |
| 47 | // Persist the APIToken to the database. |
| 48 | func (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 | |
| 73 | func (r *APITokenRepo) FindByID(ctx context.Context, id uuid.UUID) (*biz.APIToken, error) { |
| 74 | ctx, span := otelx.Start(ctx, apiTokenRepoTracer, "APITokenRepo.FindByID") |
nothing calls this directly
no test coverage detected