Skip to content

Commit

Permalink
revert changes
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene authored and arvindh123 committed Dec 30, 2024
1 parent 18eb5f0 commit 8278fa5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
7 changes: 1 addition & 6 deletions auth/api/http/pats/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ func retrievePATEndpoint(svc auth.Service) endpoint.Endpoint {
return nil, err
}

res, err := svc.Identify(ctx, req.token)
if err != nil {
return nil, err
}

pat, err := svc.RetrievePAT(ctx, res.User, req.id)
pat, err := svc.RetrievePAT(ctx, req.token, req.id)
if err != nil {
return nil, err
}
Expand Down
24 changes: 7 additions & 17 deletions auth/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,6 @@ func (svc service) RetrieveKey(ctx context.Context, token, id string) (Key, erro
}

func (svc service) Identify(ctx context.Context, token string) (Key, error) {
if strings.HasPrefix(token, "pat"+"_") {
pat, err := svc.IdentifyPAT(ctx, token)
if err != nil {
return Key{}, err
}
return Key{
ID: pat.ID,
Type: PersonalAccessToken,
Subject: pat.User,
User: pat.User,
IssuedAt: pat.IssuedAt,
ExpiresAt: pat.ExpiresAt,
}, nil
}

key, err := svc.tokenizer.Parse(token)
if errors.Contains(err, ErrExpiry) {
err = svc.keys.Remove(ctx, key.Issuer, key.ID)
Expand Down Expand Up @@ -529,8 +514,13 @@ func (svc service) UpdatePATDescription(ctx context.Context, token, patID, descr
return pat, nil
}

func (svc service) RetrievePAT(ctx context.Context, userID, patID string) (PAT, error) {
pat, err := svc.pats.Retrieve(ctx, userID, patID)
func (svc service) RetrievePAT(ctx context.Context, token, patID string) (PAT, error) {
key, err := svc.Identify(ctx, token)
if err != nil {
return PAT{}, err
}

pat, err := svc.pats.Retrieve(ctx, key.User, patID)
if err != nil {
return PAT{}, errors.Wrap(errRetrievePAT, err)
}
Expand Down

0 comments on commit 8278fa5

Please sign in to comment.