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