mirror of
https://github.com/kyverno/policy-reporter.git
synced 2024-12-14 11:57:32 +00:00
Fix CustomFields mapping
Signed-off-by: Frank Jogeleit <frank.jogeleit@web.de>
This commit is contained in:
parent
621cdbbced
commit
3db2765f90
6 changed files with 133 additions and 15 deletions
|
@ -1,5 +1,8 @@
|
|||
# Changelog
|
||||
|
||||
# 2.13.4
|
||||
* Fix `customFields` mapping in TargetFactory
|
||||
|
||||
# 2.13.3
|
||||
* Fix `customFields` property in values.yaml
|
||||
* Fix PolicyReporter `image.tag` version
|
||||
|
|
|
@ -5,8 +5,8 @@ description: |
|
|||
It creates Prometheus Metrics and can send rule validation events to different targets like Loki, Elasticsearch, Slack or Discord
|
||||
|
||||
type: application
|
||||
version: 2.13.3
|
||||
appVersion: 2.10.2
|
||||
version: 2.13.4
|
||||
appVersion: 2.10.3
|
||||
|
||||
icon: https://github.com/kyverno/kyverno/raw/main/img/logo.png
|
||||
home: https://kyverno.github.io/policy-reporter
|
||||
|
|
|
@ -2,7 +2,7 @@ image:
|
|||
registry: ghcr.io
|
||||
repository: kyverno/policy-reporter
|
||||
pullPolicy: IfNotPresent
|
||||
tag: 2.10.2
|
||||
tag: 2.10.3
|
||||
|
||||
imagePullSecrets: []
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ var testConfig = &config.Config{
|
|||
Webhook: "http://hook.slack:80",
|
||||
SkipExisting: true,
|
||||
MinimumPriority: "debug",
|
||||
CustomFields: map[string]string{"field": "value"},
|
||||
Channels: []config.Slack{{
|
||||
Webhook: "http://localhost:9200",
|
||||
}},
|
||||
|
@ -44,6 +45,7 @@ var testConfig = &config.Config{
|
|||
Webhook: "http://hook.discord:80",
|
||||
SkipExisting: true,
|
||||
MinimumPriority: "debug",
|
||||
CustomFields: map[string]string{"field": "value"},
|
||||
Channels: []config.Discord{{
|
||||
Webhook: "http://localhost:9200",
|
||||
}},
|
||||
|
@ -53,6 +55,7 @@ var testConfig = &config.Config{
|
|||
SkipTLS: true,
|
||||
SkipExisting: true,
|
||||
MinimumPriority: "debug",
|
||||
CustomFields: map[string]string{"field": "value"},
|
||||
Channels: []config.Teams{{
|
||||
Webhook: "http://localhost:9200",
|
||||
}},
|
||||
|
@ -70,6 +73,7 @@ var testConfig = &config.Config{
|
|||
SkipExisting: true,
|
||||
SkipTLS: true,
|
||||
MinimumPriority: "debug",
|
||||
CustomFields: map[string]string{"field": "value"},
|
||||
Channels: []config.Webhook{{
|
||||
Host: "http://localhost:8081",
|
||||
Headers: map[string]string{
|
||||
|
@ -86,6 +90,7 @@ var testConfig = &config.Config{
|
|||
Endpoint: "https://storage.yandexcloud.net",
|
||||
Region: "ru-central1",
|
||||
Prefix: "prefix",
|
||||
CustomFields: map[string]string{"field": "value"},
|
||||
Channels: []config.S3{{}},
|
||||
},
|
||||
Kinesis: config.Kinesis{
|
||||
|
@ -96,6 +101,7 @@ var testConfig = &config.Config{
|
|||
MinimumPriority: "debug",
|
||||
Endpoint: "https://yds.serverless.yandexcloud.net",
|
||||
Region: "ru-central1",
|
||||
CustomFields: map[string]string{"field": "value"},
|
||||
Channels: []config.Kinesis{{}},
|
||||
},
|
||||
EmailReports: config.EmailReports{
|
||||
|
|
|
@ -366,12 +366,13 @@ func (f *TargetFactory) createElasticsearchClient(config Elasticsearch, parent E
|
|||
SkipExistingOnStartup: config.SkipExisting,
|
||||
Filter: createTargetFilter(config.Filter, config.MinimumPriority, config.Sources),
|
||||
},
|
||||
Host: config.Host,
|
||||
Username: config.Username,
|
||||
Password: config.Password,
|
||||
Rotation: config.Rotation,
|
||||
Index: config.Index,
|
||||
HTTPClient: http.NewClient(config.Certificate, config.SkipTLS),
|
||||
Host: config.Host,
|
||||
Username: config.Username,
|
||||
Password: config.Password,
|
||||
Rotation: config.Rotation,
|
||||
Index: config.Index,
|
||||
CustomFields: config.CustomFields,
|
||||
HTTPClient: http.NewClient(config.Certificate, config.SkipTLS),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -494,9 +495,10 @@ func (f *TargetFactory) createWebhookClient(config Webhook, parent Webhook) targ
|
|||
SkipExistingOnStartup: config.SkipExisting,
|
||||
Filter: createTargetFilter(config.Filter, config.MinimumPriority, config.Sources),
|
||||
},
|
||||
Host: config.Host,
|
||||
Headers: config.Headers,
|
||||
HTTPClient: http.NewClient(config.Certificate, config.SkipTLS),
|
||||
Host: config.Host,
|
||||
Headers: config.Headers,
|
||||
CustomFields: config.CustomFields,
|
||||
HTTPClient: http.NewClient(config.Certificate, config.SkipTLS),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -569,8 +571,9 @@ func (f *TargetFactory) createS3Client(config S3, parent S3) target.Client {
|
|||
SkipExistingOnStartup: config.SkipExisting,
|
||||
Filter: createTargetFilter(config.Filter, config.MinimumPriority, config.Sources),
|
||||
},
|
||||
S3: s3Client,
|
||||
Prefix: config.Prefix,
|
||||
S3: s3Client,
|
||||
CustomFields: config.CustomFields,
|
||||
Prefix: config.Prefix,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -637,7 +640,8 @@ func (f *TargetFactory) createKinesisClient(config Kinesis, parent Kinesis) targ
|
|||
SkipExistingOnStartup: config.SkipExisting,
|
||||
Filter: createTargetFilter(config.Filter, config.MinimumPriority, config.Sources),
|
||||
},
|
||||
Kinesis: kinesisClient,
|
||||
CustomFields: config.CustomFields,
|
||||
Kinesis: kinesisClient,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -286,4 +286,109 @@ func Test_GetValuesFromSecret(t *testing.T) {
|
|||
t.Error("Expected client are skipped")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Get CustomFields from Slack", func(t *testing.T) {
|
||||
clients := factory.SlackClients(config.Slack{CustomFields: map[string]string{"field": "value"}, Webhook: "http://localhost"})
|
||||
if len(clients) != 1 {
|
||||
t.Error("Expected one client created")
|
||||
}
|
||||
|
||||
client := reflect.ValueOf(clients[0]).Elem()
|
||||
|
||||
customFields := client.FieldByName("customFields").MapKeys()
|
||||
if customFields[0].String() != "field" {
|
||||
t.Errorf("Expected customFields are added")
|
||||
}
|
||||
})
|
||||
t.Run("Get CustomFields from Discord", func(t *testing.T) {
|
||||
clients := factory.DiscordClients(config.Discord{CustomFields: map[string]string{"field": "value"}, Webhook: "http://localhost"})
|
||||
if len(clients) != 1 {
|
||||
t.Error("Expected one client created")
|
||||
}
|
||||
|
||||
client := reflect.ValueOf(clients[0]).Elem()
|
||||
|
||||
customFields := client.FieldByName("customFields").MapKeys()
|
||||
if customFields[0].String() != "field" {
|
||||
t.Errorf("Expected customFields are added")
|
||||
}
|
||||
})
|
||||
t.Run("Get CustomFields from MS Teams", func(t *testing.T) {
|
||||
clients := factory.TeamsClients(config.Teams{CustomFields: map[string]string{"field": "value"}, Webhook: "http://localhost"})
|
||||
if len(clients) != 1 {
|
||||
t.Error("Expected one client created")
|
||||
}
|
||||
|
||||
client := reflect.ValueOf(clients[0]).Elem()
|
||||
|
||||
customFields := client.FieldByName("customFields").MapKeys()
|
||||
if customFields[0].String() != "field" {
|
||||
t.Errorf("Expected customFields are added")
|
||||
}
|
||||
})
|
||||
t.Run("Get CustomFields from Elasticsearch", func(t *testing.T) {
|
||||
clients := factory.ElasticsearchClients(config.Elasticsearch{CustomFields: map[string]string{"field": "value"}, Host: "http://localhost"})
|
||||
if len(clients) != 1 {
|
||||
t.Error("Expected one client created")
|
||||
}
|
||||
|
||||
client := reflect.ValueOf(clients[0]).Elem()
|
||||
|
||||
customFields := client.FieldByName("customFields").MapKeys()
|
||||
if customFields[0].String() != "field" {
|
||||
t.Errorf("Expected customFields are added")
|
||||
}
|
||||
})
|
||||
t.Run("Get CustomFields from Webhook", func(t *testing.T) {
|
||||
clients := factory.WebhookClients(config.Webhook{CustomFields: map[string]string{"field": "value"}, Host: "http://localhost"})
|
||||
if len(clients) != 1 {
|
||||
t.Error("Expected one client created")
|
||||
}
|
||||
|
||||
client := reflect.ValueOf(clients[0]).Elem()
|
||||
|
||||
customFields := client.FieldByName("customFields").MapKeys()
|
||||
if customFields[0].String() != "field" {
|
||||
t.Errorf("Expected customFields are added")
|
||||
}
|
||||
})
|
||||
t.Run("Get CustomFields from Kinesis", func(t *testing.T) {
|
||||
clients := factory.KinesisClients(testConfig.Kinesis)
|
||||
if len(clients) < 1 {
|
||||
t.Error("Expected one client created")
|
||||
}
|
||||
|
||||
client := reflect.ValueOf(clients[0]).Elem()
|
||||
|
||||
customFields := client.FieldByName("customFields").MapKeys()
|
||||
if customFields[0].String() != "field" {
|
||||
t.Errorf("Expected customFields are added")
|
||||
}
|
||||
})
|
||||
t.Run("Get CustomFields from S3", func(t *testing.T) {
|
||||
clients := factory.S3Clients(testConfig.S3)
|
||||
if len(clients) < 1 {
|
||||
t.Error("Expected one client created")
|
||||
}
|
||||
|
||||
client := reflect.ValueOf(clients[0]).Elem()
|
||||
|
||||
customFields := client.FieldByName("customFields").MapKeys()
|
||||
if customFields[0].String() != "field" {
|
||||
t.Errorf("Expected customFields are added")
|
||||
}
|
||||
})
|
||||
t.Run("Get CustomLabels from Loki", func(t *testing.T) {
|
||||
clients := factory.LokiClients(config.Loki{CustomLabels: map[string]string{"label": "value"}, Host: "http://localhost"})
|
||||
if len(clients) < 1 {
|
||||
t.Error("Expected one client created")
|
||||
}
|
||||
|
||||
client := reflect.ValueOf(clients[0]).Elem()
|
||||
|
||||
customFields := client.FieldByName("customLabels").MapKeys()
|
||||
if customFields[0].String() != "label" {
|
||||
t.Errorf("Expected customLabels are added")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue