ListDeployments returns a list of deployments for a given project.
(ctx context.Context, req *adminv1.ListDeploymentsRequest)
| 102 | |
| 103 | // ListDeployments returns a list of deployments for a given project. |
| 104 | func (s *Server) ListDeployments(ctx context.Context, req *adminv1.ListDeploymentsRequest) (*adminv1.ListDeploymentsResponse, error) { |
| 105 | observability.AddRequestAttributes(ctx, |
| 106 | attribute.String("args.organization_name", req.Org), |
| 107 | attribute.String("args.project_name", req.Project), |
| 108 | attribute.String("args.environment", req.Environment), |
| 109 | attribute.String("args.branch", req.Branch), |
| 110 | attribute.String("args.user_id", req.UserId), |
| 111 | ) |
| 112 | |
| 113 | proj, err := s.admin.DB.FindProjectByName(ctx, req.Org, req.Project) |
| 114 | if err != nil { |
| 115 | return nil, err |
| 116 | } |
| 117 | |
| 118 | claims := auth.GetClaims(ctx) |
| 119 | permissions := claims.ProjectPermissions(ctx, proj.OrganizationID, proj.ID) |
| 120 | |
| 121 | if !permissions.ReadProject { |
| 122 | return nil, status.Error(codes.PermissionDenied, "does not have permission to read project") |
| 123 | } |
| 124 | |
| 125 | depls, err := s.admin.DB.FindDeploymentsForProject(ctx, proj.ID, req.Environment, req.Branch) |
| 126 | if err != nil { |
| 127 | return nil, err |
| 128 | } |
| 129 | |
| 130 | // Filter deployments based on permissions and specified environment and user ID. |
| 131 | var newDepls []*database.Deployment |
| 132 | for _, d := range depls { |
| 133 | if d.Environment == "prod" && !permissions.ReadProd { |
| 134 | continue |
| 135 | } |
| 136 | if d.Environment == "dev" && !permissions.ReadDev { |
| 137 | continue |
| 138 | } |
| 139 | if req.UserId != "" && d.OwnerUserID != nil && req.UserId != *d.OwnerUserID { |
| 140 | continue |
| 141 | } |
| 142 | newDepls = append(newDepls, d) |
| 143 | } |
| 144 | |
| 145 | dtos := make([]*adminv1.Deployment, len(newDepls)) |
| 146 | for i, d := range newDepls { |
| 147 | dtos[i] = deploymentToDTO(d) |
| 148 | } |
| 149 | |
| 150 | return &adminv1.ListDeploymentsResponse{ |
| 151 | Deployments: dtos, |
| 152 | }, nil |
| 153 | } |
| 154 | |
| 155 | // GetDeployment returns runtime info and JWT on behalf of a specific user, or alternatively for a raw set of JWT attributes |
| 156 | func (s *Server) GetDeployment(ctx context.Context, req *adminv1.GetDeploymentRequest) (*adminv1.GetDeploymentResponse, error) { |
nothing calls this directly
no test coverage detected