-
Notifications
You must be signed in to change notification settings - Fork 0
Reapply "Merge pull request #40 from snyk/feat(reachability)/pass-loc… #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+94
−58
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ func setupSBOMReachabilityFlow( | |
errFactory *errors.ErrorFactory, | ||
logger *zerolog.Logger, | ||
sbom, sourceDir string, | ||
localPolicy *testapi.LocalPolicy, | ||
) ([]workflow.Data, error) { | ||
config := ictx.GetConfiguration() | ||
|
||
|
@@ -104,54 +105,38 @@ func setupSBOMReachabilityFlow( | |
) | ||
|
||
bsClient := bundlestore.NewClient(ictx.GetNetworkAccess().GetHttpClient(), codeScannerConfig, cScanner, logger) | ||
return RunSbomReachabilityFlow(ctx, ictx, testClient, errFactory, logger, sbom, sourceDir, bsClient, orgID) | ||
return RunSbomReachabilityFlow(ctx, ictx, testClient, errFactory, logger, sbom, sourceDir, bsClient, orgID, localPolicy) | ||
} | ||
|
||
// setupDefaultTestFlow sets up and runs the default test flow with risk score and severity thresholds. | ||
func setupDefaultTestFlow( | ||
ctx context.Context, | ||
ictx workflow.InvocationContext, | ||
testClient testapi.TestClient, | ||
orgID string, | ||
errFactory *errors.ErrorFactory, | ||
logger *zerolog.Logger, | ||
riskScoreThreshold int, | ||
) ([]workflow.Data, error) { | ||
config := ictx.GetConfiguration() | ||
|
||
// Risk Score FFs | ||
ffRiskScore := config.GetBool(FeatureFlagRiskScore) | ||
ffRiskScoreInCLI := config.GetBool(FeatureFlagRiskScoreInCLI) | ||
riskScoreFFsEnabled := ffRiskScore && ffRiskScoreInCLI | ||
|
||
if riskScoreThreshold != -1 && !riskScoreFFsEnabled { | ||
// The user tried to use a risk score threshold without the required feature flags. | ||
// Return a specific error for the first missing flag found. | ||
if !ffRiskScore { | ||
return nil, errFactory.NewFeatureNotPermittedError(FeatureFlagRiskScore) | ||
} | ||
return nil, errFactory.NewFeatureNotPermittedError(FeatureFlagRiskScoreInCLI) | ||
} | ||
|
||
var riskScorePtr *uint16 | ||
if riskScoreThreshold >= math.MaxUint16 { | ||
// CreateLocalPolicy will create a local policy only if risk score or severity threshold are specified in the config. | ||
func CreateLocalPolicy(config configuration.Configuration, logger *zerolog.Logger) *testapi.LocalPolicy { | ||
var riskScoreThreshold *uint16 | ||
riskScoreThresholdInt := config.GetInt(flags.FlagRiskScoreThreshold) | ||
if riskScoreThresholdInt >= math.MaxUint16 { | ||
// the API will enforce a range from the test spec | ||
logger.Warn().Msgf("Risk score threshold %d exceeds maximum uint16 value. Setting to maximum.", riskScoreThreshold) | ||
logger.Warn().Msgf("Risk score threshold %d exceeds maximum uint16 value. Setting to maximum.", riskScoreThresholdInt) | ||
maxVal := uint16(math.MaxUint16) | ||
riskScorePtr = &maxVal | ||
} else if riskScoreThreshold >= 0 { | ||
rs := uint16(riskScoreThreshold) | ||
riskScorePtr = &rs | ||
riskScoreThreshold = &maxVal | ||
} else if riskScoreThresholdInt >= 0 { | ||
rs := uint16(riskScoreThresholdInt) | ||
riskScoreThreshold = &rs | ||
} | ||
|
||
var severityThresholdPtr *testapi.Severity | ||
var severityThreshold *testapi.Severity | ||
severityThresholdStr := config.GetString(flags.FlagSeverityThreshold) | ||
if severityThresholdStr != "" { | ||
st := testapi.Severity(severityThresholdStr) | ||
severityThresholdPtr = &st | ||
severityThreshold = &st | ||
} | ||
|
||
return RunUnifiedTestFlow(ctx, ictx, testClient, riskScorePtr, severityThresholdPtr, orgID, errFactory, logger) | ||
if riskScoreThreshold == nil && severityThreshold == nil { | ||
return nil | ||
} | ||
|
||
return &testapi.LocalPolicy{ | ||
RiskScoreThreshold: riskScoreThreshold, | ||
SeverityThreshold: severityThreshold, | ||
} | ||
} | ||
|
||
// OSWorkflow is the entry point for the Open Source Test workflow. | ||
|
@@ -195,6 +180,17 @@ func OSWorkflow( | |
return nil, errFactory.NewEmptyOrgError() | ||
} | ||
|
||
if riskScoreThreshold != -1 && !riskScoreFFsEnabled { | ||
// The user tried to use a risk score threshold without the required feature flags. | ||
// Return a specific error for the first missing flag found. | ||
if !ffRiskScore { | ||
return nil, errFactory.NewFeatureNotPermittedError(FeatureFlagRiskScore) | ||
} | ||
return nil, errFactory.NewFeatureNotPermittedError(FeatureFlagRiskScoreInCLI) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Feature Flag Validation Scope ErrorMoving the risk score feature flag validation from
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
localPolicy := CreateLocalPolicy(config, logger) | ||
|
||
// Create Snyk client | ||
httpClient := ictx.GetNetworkAccess().GetHttpClient() | ||
snykClient := snykclient.NewSnykClient(httpClient, ictx.GetConfiguration().GetString(configuration.API_URL), orgID) | ||
|
@@ -212,8 +208,8 @@ func OSWorkflow( | |
// Route to the appropriate flow based on flags | ||
switch { | ||
case sbomReachabilityTest: | ||
return setupSBOMReachabilityFlow(ctx, ictx, testClient, orgID, errFactory, logger, sbom, sourceDir) | ||
return setupSBOMReachabilityFlow(ctx, ictx, testClient, orgID, errFactory, logger, sbom, sourceDir, localPolicy) | ||
default: | ||
return setupDefaultTestFlow(ctx, ictx, testClient, orgID, errFactory, logger, riskScoreThreshold) | ||
return RunUnifiedTestFlow(ctx, ictx, testClient, orgID, errFactory, logger, localPolicy) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.