Skip to content

Commit 49856e6

Browse files
committed
chore: mark optional fields
1 parent cf5706b commit 49856e6

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

internal/api/api.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,15 @@ func (a *snykApiClient) GetSastSettings(orgId string) (*sast_contract.SastRespon
249249
}
250250

251251
func (a *snykApiClient) GetOrgSettings(orgId string) (*contract.OrgSettingsResponse, error) {
252-
endpoint := fmt.Sprintf("%s/v1/org/%s/settings", a.url, url.QueryEscape(orgId))
253-
res, err := a.client.Get(endpoint)
254-
if err != nil {
255-
return nil, fmt.Errorf("unable to retrieve org settings: %w", err)
256-
}
257-
//goland:noinspection GoUnhandledErrorResult
258-
defer res.Body.Close()
259-
260-
body, err := io.ReadAll(res.Body)
252+
endpoint := fmt.Sprintf("/v1/org/%s/settings", url.QueryEscape(orgId))
253+
body, err := clientGet(a, endpoint, nil)
261254
if err != nil {
262255
return nil, fmt.Errorf("unable to retrieve org settings: %w", err)
263256
}
264257

265258
var response contract.OrgSettingsResponse
266259
if err = json.Unmarshal(body, &response); err != nil {
267-
return nil, fmt.Errorf("unable to retrieve org settings (status: %d): %w", res.StatusCode, err)
260+
return nil, err
268261
}
269262

270263
return &response, err

internal/api/contract/OrgSettingsResponse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ type OrgRequestAccessSettings struct {
1111
}
1212

1313
type OrgSettingsResponse struct {
14-
Ignores OrgIgnoreSettings `json:"ignores"`
15-
RequestAccess OrgRequestAccessSettings `json:"requestAccess"`
14+
Ignores *OrgIgnoreSettings `json:"ignores"`
15+
RequestAccess *OrgRequestAccessSettings `json:"requestAccess"`
1616
}

pkg/local_workflows/ignore_workflow/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func addCreateIgnoreDefaultConfigurationValues(invocationCtx workflow.Invocation
4545
}
4646

4747
func getOrgIgnoreApprovalEnabled(engine workflow.Engine) configuration.DefaultValueFunction {
48-
return func(existingValue interface{}) (interface{}, error) {
48+
return func(_ configuration.Configuration, existingValue interface{}) (interface{}, error) {
4949
if existingValue != nil {
5050
return existingValue, nil
5151
}
@@ -62,6 +62,10 @@ func getOrgIgnoreApprovalEnabled(engine workflow.Engine) configuration.DefaultVa
6262
return nil, err
6363
}
6464

65+
if settings.Ignores == nil {
66+
return false, nil
67+
}
68+
6569
return settings.Ignores.ApprovalWorkflowEnabled, nil
6670
}
6771
}

pkg/local_workflows/ignore_workflow/ignore_workflow.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,17 @@ func ignoreCreateWorkflowEntryPoint(invocationCtx workflow.InvocationContext, _
103103
id := invocationCtx.GetWorkflowIdentifier()
104104

105105
if !config.GetBool(ConfigIgnoreApprovalEnabled) {
106+
orgName := config.GetString(configuration.ORGANIZATION_SLUG)
106107
return nil, snyk_errors.Error{
107-
ID: "SNYK-CLI-0014",
108-
Title: "Organization setting not enabled",
109-
Description: "The feature you are trying to use is not enabled you the current organization. Enable it in the settings or try switching the organization.",
110-
Detail: "",
111-
Level: "fatal",
108+
Type: "https://docs.snyk.io/scan-with-snyk/error-catalog#snyk-cli-0016",
109+
Title: "Feature not enabled",
110+
Description: "This feature is disabled for your current organization. You can enable it in the settings or switch to an organization where it's already enabled.",
111+
StatusCode: 403,
112+
ErrorCode: "SNYK-CLI-0016",
113+
Classification: "ACTIONABLE",
114+
Links: []string{},
115+
Level: "error",
116+
Detail: fmt.Sprintf("The Ignore Approval Workflow feature must be enabled for the %s organization. Enable it in your organization settings: Settings > General > Ignore approval workflow for Snyk Code.", orgName),
112117
}
113118
}
114119

0 commit comments

Comments
 (0)