Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/controlplane/pkg/biz/apitoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type APITokenRepo interface {
UpdateLastUsedAt(ctx context.Context, ID uuid.UUID, lastUsedAt time.Time) error
FindByID(ctx context.Context, ID uuid.UUID) (*APIToken, error)
FindByIDInOrg(ctx context.Context, orgID uuid.UUID, id uuid.UUID) (*APIToken, error)
FindByNameInOrg(ctx context.Context, orgID uuid.UUID, name string) (*APIToken, error)
}

type APITokenUseCase struct {
Expand Down Expand Up @@ -402,6 +403,15 @@ func (uc *APITokenUseCase) FindByID(ctx context.Context, id string) (*APIToken,
return t, nil
}

func (uc *APITokenUseCase) FindByNameInOrg(ctx context.Context, orgID, name string) (*APIToken, error) {
orgUUID, err := uuid.Parse(orgID)
if err != nil {
return nil, NewErrInvalidUUID(err)
}

return uc.apiTokenRepo.FindByNameInOrg(ctx, orgUUID, name)
}

func NewAPITokenSyncerUseCase(tokenUC *APITokenUseCase) *APITokenSyncerUseCase {
return &APITokenSyncerUseCase{
base: tokenUC,
Expand Down
30 changes: 30 additions & 0 deletions app/controlplane/pkg/biz/mocks/APITokenRepo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions app/controlplane/pkg/data/apitoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ func (r *APITokenRepo) FindByIDInOrg(ctx context.Context, orgID uuid.UUID, id uu
return entAPITokenToBiz(token), nil
}

func (r *APITokenRepo) FindByNameInOrg(ctx context.Context, orgID uuid.UUID, name string) (*biz.APIToken, error) {
token, err := r.data.DB.APIToken.Query().Where(apitoken.Name(name), apitoken.HasOrganizationWith(organization.ID(orgID)), apitoken.RevokedAtIsNil()).WithProject().Only(ctx)
if err != nil {
if ent.IsNotFound(err) {
return nil, biz.NewErrNotFound("API token")
}

return nil, err
}

return entAPITokenToBiz(token), nil
}

func (r *APITokenRepo) List(ctx context.Context, orgID *uuid.UUID, filters *biz.APITokenListFilters) ([]*biz.APIToken, error) {
query := r.data.DB.APIToken.Query().WithProject().WithOrganization()

Expand Down
Loading