@@ -82,6 +82,7 @@ func setupSBOMReachabilityFlow(
82
82
errFactory * errors.ErrorFactory ,
83
83
logger * zerolog.Logger ,
84
84
sbom , sourceDir string ,
85
+ localPolicy * testapi.LocalPolicy ,
85
86
) ([]workflow.Data , error ) {
86
87
config := ictx .GetConfiguration ()
87
88
@@ -105,55 +106,38 @@ func setupSBOMReachabilityFlow(
105
106
)
106
107
107
108
bsClient := bundlestore .NewClient (ictx .GetNetworkAccess ().GetHttpClient (), codeScannerConfig , cScanner , logger )
108
- return RunSbomReachabilityFlow (ctx , ictx , testClient , errFactory , logger , sbom , sourceDir , bsClient , orgID , orgSlugOrID )
109
+ return RunSbomReachabilityFlow (ctx , ictx , testClient , errFactory , logger , sbom , sourceDir , bsClient , orgID , orgSlugOrID , localPolicy )
109
110
}
110
111
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 {
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 {
140
117
// the API will enforce a range from the test spec
141
- logger .Warn ().Msgf ("Risk score threshold %d exceeds maximum uint16 value. Setting to maximum." , riskScoreThreshold )
118
+ logger .Warn ().Msgf ("Risk score threshold %d exceeds maximum uint16 value. Setting to maximum." , riskScoreThresholdInt )
142
119
maxVal := uint16 (math .MaxUint16 )
143
- riskScorePtr = & maxVal
144
- } else if riskScoreThreshold >= 0 {
145
- rs := uint16 (riskScoreThreshold )
146
- riskScorePtr = & rs
120
+ riskScoreThreshold = & maxVal
121
+ } else if riskScoreThresholdInt >= 0 {
122
+ rs := uint16 (riskScoreThresholdInt )
123
+ riskScoreThreshold = & rs
147
124
}
148
125
149
- var severityThresholdPtr * testapi.Severity
126
+ var severityThreshold * testapi.Severity
150
127
severityThresholdStr := config .GetString (flags .FlagSeverityThreshold )
151
128
if severityThresholdStr != "" {
152
129
st := testapi .Severity (severityThresholdStr )
153
- severityThresholdPtr = & st
130
+ severityThreshold = & st
154
131
}
155
132
156
- return RunUnifiedTestFlow (ctx , ictx , testClient , riskScorePtr , severityThresholdPtr , orgID , orgSlugOrID , errFactory , logger )
133
+ if riskScoreThreshold == nil && severityThreshold == nil {
134
+ return nil
135
+ }
136
+
137
+ return & testapi.LocalPolicy {
138
+ RiskScoreThreshold : riskScoreThreshold ,
139
+ SeverityThreshold : severityThreshold ,
140
+ }
157
141
}
158
142
159
143
// OSWorkflow is the entry point for the Open Source Test workflow.
@@ -203,6 +187,17 @@ func OSWorkflow(
203
187
orgSlugOrID = orgID
204
188
}
205
189
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
+
206
201
// Create Snyk client
207
202
httpClient := ictx .GetNetworkAccess ().GetHttpClient ()
208
203
snykClient := snykclient .NewSnykClient (httpClient , ictx .GetConfiguration ().GetString (configuration .API_URL ), orgID )
@@ -220,8 +215,8 @@ func OSWorkflow(
220
215
// Route to the appropriate flow based on flags
221
216
switch {
222
217
case sbomReachabilityTest :
223
- return setupSBOMReachabilityFlow (ctx , ictx , testClient , orgID , orgSlugOrID , errFactory , logger , sbom , sourceDir )
218
+ return setupSBOMReachabilityFlow (ctx , ictx , testClient , orgID , orgSlugOrID , errFactory , logger , sbom , sourceDir , localPolicy )
224
219
default :
225
- return setupDefaultTestFlow (ctx , ictx , testClient , orgID , orgSlugOrID , errFactory , logger , riskScoreThreshold )
220
+ return RunUnifiedTestFlow (ctx , ictx , testClient , orgID , orgSlugOrID , errFactory , logger , localPolicy )
226
221
}
227
222
}
0 commit comments