ListServiceAuthTokens lists all auth tokens for a service account.
(ctx context.Context, req *adminv1.ListServiceAuthTokensRequest)
| 430 | |
| 431 | // ListServiceAuthTokens lists all auth tokens for a service account. |
| 432 | func (s *Server) ListServiceAuthTokens(ctx context.Context, req *adminv1.ListServiceAuthTokensRequest) (*adminv1.ListServiceAuthTokensResponse, error) { |
| 433 | observability.AddRequestAttributes(ctx, |
| 434 | attribute.String("args.service_name", req.ServiceName), |
| 435 | attribute.String("args.organization_name", req.Org), |
| 436 | ) |
| 437 | |
| 438 | org, err := s.admin.DB.FindOrganizationByName(ctx, req.Org) |
| 439 | if err != nil { |
| 440 | return nil, err |
| 441 | } |
| 442 | |
| 443 | claims := auth.GetClaims(ctx) |
| 444 | if !claims.OrganizationPermissions(ctx, org.ID).ManageOrg { |
| 445 | return nil, status.Error(codes.PermissionDenied, "not allowed to update org") |
| 446 | } |
| 447 | |
| 448 | service, err := s.admin.DB.FindServiceByName(ctx, org.ID, req.ServiceName) |
| 449 | if err != nil { |
| 450 | return nil, err |
| 451 | } |
| 452 | |
| 453 | tokens, err := s.admin.DB.FindServiceAuthTokens(ctx, service.ID) |
| 454 | if err != nil { |
| 455 | return nil, err |
| 456 | } |
| 457 | |
| 458 | dtos := make([]*adminv1.ServiceToken, len(tokens)) |
| 459 | for i, token := range tokens { |
| 460 | id, err := uuid.Parse(token.ID) |
| 461 | if err != nil { |
| 462 | return nil, status.Errorf(codes.Internal, "invalid token ID %q: %v", token.ID, err) |
| 463 | } |
| 464 | |
| 465 | prefix := authtoken.FromID(authtoken.TypeService, id).Prefix() |
| 466 | |
| 467 | dtos[i] = &adminv1.ServiceToken{ |
| 468 | Id: token.ID, |
| 469 | Prefix: prefix, |
| 470 | CreatedOn: timestamppb.New(token.CreatedOn), |
| 471 | ExpiresOn: timestamppb.New(safeTime(token.ExpiresOn)), |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | return &adminv1.ListServiceAuthTokensResponse{ |
| 476 | Tokens: dtos, |
| 477 | }, nil |
| 478 | } |
| 479 | |
| 480 | // IssueServiceAuthToken issues a new auth token for a service account. |
| 481 | func (s *Server) IssueServiceAuthToken(ctx context.Context, req *adminv1.IssueServiceAuthTokenRequest) (*adminv1.IssueServiceAuthTokenResponse, error) { |
nothing calls this directly
no test coverage detected