@@ -82,7 +82,6 @@ func setupSBOMReachabilityFlow(
82
82
errFactory * errors.ErrorFactory ,
83
83
logger * zerolog.Logger ,
84
84
sbom , sourceDir string ,
85
- localPolicy * testapi.LocalPolicy ,
86
85
) ([]workflow.Data , error ) {
87
86
config := ictx .GetConfiguration ()
88
87
@@ -106,38 +105,55 @@ func setupSBOMReachabilityFlow(
106
105
)
107
106
108
107
bsClient := bundlestore .NewClient (ictx .GetNetworkAccess ().GetHttpClient (), codeScannerConfig , cScanner , logger )
109
- return RunSbomReachabilityFlow (ctx , ictx , testClient , errFactory , logger , sbom , sourceDir , bsClient , orgID , orgSlugOrID , localPolicy )
108
+ return RunSbomReachabilityFlow (ctx , ictx , testClient , errFactory , logger , sbom , sourceDir , bsClient , orgID , orgSlugOrID )
110
109
}
111
110
112
- // CreateLocalPolicy will create a local policy only if risk score or severity threshold are specified in the config.
113
- func CreateLocalPolicy (config configuration.Configuration , logger * zerolog.Logger ) * testapi.LocalPolicy {
114
- var riskScoreThreshold * uint16
115
- riskScoreThresholdInt := config .GetInt (flags .FlagRiskScoreThreshold )
116
- if riskScoreThresholdInt >= math .MaxUint16 {
111
+ // setupDefaultTestFlow sets up and runs the default test flow with risk score and severity thresholds.
112
+ func setupDefaultTestFlow (
113
+ ctx context.Context ,
114
+ ictx workflow.InvocationContext ,
115
+ testClient testapi.TestClient ,
116
+ orgID string ,
117
+ orgSlugOrID string ,
118
+ errFactory * errors.ErrorFactory ,
119
+ logger * zerolog.Logger ,
120
+ riskScoreThreshold int ,
121
+ ) ([]workflow.Data , error ) {
122
+ config := ictx .GetConfiguration ()
123
+
124
+ // Risk Score FFs
125
+ ffRiskScore := config .GetBool (FeatureFlagRiskScore )
126
+ ffRiskScoreInCLI := config .GetBool (FeatureFlagRiskScoreInCLI )
127
+ riskScoreFFsEnabled := ffRiskScore && ffRiskScoreInCLI
128
+
129
+ if riskScoreThreshold != - 1 && ! riskScoreFFsEnabled {
130
+ // The user tried to use a risk score threshold without the required feature flags.
131
+ // Return a specific error for the first missing flag found.
132
+ if ! ffRiskScore {
133
+ return nil , errFactory .NewFeatureNotPermittedError (FeatureFlagRiskScore )
134
+ }
135
+ return nil , errFactory .NewFeatureNotPermittedError (FeatureFlagRiskScoreInCLI )
136
+ }
137
+
138
+ var riskScorePtr * uint16
139
+ if riskScoreThreshold >= math .MaxUint16 {
117
140
// the API will enforce a range from the test spec
118
- logger .Warn ().Msgf ("Risk score threshold %d exceeds maximum uint16 value. Setting to maximum." , riskScoreThresholdInt )
141
+ logger .Warn ().Msgf ("Risk score threshold %d exceeds maximum uint16 value. Setting to maximum." , riskScoreThreshold )
119
142
maxVal := uint16 (math .MaxUint16 )
120
- riskScoreThreshold = & maxVal
121
- } else if riskScoreThresholdInt >= 0 {
122
- rs := uint16 (riskScoreThresholdInt )
123
- riskScoreThreshold = & rs
143
+ riskScorePtr = & maxVal
144
+ } else if riskScoreThreshold >= 0 {
145
+ rs := uint16 (riskScoreThreshold )
146
+ riskScorePtr = & rs
124
147
}
125
148
126
- var severityThreshold * testapi.Severity
149
+ var severityThresholdPtr * testapi.Severity
127
150
severityThresholdStr := config .GetString (flags .FlagSeverityThreshold )
128
151
if severityThresholdStr != "" {
129
152
st := testapi .Severity (severityThresholdStr )
130
- severityThreshold = & st
153
+ severityThresholdPtr = & st
131
154
}
132
155
133
- if riskScoreThreshold == nil && severityThreshold == nil {
134
- return nil
135
- }
136
-
137
- return & testapi.LocalPolicy {
138
- RiskScoreThreshold : riskScoreThreshold ,
139
- SeverityThreshold : severityThreshold ,
140
- }
156
+ return RunUnifiedTestFlow (ctx , ictx , testClient , riskScorePtr , severityThresholdPtr , orgID , orgSlugOrID , errFactory , logger )
141
157
}
142
158
143
159
// OSWorkflow is the entry point for the Open Source Test workflow.
@@ -187,17 +203,6 @@ func OSWorkflow(
187
203
orgSlugOrID = orgID
188
204
}
189
205
190
- if riskScoreThreshold != - 1 && ! riskScoreFFsEnabled {
191
- // The user tried to use a risk score threshold without the required feature flags.
192
- // Return a specific error for the first missing flag found.
193
- if ! ffRiskScore {
194
- return nil , errFactory .NewFeatureNotPermittedError (FeatureFlagRiskScore )
195
- }
196
- return nil , errFactory .NewFeatureNotPermittedError (FeatureFlagRiskScoreInCLI )
197
- }
198
-
199
- localPolicy := CreateLocalPolicy (config , logger )
200
-
201
206
// Create Snyk client
202
207
httpClient := ictx .GetNetworkAccess ().GetHttpClient ()
203
208
snykClient := snykclient .NewSnykClient (httpClient , ictx .GetConfiguration ().GetString (configuration .API_URL ), orgID )
@@ -215,8 +220,8 @@ func OSWorkflow(
215
220
// Route to the appropriate flow based on flags
216
221
switch {
217
222
case sbomReachabilityTest :
218
- return setupSBOMReachabilityFlow (ctx , ictx , testClient , orgID , orgSlugOrID , errFactory , logger , sbom , sourceDir , localPolicy )
223
+ return setupSBOMReachabilityFlow (ctx , ictx , testClient , orgID , orgSlugOrID , errFactory , logger , sbom , sourceDir )
219
224
default :
220
- return RunUnifiedTestFlow (ctx , ictx , testClient , orgID , orgSlugOrID , errFactory , logger , localPolicy )
225
+ return setupDefaultTestFlow (ctx , ictx , testClient , orgID , orgSlugOrID , errFactory , logger , riskScoreThreshold )
221
226
}
222
227
}
0 commit comments