(ctx context.Context, req *adminv1.GetAlertMetaRequest)
| 27 | ) |
| 28 | |
| 29 | func (s *Server) GetAlertMeta(ctx context.Context, req *adminv1.GetAlertMetaRequest) (*adminv1.GetAlertMetaResponse, error) { |
| 30 | observability.AddRequestAttributes(ctx, |
| 31 | attribute.String("args.project_id", req.ProjectId), |
| 32 | attribute.String("args.alert", req.Alert), |
| 33 | attribute.Bool("args.query_for", req.GetQueryFor() != nil), |
| 34 | attribute.StringSlice("args.email_recipients", req.EmailRecipients), |
| 35 | attribute.String("args.owner_id", req.OwnerId), |
| 36 | ) |
| 37 | |
| 38 | proj, err := s.admin.DB.FindProject(ctx, req.ProjectId) |
| 39 | if err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | |
| 43 | permissions := auth.GetClaims(ctx).ProjectPermissions(ctx, proj.OrganizationID, proj.ID) |
| 44 | if !permissions.ReadProdStatus { |
| 45 | return nil, status.Error(codes.PermissionDenied, "does not have permission to read alert meta") |
| 46 | } |
| 47 | |
| 48 | org, err := s.admin.DB.FindOrganization(ctx, proj.OrganizationID) |
| 49 | if err != nil { |
| 50 | return nil, err |
| 51 | } |
| 52 | |
| 53 | var attr map[string]any |
| 54 | if req.QueryFor != nil { |
| 55 | switch forVal := req.QueryFor.(type) { |
| 56 | case *adminv1.GetAlertMetaRequest_QueryForUserId: |
| 57 | attr, _, _, err = s.getAttributesForUser(ctx, proj.OrganizationID, proj.ID, forVal.QueryForUserId, "") |
| 58 | if err != nil { |
| 59 | return nil, err |
| 60 | } |
| 61 | case *adminv1.GetAlertMetaRequest_QueryForUserEmail: |
| 62 | attr, _, _, err = s.getAttributesForUser(ctx, proj.OrganizationID, proj.ID, "", forVal.QueryForUserEmail) |
| 63 | if err != nil { |
| 64 | return nil, err |
| 65 | } |
| 66 | default: |
| 67 | return nil, status.Error(codes.InvalidArgument, "invalid 'for' type") |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | var attrPB *structpb.Struct |
| 72 | if attr != nil { |
| 73 | attrPB, err = structpb.NewStruct(attr) |
| 74 | if err != nil { |
| 75 | return nil, status.Error(codes.Internal, err.Error()) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // Handle email recipients - create magic tokens for all recipients |
| 80 | recipientURLs := make(map[string]*adminv1.GetAlertMetaResponse_URLs) |
| 81 | |
| 82 | var recipients []string |
| 83 | recipients = append(recipients, req.EmailRecipients...) |
| 84 | if req.AnonRecipients { |
| 85 | // add empty email for slack and other notifiers token |
| 86 | recipients = append(recipients, "") |
nothing calls this directly
no test coverage detected