Skip to content
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

Rename fields in security config, support both names by custom unmarshal #12626

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions pkg/securityconfig/securityconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package securityconfig
import (
"io"
"os"
"reflect"

"gopkg.in/yaml.v3"
)

type CheckmarxOne struct {
Preset string `yaml:"preset,omitempty"`
Exclude []string `yaml:"exclude,omitempty"`
Preset string `yaml:"preset,omitempty"`
Exclude []string `yaml:"exclude,omitempty"`
}

type Whitesource struct {
type Mend struct {
Language string `yaml:"language,omitempty"`
SubProjects bool `yaml:"subprojects,omitempty"`
Exclude []string `yaml:"exclude,omitempty"`
Expand All @@ -22,11 +23,47 @@ type SecurityConfig struct {
ModuleName string `yaml:"module-name,omitempty"`
RcTag string `yaml:"rc-tag,omitempty"`
Kind string `yaml:"kind,omitempty"`
Images []string `yaml:"protecode"`
Whitesource Whitesource `yaml:"whitesource,omitempty"`
Images []string `yaml:"bdba,omitempty"`
Mend Mend `yaml:"mend,omitempty"`
CheckmarxOne CheckmarxOne `yaml:"checkmarx-one,omitempty"`
}

// TODO(kacpermalachowski): Remove after migration to the new field names
// see: https://github.tools.sap/kyma/test-infra/issues/491
func (config *SecurityConfig) UnmarshalYAML(value *yaml.Node) error {
// Cannot use inheritance due to infinite loop
var cfg struct {
ModuleName string `yaml:"module-name,omitempty"`
RcTag string `yaml:"rc-tag,omitempty"`
Kind string `yaml:"kind,omitempty"`
Images []string `yaml:"bdba,omitempty"`
Mend Mend `yaml:"mend,omitempty"`
CheckmarxOne CheckmarxOne `yaml:"checkmarx-one,omitempty"`
Protecode []string `yaml:"protecode,omitempty"`
Whitesource Mend `yaml:"whitesource,omitempty"`
}

if err := value.Decode(&cfg); err != nil {
return err
}

config.ModuleName = cfg.ModuleName
config.RcTag = cfg.RcTag
config.Kind = cfg.Kind
config.Images = cfg.Images
config.Mend = cfg.Mend

if len(cfg.Protecode) > 0 {
config.Images = cfg.Protecode
}

if !reflect.DeepEqual(cfg.Whitesource, Mend{}) {
config.Mend = cfg.Whitesource
}

return nil
}

func ParseSecurityConfig(reader io.Reader) (*SecurityConfig, error) {
var securityConfig SecurityConfig
err := yaml.NewDecoder(reader).Decode(&securityConfig)
Expand Down
23 changes: 22 additions & 1 deletion pkg/securityconfig/securityconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestLoadSecurityConfig(t *testing.T) {
ExpectedConfig: &SecurityConfig{
ModuleName: "test-infra",
Images: []string{"europe-docker.pkg.dev/kyma-project/prod/buildpack-go:v20230717-e09b0fee"},
Whitesource: Whitesource{
Mend: Mend{
Language: "golang-mod",
SubProjects: true,
Exclude: []string{"**/examples/**"},
Expand All @@ -40,6 +40,27 @@ whitesource:
ExpectedConfig: nil,
FileContent: ``,
},
{
Name: "Valid config with mend, pass",
WantErr: false,
ExpectedConfig: &SecurityConfig{
ModuleName: "test-infra",
Images: []string{"europe-docker.pkg.dev/kyma-project/prod/buildpack-go:v20230717-e09b0fee"},
Mend: Mend{
Language: "golang-mod",
SubProjects: true,
Exclude: []string{"**/examples/**"},
},
},
FileContent: `module-name: test-infra
bdba:
- europe-docker.pkg.dev/kyma-project/prod/buildpack-go:v20230717-e09b0fee
mend:
language: golang-mod
subprojects: true
exclude:
- "**/examples/**"`,
},
}

for _, c := range tc {
Expand Down
22 changes: 11 additions & 11 deletions sec-scanners-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module-name: test-infra
rc-tag: rc-tag
kind: kyma
protecode:
- europe-docker.pkg.dev/kyma-project/prod/cors-proxy:v20250131-b15f4e86
- europe-docker.pkg.dev/kyma-project/prod/create-github-issue:v20250131-b15f4e86
- europe-docker.pkg.dev/kyma-project/prod/dashboard-token-proxy:v20250131-b15f4e86
- europe-docker.pkg.dev/kyma-project/prod/github-webhook-gateway:v20250131-b15f4e86
- europe-docker.pkg.dev/kyma-project/prod/move-gcs-bucket:v20250131-b15f4e86
- europe-docker.pkg.dev/kyma-project/prod/scan-logs-for-secrets:v20250131-b15f4e86
- europe-docker.pkg.dev/kyma-project/prod/search-github-issue:v20250131-b15f4e86
- europe-docker.pkg.dev/kyma-project/prod/test-infra/rotate-service-account:v20250131-b15f4e86
- europe-docker.pkg.dev/kyma-project/prod/test-infra/service-account-keys-cleaner:v20250131-b15f4e86
bdba:
- europe-docker.pkg.dev/kyma-project/prod/cors-proxy:v20250131-885542fa
- europe-docker.pkg.dev/kyma-project/prod/create-github-issue:v20250131-885542fa
- europe-docker.pkg.dev/kyma-project/prod/dashboard-token-proxy:v20250131-885542fa
- europe-docker.pkg.dev/kyma-project/prod/github-webhook-gateway:v20250131-885542fa
- europe-docker.pkg.dev/kyma-project/prod/move-gcs-bucket:v20250131-885542fa
- europe-docker.pkg.dev/kyma-project/prod/scan-logs-for-secrets:v20250131-885542fa
- europe-docker.pkg.dev/kyma-project/prod/search-github-issue:v20250131-885542fa
- europe-docker.pkg.dev/kyma-project/prod/test-infra/rotate-service-account:v20250131-885542fa
- europe-docker.pkg.dev/kyma-project/prod/test-infra/service-account-keys-cleaner:v20250131-885542fa
- europe-docker.pkg.dev/kyma-project/prod/test-infra/signify-secret-rotator:v20250108-fae88ec9
- europe-docker.pkg.dev/kyma-project/prod/test-infra/slackmessagesender:v20250108-fae88ec9
whitesource:
mend:
language: golang-mod
exclude:
- '**/*_test.go'
Expand Down
Loading