(ctx context.Context, req *adminv1.GetDeploymentConfigRequest)
| 735 | } |
| 736 | |
| 737 | func (s *Server) GetDeploymentConfig(ctx context.Context, req *adminv1.GetDeploymentConfigRequest) (*adminv1.GetDeploymentConfigResponse, error) { |
| 738 | // If the deployment ID is not provided, attempt to infer it from the access token. |
| 739 | claims := auth.GetClaims(ctx) |
| 740 | if req.DeploymentId == "" { |
| 741 | if claims.OwnerType() == auth.OwnerTypeDeployment { |
| 742 | req.DeploymentId = claims.OwnerID() |
| 743 | } else { |
| 744 | return nil, status.Error(codes.InvalidArgument, "missing deployment_id") |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | observability.AddRequestAttributes(ctx, |
| 749 | attribute.String("args.deployment_id", req.DeploymentId), |
| 750 | ) |
| 751 | |
| 752 | depl, err := s.admin.DB.FindDeployment(ctx, req.DeploymentId) |
| 753 | if err != nil { |
| 754 | return nil, err |
| 755 | } |
| 756 | |
| 757 | proj, err := s.admin.DB.FindProject(ctx, depl.ProjectID) |
| 758 | if err != nil { |
| 759 | return nil, err |
| 760 | } |
| 761 | |
| 762 | // Find the runtime provisioned for this deployment |
| 763 | pr, ok, err := s.admin.FindProvisionedRuntimeResource(ctx, depl.ID) |
| 764 | if err != nil { |
| 765 | return nil, err |
| 766 | } |
| 767 | if !ok { |
| 768 | return nil, status.Errorf(codes.FailedPrecondition, "can't update deployment %q because its runtime has not been initialized yet", depl.ID) |
| 769 | } |
| 770 | |
| 771 | org, err := s.admin.DB.FindOrganization(ctx, proj.OrganizationID) |
| 772 | if err != nil { |
| 773 | return nil, err |
| 774 | } |
| 775 | |
| 776 | permissions := claims.ProjectPermissions(ctx, proj.OrganizationID, proj.ID) |
| 777 | if depl.Environment == "prod" { |
| 778 | if !permissions.ReadProdStatus { |
| 779 | return nil, status.Error(codes.PermissionDenied, "does not have permission to read prod deployment") |
| 780 | } |
| 781 | } else { |
| 782 | if !permissions.ReadDevStatus { |
| 783 | return nil, status.Error(codes.PermissionDenied, "does not have permission to read dev deployment") |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | resp := &adminv1.GetDeploymentConfigResponse{ |
| 788 | FrontendUrl: s.admin.URLs.WithCustomDomain(org.CustomDomain).Project(org.Name, proj.Name), |
| 789 | Editable: depl.Editable, |
| 790 | UpdatedOn: timestamppb.New(depl.UpdatedOn), |
| 791 | UsesArchive: proj.ArchiveAssetID != nil, |
| 792 | } |
| 793 | |
| 794 | // variables |
nothing calls this directly
no test coverage detected