(ctx context.Context, req *adminv1.CreateProjectRequest)
| 447 | } |
| 448 | |
| 449 | func (s *Server) CreateProject(ctx context.Context, req *adminv1.CreateProjectRequest) (*adminv1.CreateProjectResponse, error) { |
| 450 | observability.AddRequestAttributes(ctx, |
| 451 | attribute.String("args.org", req.Org), |
| 452 | attribute.String("args.project", req.Project), |
| 453 | attribute.String("args.description", req.Description), |
| 454 | attribute.Bool("args.public", req.Public), |
| 455 | attribute.String("args.directory_name", req.DirectoryName), |
| 456 | attribute.String("args.provisioner", req.Provisioner), |
| 457 | attribute.String("args.prod_version", req.ProdVersion), |
| 458 | attribute.Int64("args.prod_slots", req.ProdSlots), |
| 459 | attribute.Int64("args.dev_slots", req.DevSlots), |
| 460 | attribute.String("args.sub_path", req.Subpath), |
| 461 | attribute.String("args.primary_branch", req.PrimaryBranch), |
| 462 | attribute.String("args.git_remote", req.GitRemote), |
| 463 | attribute.String("args.archive_asset_id", req.ArchiveAssetId), |
| 464 | attribute.Bool("args.skip_deploy", req.SkipDeploy), |
| 465 | ) |
| 466 | |
| 467 | // Backwards compatibility |
| 468 | req.GitRemote = normalizeGitRemote(req.GitRemote) |
| 469 | |
| 470 | // Find parent org |
| 471 | org, err := s.admin.DB.FindOrganizationByName(ctx, req.Org) |
| 472 | if err != nil { |
| 473 | return nil, err |
| 474 | } |
| 475 | |
| 476 | // Check permissions |
| 477 | claims := auth.GetClaims(ctx) |
| 478 | if !claims.OrganizationPermissions(ctx, org.ID).CreateProjects { |
| 479 | return nil, status.Error(codes.PermissionDenied, "does not have permission to create projects") |
| 480 | } |
| 481 | |
| 482 | // check if org has any blocking billing errors |
| 483 | err = s.admin.CheckBlockingBillingErrors(ctx, org.ID) |
| 484 | if err != nil { |
| 485 | if errors.Is(err, admin.ErrBlockingBillingIssue) { |
| 486 | return nil, status.Error(codes.FailedPrecondition, err.Error()) |
| 487 | } |
| 488 | return nil, err |
| 489 | } |
| 490 | |
| 491 | // Apply defaults when slots are omitted (e.g. the UI, or older CLIs that don't pass these fields). |
| 492 | prodSlots := int(req.ProdSlots) |
| 493 | if prodSlots == 0 { |
| 494 | prodSlots = defaultProdSlots |
| 495 | } |
| 496 | devSlots := int(req.DevSlots) |
| 497 | if devSlots == 0 { |
| 498 | devSlots = defaultDevSlots |
| 499 | } |
| 500 | |
| 501 | // Check projects quota |
| 502 | usage, err := s.admin.DB.CountProjectsQuotaUsage(ctx, org.ID) |
| 503 | if err != nil { |
| 504 | return nil, err |
| 505 | } |
| 506 | if org.QuotaProjects >= 0 && usage.Projects >= org.QuotaProjects { |
nothing calls this directly
no test coverage detected