mirror of
https://github.com/kubescape/kubescape.git
synced 2026-04-15 06:58:11 +00:00
fixed flaky loop(cautils): loadpolicy getter
We should not inject pointers to the variable iterated over by the "range" operator. Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
This commit is contained in:
committed by
Frédéric BIDON
parent
108a2d6dd8
commit
4752364699
56
.golangci.yml
Normal file
56
.golangci.yml
Normal file
@@ -0,0 +1,56 @@
|
||||
linters-settings:
|
||||
govet:
|
||||
check-shadowing: true
|
||||
maligned:
|
||||
suggest-new: true
|
||||
dupl:
|
||||
threshold: 200
|
||||
goconst:
|
||||
min-len: 3
|
||||
min-occurrences: 2
|
||||
forbidigo:
|
||||
forbid:
|
||||
- ^print.*$
|
||||
- 'fmt\.Print.*'
|
||||
gocognit:
|
||||
min-complexity: 65 # This is super high value. We should gradually lower it to 30-40.
|
||||
|
||||
linters:
|
||||
enable:
|
||||
- gosec
|
||||
disable:
|
||||
- typecheck
|
||||
- errcheck
|
||||
- govet
|
||||
- staticcheck
|
||||
- gosimple
|
||||
- deadcode
|
||||
- gofmt
|
||||
- goimports
|
||||
- bodyclose
|
||||
- dupl
|
||||
#- forbidigo # <- see later
|
||||
- gocognit
|
||||
- gocritic
|
||||
- goimports
|
||||
- nakedret
|
||||
#- nolintlint
|
||||
- revive
|
||||
- stylecheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- maligned
|
||||
- lll
|
||||
- gochecknoinits
|
||||
- gochecknoglobals
|
||||
issues:
|
||||
exclude-rules:
|
||||
- linters:
|
||||
- revive
|
||||
text: "var-naming"
|
||||
- linters:
|
||||
- revive
|
||||
text: "type name will be used as (.+?) by other packages, and that stutters"
|
||||
- linters:
|
||||
- stylecheck
|
||||
text: "ST1003"
|
||||
@@ -36,11 +36,11 @@ func NewLoadPolicy(filePaths []string) *LoadPolicy {
|
||||
}
|
||||
}
|
||||
|
||||
// Return control from file
|
||||
// GetControl returns a control from the policy file.
|
||||
func (lp *LoadPolicy) GetControl(controlID string) (*reporthandling.Control, error) {
|
||||
|
||||
control := &reporthandling.Control{}
|
||||
filePath := lp.filePath()
|
||||
|
||||
f, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -49,20 +49,26 @@ func (lp *LoadPolicy) GetControl(controlID string) (*reporthandling.Control, err
|
||||
if err = json.Unmarshal(f, control); err != nil {
|
||||
return control, err
|
||||
}
|
||||
if controlID != "" && !strings.EqualFold(controlID, control.ControlID) && !strings.EqualFold(controlID, control.ControlID) {
|
||||
framework, err := lp.GetFramework(control.Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("control from file not matching")
|
||||
} else {
|
||||
for _, ctrl := range framework.Controls {
|
||||
if strings.EqualFold(ctrl.ControlID, controlID) || strings.EqualFold(ctrl.ControlID, controlID) {
|
||||
control = &ctrl
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if controlID == "" || strings.EqualFold(controlID, control.ControlID) {
|
||||
return control, nil
|
||||
}
|
||||
|
||||
framework, err := lp.GetFramework(control.Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("control from file not matching")
|
||||
}
|
||||
|
||||
for _, toPin := range framework.Controls {
|
||||
ctrl := toPin
|
||||
if strings.EqualFold(ctrl.ControlID, controlID) {
|
||||
control = &ctrl
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
return control, err
|
||||
|
||||
return control, nil
|
||||
}
|
||||
|
||||
func (lp *LoadPolicy) GetFramework(frameworkName string) (*reporthandling.Framework, error) {
|
||||
|
||||
Reference in New Issue
Block a user