(ctx context.Context, req *adminv1.GetProjectVariablesRequest)
| 895 | } |
| 896 | |
| 897 | func (s *Server) GetProjectVariables(ctx context.Context, req *adminv1.GetProjectVariablesRequest) (*adminv1.GetProjectVariablesResponse, error) { |
| 898 | observability.AddRequestAttributes(ctx, |
| 899 | attribute.String("args.org", req.Org), |
| 900 | attribute.String("args.project", req.Project), |
| 901 | attribute.String("args.environment", req.Environment), |
| 902 | attribute.Bool("args.for_all_environments", req.ForAllEnvironments), |
| 903 | ) |
| 904 | |
| 905 | proj, err := s.admin.DB.FindProjectByName(ctx, req.Org, req.Project) |
| 906 | if err != nil { |
| 907 | return nil, err |
| 908 | } |
| 909 | |
| 910 | claims := auth.GetClaims(ctx) |
| 911 | perms := claims.ProjectPermissions(ctx, proj.OrganizationID, proj.ID) |
| 912 | excludeProd := false |
| 913 | if !perms.ReadDevStatus && !perms.ReadProdStatus { |
| 914 | return nil, status.Error(codes.PermissionDenied, "does not have permission to read variables") |
| 915 | } |
| 916 | if !perms.ReadProdStatus { |
| 917 | if req.Environment == "prod" { |
| 918 | return nil, status.Error(codes.PermissionDenied, "does not have permission to read variables for the prod environment") |
| 919 | } |
| 920 | excludeProd = true |
| 921 | } |
| 922 | // NOTE: Not explicitly checking ReadDevStatus for non-prod environments for simplicity; if you have ReadProdStatus, you're good to read variables for non-prod envs as well. |
| 923 | |
| 924 | var vars []*database.ProjectVariable |
| 925 | if req.ForAllEnvironments { |
| 926 | vars, err = s.admin.DB.FindProjectVariables(ctx, proj.ID, nil) |
| 927 | } else { |
| 928 | vars, err = s.admin.DB.FindProjectVariables(ctx, proj.ID, &req.Environment) |
| 929 | } |
| 930 | if err != nil { |
| 931 | return nil, err |
| 932 | } |
| 933 | |
| 934 | resp := &adminv1.GetProjectVariablesResponse{ |
| 935 | Variables: make([]*adminv1.ProjectVariable, 0, len(vars)), |
| 936 | VariablesMap: make(map[string]string, len(vars)), |
| 937 | } |
| 938 | for _, v := range vars { |
| 939 | if excludeProd && v.Environment == "prod" { |
| 940 | continue |
| 941 | } |
| 942 | resp.Variables = append(resp.Variables, projectVariableToDTO(v)) |
| 943 | // nolint:staticcheck // We still need to set it |
| 944 | resp.VariablesMap[v.Name] = v.Value |
| 945 | } |
| 946 | return resp, nil |
| 947 | } |
| 948 | |
| 949 | func (s *Server) UpdateProjectVariables(ctx context.Context, req *adminv1.UpdateProjectVariablesRequest) (*adminv1.UpdateProjectVariablesResponse, error) { |
| 950 | observability.AddRequestAttributes(ctx, |
nothing calls this directly
no test coverage detected