Skip to content
Merged
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
4 changes: 4 additions & 0 deletions app/controlplane/pkg/biz/workflowcontract.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ func (uc *WorkflowContractUseCase) GetPolicy(providerName, policyName, token str

policy, ref, err := provider.Resolve(policyName, token)
if err != nil {
if errors.Is(err, policies.ErrNotFound) {
return nil, NewErrNotFound(fmt.Sprintf("policy %q", policyName))
}

return nil, fmt.Errorf("failed to resolve policy: %w. Available providers: %s", err, uc.policyRegistry.GetProviderNames())
}

Expand Down
7 changes: 7 additions & 0 deletions app/controlplane/pkg/policies/policyprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type PolicyReference struct {
Digest string
}

var ErrNotFound = fmt.Errorf("policy not found")

// Resolve calls the remote provider for retrieving a policy
func (p *PolicyProvider) Resolve(policyName string, token string) (*schemaapi.Policy, *PolicyReference, error) {
if policyName == "" || token == "" {
Expand All @@ -60,7 +62,12 @@ func (p *PolicyProvider) Resolve(policyName string, token string) (*schemaapi.Po
if err != nil {
return nil, nil, fmt.Errorf("error executing policy request: %w", err)
}

if resp.StatusCode != http.StatusOK {
if resp.StatusCode == http.StatusNotFound {
return nil, nil, ErrNotFound
}

return nil, nil, fmt.Errorf("expected status code 200 but got %d", resp.StatusCode)
}

Expand Down