Skip to content

Commit

Permalink
Rename fields in security config, support both names by custom unmars…
Browse files Browse the repository at this point in the history
…hal (#12626)

* Rename fields in config, support both names by custom unmarshal

* Move to new config names

* Rename to bdba
  • Loading branch information
KacperMalachowski authored Feb 3, 2025
1 parent 6a08187 commit a06d205
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 17 deletions.
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

0 comments on commit a06d205

Please sign in to comment.