Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 79 additions & 63 deletions app/controlplane/api/controlplane/v1/organization.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions app/controlplane/api/controlplane/v1/organization.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ message OrganizationServiceUpdateRequest {

// prevent workflows and projects from being created implicitly during attestation init
optional bool prevent_implicit_workflow_creation = 5;

// prevent_project_scoped_contracts restricts contract creation to only organization-level contracts
optional bool prevent_project_scoped_contracts = 6;
}

message OrganizationServiceUpdateResponse {
Expand Down
331 changes: 172 additions & 159 deletions app/controlplane/api/controlplane/v1/response_messages.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/controlplane/api/controlplane/v1/response_messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ message OrgItem {
repeated string policy_allowed_hostnames = 5;
// prevent workflows and projects from being created implicitly during attestation init
bool prevent_implicit_workflow_creation = 7;
// prevent_project_scoped_contracts restricts contract creation to only organization-level contracts
bool prevent_project_scoped_contracts = 8;

enum PolicyViolationBlockingStrategy {
POLICY_VIOLATION_BLOCKING_STRATEGY_UNSPECIFIED = 0;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/controlplane/cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/controlplane/internal/service/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func bizOrgToPb(m *biz.Organization) *pb.OrgItem {
DefaultPolicyViolationStrategy: bizPolicyViolationBlockingStrategyToPb(m.BlockOnPolicyViolation),
PolicyAllowedHostnames: m.PoliciesAllowedHostnames,
PreventImplicitWorkflowCreation: m.PreventImplicitWorkflowCreation,
PreventProjectScopedContracts: m.PreventProjectScopedContracts,
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/controlplane/internal/service/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *OrganizationService) Update(ctx context.Context, req *pb.OrganizationSe
}
}

org, err := s.orgUC.Update(ctx, currentUser.ID, req.Name, req.BlockOnPolicyViolation, policiesAllowedHostnames, req.PreventImplicitWorkflowCreation)
org, err := s.orgUC.Update(ctx, currentUser.ID, req.Name, req.BlockOnPolicyViolation, policiesAllowedHostnames, req.PreventImplicitWorkflowCreation, req.PreventProjectScopedContracts)
if err != nil {
return nil, handleUseCaseErr(err, s.log)
}
Expand Down
15 changes: 14 additions & 1 deletion app/controlplane/internal/service/workflowcontract.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ type WorkflowContractService struct {
*service

contractUseCase *biz.WorkflowContractUseCase
orgUseCase *biz.OrganizationUseCase
}

func NewWorkflowSchemaService(uc *biz.WorkflowContractUseCase, opts ...NewOpt) *WorkflowContractService {
func NewWorkflowSchemaService(uc *biz.WorkflowContractUseCase, orgUC *biz.OrganizationUseCase, opts ...NewOpt) *WorkflowContractService {
return &WorkflowContractService{
service: newService(opts...),
contractUseCase: uc,
orgUseCase: orgUC,
}
}

Expand Down Expand Up @@ -109,9 +111,20 @@ func (s *WorkflowContractService) Create(ctx context.Context, req *pb.WorkflowCo
return nil, errors.BadRequest("invalid", "project is required")
}

// Check organization settings for project-scoped contracts
org, err := s.orgUseCase.FindByID(ctx, currentOrg.ID)
if err != nil {
return nil, handleUseCaseErr(err, s.log)
}

// if the project is provided we make sure it exists and the user has permission to it
var projectID *uuid.UUID
if req.ProjectReference.IsSet() {
// Check if organization prevents project-scoped contracts
if org.PreventProjectScopedContracts {
return nil, errors.BadRequest("invalid", "organization does not allow project-scoped contracts")
}

// Make sure the provided project exists and the user has permission to create tokens in it
project, err := s.userHasPermissionOnProject(ctx, currentOrg.ID, req.GetProjectReference(), authz.PolicyWorkflowContractCreate)
if err != nil {
Expand Down
30 changes: 18 additions & 12 deletions app/controlplane/pkg/biz/mocks/OrganizationRepo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading