From 1a7f22bfb68de789361982ccfaa83eead88b57f9 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Date: Mon, 14 Jul 2025 14:58:09 +0200 Subject: [PATCH 1/4] fix(autoonboarding): ack if org not found Signed-off-by: Miguel Martinez --- app/controlplane/configs/config.devel.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controlplane/configs/config.devel.yaml b/app/controlplane/configs/config.devel.yaml index a6ed90ff4..44044e7be 100644 --- a/app/controlplane/configs/config.devel.yaml +++ b/app/controlplane/configs/config.devel.yaml @@ -16,8 +16,8 @@ server: # certificate: "../../devel/devkeys/selfsigned/controlplane.crt" # private_key: "../../devel/devkeys/selfsigned/controlplane.key" -# nats_server: -# uri: nats://0.0.0.0:4222 +nats_server: + uri: nats://0.0.0.0:4222 certificate_authorities: - issuer: true @@ -104,4 +104,4 @@ enable_profiler: true # federated_authentication: # enabled: true -# url: http://localhost:8002/machine-identity/verify-token \ No newline at end of file +# url: http://localhost:8002/machine-identity/verify-token From d032323f792b2acb792b40c07652dd3b947252d1 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Date: Mon, 14 Jul 2025 15:18:26 +0200 Subject: [PATCH 2/4] feat: add find token by name Signed-off-by: Miguel Martinez --- app/controlplane/pkg/biz/apitoken.go | 10 ++++++++++ app/controlplane/pkg/data/apitoken.go | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/app/controlplane/pkg/biz/apitoken.go b/app/controlplane/pkg/biz/apitoken.go index 2a7d8cb8a..5b00a1cd1 100644 --- a/app/controlplane/pkg/biz/apitoken.go +++ b/app/controlplane/pkg/biz/apitoken.go @@ -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 { @@ -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, diff --git a/app/controlplane/pkg/data/apitoken.go b/app/controlplane/pkg/data/apitoken.go index 57f060fa3..a53c2ac89 100644 --- a/app/controlplane/pkg/data/apitoken.go +++ b/app/controlplane/pkg/data/apitoken.go @@ -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() From 68dcfb9db334ef4540cbb626c2b893085fa24fe4 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Date: Mon, 14 Jul 2025 15:19:37 +0200 Subject: [PATCH 3/4] feat: add find token by name Signed-off-by: Miguel Martinez --- app/controlplane/configs/config.devel.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controlplane/configs/config.devel.yaml b/app/controlplane/configs/config.devel.yaml index 44044e7be..a6ed90ff4 100644 --- a/app/controlplane/configs/config.devel.yaml +++ b/app/controlplane/configs/config.devel.yaml @@ -16,8 +16,8 @@ server: # certificate: "../../devel/devkeys/selfsigned/controlplane.crt" # private_key: "../../devel/devkeys/selfsigned/controlplane.key" -nats_server: - uri: nats://0.0.0.0:4222 +# nats_server: +# uri: nats://0.0.0.0:4222 certificate_authorities: - issuer: true @@ -104,4 +104,4 @@ enable_profiler: true # federated_authentication: # enabled: true -# url: http://localhost:8002/machine-identity/verify-token +# url: http://localhost:8002/machine-identity/verify-token \ No newline at end of file From 83a802c20568204fc37e36d068d783040ac229fb Mon Sep 17 00:00:00 2001 From: Miguel Martinez Date: Mon, 14 Jul 2025 15:23:48 +0200 Subject: [PATCH 4/4] feat: add find token by name Signed-off-by: Miguel Martinez --- .../pkg/biz/mocks/APITokenRepo.go | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/controlplane/pkg/biz/mocks/APITokenRepo.go b/app/controlplane/pkg/biz/mocks/APITokenRepo.go index 9803d4411..4d64bfa15 100644 --- a/app/controlplane/pkg/biz/mocks/APITokenRepo.go +++ b/app/controlplane/pkg/biz/mocks/APITokenRepo.go @@ -109,6 +109,36 @@ func (_m *APITokenRepo) FindByIDInOrg(ctx context.Context, orgID uuid.UUID, id u return r0, r1 } +// FindByNameInOrg provides a mock function with given fields: ctx, orgID, name +func (_m *APITokenRepo) FindByNameInOrg(ctx context.Context, orgID uuid.UUID, name string) (*biz.APIToken, error) { + ret := _m.Called(ctx, orgID, name) + + if len(ret) == 0 { + panic("no return value specified for FindByNameInOrg") + } + + var r0 *biz.APIToken + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, uuid.UUID, string) (*biz.APIToken, error)); ok { + return rf(ctx, orgID, name) + } + if rf, ok := ret.Get(0).(func(context.Context, uuid.UUID, string) *biz.APIToken); ok { + r0 = rf(ctx, orgID, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*biz.APIToken) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, uuid.UUID, string) error); ok { + r1 = rf(ctx, orgID, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // List provides a mock function with given fields: ctx, orgID, filters func (_m *APITokenRepo) List(ctx context.Context, orgID *uuid.UUID, filters *biz.APITokenListFilters) ([]*biz.APIToken, error) { ret := _m.Called(ctx, orgID, filters)