diff --git a/pkg/securityconfig/securityconfig.go b/pkg/securityconfig/securityconfig.go index 7d8a208ac8ae..f6429dc06694 100644 --- a/pkg/securityconfig/securityconfig.go +++ b/pkg/securityconfig/securityconfig.go @@ -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"` @@ -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) diff --git a/pkg/securityconfig/securityconfig_test.go b/pkg/securityconfig/securityconfig_test.go index c7fc574e7b95..5e58a94ce33e 100644 --- a/pkg/securityconfig/securityconfig_test.go +++ b/pkg/securityconfig/securityconfig_test.go @@ -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/**"}, @@ -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 +protecode: + - europe-docker.pkg.dev/kyma-project/prod/buildpack-go:v20230717-e09b0fee +mend: + language: golang-mod + subprojects: true + exclude: + - "**/examples/**"`, + }, } for _, c := range tc {