Skip to content

Commit 679de80

Browse files
authored
fix: scope down revocation (#1060)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 63ceef8 commit 679de80

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

app/controlplane/pkg/biz/apitoken.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type APITokenRepo interface {
5252
List(ctx context.Context, orgID *uuid.UUID, includeRevoked bool) ([]*APIToken, error)
5353
Revoke(ctx context.Context, orgID, ID uuid.UUID) error
5454
FindByID(ctx context.Context, ID uuid.UUID) (*APIToken, error)
55-
FindByName(ctx context.Context, name string) (*APIToken, error)
55+
FindByNameInOrg(ctx context.Context, orgID uuid.UUID, name string) (*APIToken, error)
5656
}
5757

5858
type APITokenUseCase struct {
@@ -183,11 +183,9 @@ func (uc *APITokenUseCase) FindByNameInOrg(ctx context.Context, orgID, name stri
183183
return nil, NewErrInvalidUUID(err)
184184
}
185185

186-
t, err := uc.apiTokenRepo.FindByName(ctx, name)
186+
t, err := uc.apiTokenRepo.FindByNameInOrg(ctx, orgUUID, name)
187187
if err != nil {
188188
return nil, fmt.Errorf("finding token: %w", err)
189-
} else if t.OrganizationID != orgUUID {
190-
return nil, NewErrNotFound("token")
191189
}
192190

193191
return t, nil

app/controlplane/pkg/biz/mocks/APITokenRepo.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/pkg/data/apitoken.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz"
2424
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent"
2525
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/apitoken"
26+
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/organization"
2627
"github.com/go-kratos/kratos/v2/log"
2728
"github.com/google/uuid"
2829
)
@@ -69,8 +70,8 @@ func (r *APITokenRepo) FindByID(ctx context.Context, id uuid.UUID) (*biz.APIToke
6970
return entAPITokenToBiz(token), nil
7071
}
7172

72-
func (r *APITokenRepo) FindByName(ctx context.Context, name string) (*biz.APIToken, error) {
73-
token, err := r.data.DB.APIToken.Query().Where(apitoken.NameEQ(name)).Only(ctx)
73+
func (r *APITokenRepo) FindByNameInOrg(ctx context.Context, orgID uuid.UUID, name string) (*biz.APIToken, error) {
74+
token, err := r.data.DB.APIToken.Query().Where(apitoken.NameEQ(name), apitoken.HasOrganizationWith(organization.ID(orgID)), apitoken.RevokedAtIsNil()).Only(ctx)
7475
if err != nil {
7576
if ent.IsNotFound(err) {
7677
return nil, biz.NewErrNotFound("API token")

0 commit comments

Comments
 (0)