(ctx context.Context, req *adminv1.TriggerReportRequest)
| 487 | } |
| 488 | |
| 489 | func (s *Server) TriggerReport(ctx context.Context, req *adminv1.TriggerReportRequest) (*adminv1.TriggerReportResponse, error) { |
| 490 | observability.AddRequestAttributes(ctx, |
| 491 | attribute.String("args.organization", req.Org), |
| 492 | attribute.String("args.project", req.Project), |
| 493 | attribute.String("args.name", req.Name), |
| 494 | ) |
| 495 | |
| 496 | proj, err := s.admin.DB.FindProjectByName(ctx, req.Org, req.Project) |
| 497 | if err != nil { |
| 498 | return nil, err |
| 499 | } |
| 500 | |
| 501 | claims := auth.GetClaims(ctx) |
| 502 | permissions := claims.ProjectPermissions(ctx, proj.OrganizationID, proj.ID) |
| 503 | if !permissions.ReadProd { |
| 504 | return nil, status.Error(codes.PermissionDenied, "does not have permission to read project repo") |
| 505 | } |
| 506 | |
| 507 | if proj.PrimaryDeploymentID == nil { |
| 508 | return nil, status.Error(codes.FailedPrecondition, "project does not have a production deployment") |
| 509 | } |
| 510 | |
| 511 | depl, err := s.admin.DB.FindDeployment(ctx, *proj.PrimaryDeploymentID) |
| 512 | if err != nil { |
| 513 | return nil, err |
| 514 | } |
| 515 | |
| 516 | spec, err := s.admin.LookupReport(ctx, depl, req.Name) |
| 517 | if err != nil { |
| 518 | return nil, fmt.Errorf("could not get report: %w", err) |
| 519 | } |
| 520 | annotations := parseReportAnnotations(spec.Annotations) |
| 521 | |
| 522 | isOwner := claims.OwnerType() == auth.OwnerTypeUser && annotations.AdminOwnerUserID == claims.OwnerID() |
| 523 | if !permissions.ManageReports && !isOwner { |
| 524 | return nil, status.Error(codes.PermissionDenied, "does not have permission to edit report") |
| 525 | } |
| 526 | |
| 527 | err = s.admin.TriggerReport(ctx, depl, req.Name) |
| 528 | if err != nil { |
| 529 | return nil, fmt.Errorf("failed to trigger report: %w", err) |
| 530 | } |
| 531 | |
| 532 | return &adminv1.TriggerReportResponse{}, nil |
| 533 | } |
| 534 | |
| 535 | func (s *Server) GenerateReportYAML(ctx context.Context, req *adminv1.GenerateReportYAMLRequest) (*adminv1.GenerateReportYAMLResponse, error) { |
| 536 | observability.AddRequestAttributes(ctx, |
nothing calls this directly
no test coverage detected