RevokServiceAuthToken revokes an auth token for a service account.
(ctx context.Context, req *adminv1.RevokeServiceAuthTokenRequest)
| 511 | |
| 512 | // RevokServiceAuthToken revokes an auth token for a service account. |
| 513 | func (s *Server) RevokeServiceAuthToken(ctx context.Context, req *adminv1.RevokeServiceAuthTokenRequest) (*adminv1.RevokeServiceAuthTokenResponse, error) { |
| 514 | observability.AddRequestAttributes(ctx, |
| 515 | attribute.String("args.token_id", req.TokenId), |
| 516 | ) |
| 517 | |
| 518 | token, err := s.admin.DB.FindServiceAuthToken(ctx, req.TokenId) |
| 519 | if err != nil { |
| 520 | return nil, err |
| 521 | } |
| 522 | |
| 523 | service, err := s.admin.DB.FindService(ctx, token.ServiceID) |
| 524 | if err != nil { |
| 525 | return nil, err |
| 526 | } |
| 527 | |
| 528 | org, err := s.admin.DB.FindOrganization(ctx, service.OrgID) |
| 529 | if err != nil { |
| 530 | return nil, err |
| 531 | } |
| 532 | |
| 533 | claims := auth.GetClaims(ctx) |
| 534 | if !claims.OrganizationPermissions(ctx, org.ID).ManageOrg { |
| 535 | return nil, status.Error(codes.PermissionDenied, "not allowed to revoke auth token") |
| 536 | } |
| 537 | |
| 538 | err = s.admin.DB.DeleteServiceAuthToken(ctx, token.ID) |
| 539 | if err != nil { |
| 540 | return nil, err |
| 541 | } |
| 542 | |
| 543 | return &adminv1.RevokeServiceAuthTokenResponse{}, nil |
| 544 | } |
| 545 | |
| 546 | func serviceToPB(service *database.Service, orgName string) *adminv1.Service { |
| 547 | attr, err := structpb.NewStruct(service.Attributes) |
nothing calls this directly
no test coverage detected