@@ -14,6 +14,7 @@ import (
14
14
15
15
"github.com/kyverno/policy-reporter/pkg/crd/api/targetconfig/v1alpha1"
16
16
"github.com/kyverno/policy-reporter/pkg/filters"
17
+ "github.com/kyverno/policy-reporter/pkg/helper"
17
18
"github.com/kyverno/policy-reporter/pkg/kubernetes/secrets"
18
19
"github.com/kyverno/policy-reporter/pkg/report"
19
20
"github.com/kyverno/policy-reporter/pkg/target"
@@ -99,38 +100,26 @@ func (f *TargetFactory) CreateClients(config *target.Targets) *target.Collection
99
100
}
100
101
101
102
func (f * TargetFactory ) CreateSingleClient (tc * v1alpha1.TargetConfig ) (* target.Target , error ) {
102
- var t * target.Target
103
-
104
103
if tc .Spec .S3 != nil {
105
- t = createClients (tc .Name , createConfig (tc , tc .Spec .S3 ), f .CreateS3Target )[0 ]
106
- return t , nil
104
+ return helper .First (createClients (tc .Name , createConfig (tc , tc .Spec .S3 ), f .CreateS3Target )), nil
107
105
} else if tc .Spec .Webhook != nil {
108
- t = createClients (tc .Name , createConfig (tc , tc .Spec .Webhook ), f .CreateWebhookTarget )[0 ]
109
- return t , nil
106
+ return helper .First (createClients (tc .Name , createConfig (tc , tc .Spec .Webhook ), f .CreateWebhookTarget )), nil
110
107
} else if tc .Spec .GCS != nil {
111
- t = createClients (tc .Name , createConfig (tc , tc .Spec .GCS ), f .CreateGCSTarget )[0 ]
112
- return t , nil
108
+ return helper .First (createClients (tc .Name , createConfig (tc , tc .Spec .GCS ), f .CreateGCSTarget )), nil
113
109
} else if tc .Spec .ElasticSearch != nil {
114
- t = createClients (tc .Name , createConfig (tc , tc .Spec .ElasticSearch ), f .CreateElasticsearchTarget )[0 ]
115
- return t , nil
110
+ return helper .First (createClients (tc .Name , createConfig (tc , tc .Spec .ElasticSearch ), f .CreateElasticsearchTarget )), nil
116
111
} else if tc .Spec .Telegram != nil {
117
- t = createClients (tc .Name , createConfig (tc , tc .Spec .Telegram ), f .CreateTelegramTarget )[0 ]
118
- return t , nil
112
+ return helper .First (createClients (tc .Name , createConfig (tc , tc .Spec .Telegram ), f .CreateTelegramTarget )), nil
119
113
} else if tc .Spec .Kinesis != nil {
120
- t = createClients (tc .Name , createConfig (tc , tc .Spec .Kinesis ), f .CreateKinesisTarget )[0 ]
121
- return t , nil
114
+ return helper .First (createClients (tc .Name , createConfig (tc , tc .Spec .Kinesis ), f .CreateKinesisTarget )), nil
122
115
} else if tc .Spec .SecurityHub != nil {
123
- t = createClients (tc .Name , createConfig (tc , tc .Spec .SecurityHub ), f .CreateSecurityHubTarget )[0 ]
124
- return t , nil
116
+ return helper .First (createClients (tc .Name , createConfig (tc , tc .Spec .SecurityHub ), f .CreateSecurityHubTarget )), nil
125
117
} else if tc .Spec .Loki != nil {
126
- t = createClients (tc .Name , createConfig (tc , tc .Spec .Loki ), f .CreateLokiTarget )[0 ]
127
- return t , nil
118
+ return helper .First (createClients (tc .Name , createConfig (tc , tc .Spec .Loki ), f .CreateLokiTarget )), nil
128
119
} else if tc .Spec .Slack != nil {
129
- t = createClients (tc .Name , createConfig (tc , tc .Spec .Slack ), f .CreateSlackTarget )[0 ]
130
- return t , nil
120
+ return helper .First (createClients (tc .Name , createConfig (tc , tc .Spec .Slack ), f .CreateSlackTarget )), nil
131
121
} else if tc .Spec .Teams != nil {
132
- t = createClients (tc .Name , createConfig (tc , tc .Spec .Teams ), f .CreateTeamsTarget )[0 ]
133
- return t , nil
122
+ return helper .First (createClients (tc .Name , createConfig (tc , tc .Spec .Teams ), f .CreateTeamsTarget )), nil
134
123
}
135
124
return nil , fmt .Errorf ("invalid target type passed" )
136
125
}
@@ -831,15 +820,15 @@ func (f *TargetFactory) mapSecretValues(config any, ref, mountedSecret string) {
831
820
}
832
821
833
822
case * v1alpha1.Config [v1alpha1.SlackOptions ]:
834
- if values .Host != "" {
823
+ if values .Webhook != "" {
835
824
c .Config .Webhook = values .Webhook
836
825
}
837
826
if values .Channel != "" {
838
827
c .Config .Channel = values .Channel
839
828
}
840
829
841
830
case * v1alpha1.Config [v1alpha1.WebhookOptions ]:
842
- if values .Host != "" {
831
+ if values .Webhook != "" {
843
832
c .Config .Webhook = values .Webhook
844
833
}
845
834
if values .Token != "" {
@@ -903,8 +892,8 @@ func (f *TargetFactory) mapSecretValues(config any, ref, mountedSecret string) {
903
892
if values .Token != "" {
904
893
c .Config .Token = values .Token
905
894
}
906
- if values .Host != "" {
907
- c .Config .Webhook = values .Host
895
+ if values .Webhook != "" {
896
+ c .Config .Webhook = values .Webhook
908
897
}
909
898
}
910
899
}
0 commit comments