-
Notifications
You must be signed in to change notification settings - Fork 25
Fix panic exit when containers ff could not be fetched (AST-86767) #1069
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
Changes from 3 commits
b4c4363
e44ddf5
f456710
6f4ab3d
c0e882a
d7e442a
8e04288
6bbf975
e597658
8825f28
c86df91
a17a6c6
8535a17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1123,7 +1123,7 @@ func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featu | |
var scanTypes []string | ||
var SCSScanTypes []string | ||
|
||
containerEngineCLIEnabled, _ := featureFlagsWrapper.GetSpecificFlag(wrappers.ContainerEngineCLIEnabled) | ||
runContainerEngineCLI := isContainersEngineEnabled(featureFlagsWrapper) | ||
allowedEngines, err := jwtWrapper.GetAllowedEngines(featureFlagsWrapper) | ||
if err != nil { | ||
err = errors.Errorf("Error validating scan types: %v", err) | ||
|
@@ -1140,7 +1140,7 @@ func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featu | |
|
||
scanTypes = strings.Split(userScanTypes, ",") | ||
for _, scanType := range scanTypes { | ||
if !allowedEngines[scanType] || (scanType == commonParams.ContainersType && !(containerEngineCLIEnabled.Status)) { | ||
if !allowedEngines[scanType] || (scanType == commonParams.ContainersType && !(runContainerEngineCLI)) { | ||
keys := reflect.ValueOf(allowedEngines).MapKeys() | ||
err = errors.Errorf(engineNotAllowed, scanType, scanType, keys) | ||
return err | ||
|
@@ -1156,7 +1156,7 @@ func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featu | |
|
||
} else { | ||
for k := range allowedEngines { | ||
if k == commonParams.ContainersType && !(containerEngineCLIEnabled.Status) { | ||
if k == commonParams.ContainersType && !(runContainerEngineCLI) { | ||
continue | ||
} | ||
scanTypes = append(scanTypes, k) | ||
|
@@ -1169,6 +1169,19 @@ func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featu | |
return nil | ||
} | ||
|
||
func isContainersEngineEnabled(featureFlagsWrapper wrappers.FeatureFlagsWrapper) bool { | ||
runContainerEngineCLI := true | ||
|
||
containerEngineCLIEnabled, err := featureFlagsWrapper.GetSpecificFlag(wrappers.ContainerEngineCLIEnabled) | ||
if err != nil { | ||
logger.PrintfIfVerbose("could not get CONTAINER_ENGINE_CLI_ENABLED FF. defaulting to `false` error: %s", err) | ||
runContainerEngineCLI = false | ||
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. If retrieving the Feature Flag fails (e.g., due to a network issue), the function defaults to false, which could mistakenly disable container scanning. Should the default be true or false? Defining it clearly would avoid confusion. or maybe, return an error and let the user decide... 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. if we can not determine a FF i would like it to default to false. we also add a log here so the user can understand what happen. do u think it should be defaulted to true? 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. Defaulting to false with clear logging makes the most sense. When we can't get the feature flag, we should turn scanning off and tell the user what happened. This way they know scanning is off and why. We should check if false is really the safer default, |
||
} else { | ||
runContainerEngineCLI = containerEngineCLIEnabled.Status | ||
} | ||
return runContainerEngineCLI | ||
} | ||
|
||
func scanTypeEnabled(scanType string) bool { | ||
scanTypes := strings.Split(actualScanTypes, ",") | ||
for _, a := range scanTypes { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this value necessary if it will be overwritten later anyway, whether there's an error or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i need to define the var outside the if/else scope. but you are right we can initialize it as nil.