(ctx context.Context, req *adminv1.GetRepoMetaRequest)
| 17 | ) |
| 18 | |
| 19 | func (s *Server) GetRepoMeta(ctx context.Context, req *adminv1.GetRepoMetaRequest) (*adminv1.GetRepoMetaResponse, error) { |
| 20 | observability.AddRequestAttributes(ctx, |
| 21 | attribute.String("args.project_id", req.ProjectId), |
| 22 | ) |
| 23 | |
| 24 | proj, err := s.admin.DB.FindProject(ctx, req.ProjectId) |
| 25 | if err != nil { |
| 26 | return nil, err |
| 27 | } |
| 28 | |
| 29 | claims := auth.GetClaims(ctx) |
| 30 | perms := claims.ProjectPermissions(ctx, proj.OrganizationID, proj.ID) |
| 31 | if !perms.ReadProdStatus && !perms.ReadDevStatus { |
| 32 | return nil, status.Error(codes.PermissionDenied, "does not have permission to read project repo") |
| 33 | } |
| 34 | |
| 35 | if proj.ArchiveAssetID != nil { |
| 36 | asset, err := s.admin.DB.FindAsset(ctx, *proj.ArchiveAssetID) |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | |
| 41 | downloadURL, err := s.generateSignedDownloadURL(asset) |
| 42 | if err != nil { |
| 43 | return nil, status.Error(codes.Internal, err.Error()) |
| 44 | } |
| 45 | return &adminv1.GetRepoMetaResponse{ |
| 46 | ExpiresOn: timestamppb.New(time.Now().Add(time.Hour * 24 * 365)), // Setting to a year because it doesn't need to be refreshed |
| 47 | LastUpdatedOn: timestamppb.New(proj.UpdatedOn), |
| 48 | ArchiveId: asset.ID, |
| 49 | ArchiveDownloadUrl: downloadURL, |
| 50 | ArchiveCreatedOn: timestamppb.New(asset.CreatedOn), |
| 51 | }, nil |
| 52 | } |
| 53 | |
| 54 | if proj.GitRemote == nil || proj.GithubInstallationID == nil { |
| 55 | return nil, status.Error(codes.FailedPrecondition, "project does not have a github integration") |
| 56 | } |
| 57 | |
| 58 | var depl *database.Deployment |
| 59 | if claims.OwnerType() == auth.OwnerTypeDeployment { |
| 60 | var err error |
| 61 | depl, err = s.admin.DB.FindDeployment(ctx, claims.OwnerID()) |
| 62 | if err != nil { |
| 63 | return nil, err |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | repoID, err := s.githubRepoIDForProject(ctx, proj) |
| 68 | if err != nil { |
| 69 | return nil, err |
| 70 | } |
| 71 | |
| 72 | token, expiresAt, err := s.admin.Github.InstallationToken(ctx, *proj.GithubInstallationID, repoID) |
| 73 | if err != nil { |
| 74 | return nil, err |
| 75 | } |
| 76 |
nothing calls this directly
no test coverage detected