Skip to content

Commit 7160064

Browse files
authored
Update Helm Chart (#1021)
* Update Helm Chart Signed-off-by: Frank Jogeleit <[email protected]> * add missing mapping Signed-off-by: Frank Jogeleit <[email protected]> * Update token auth Signed-off-by: Frank Jogeleit <[email protected]> --------- Signed-off-by: Frank Jogeleit <[email protected]>
1 parent 9e10204 commit 7160064

File tree

7 files changed

+57
-47
lines changed

7 files changed

+57
-47
lines changed

charts/policy-reporter/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ description: |
55
It creates Prometheus Metrics and can send rule validation events to different targets like Loki, Elasticsearch, Slack or Discord
66
77
type: application
8-
version: 3.2.1
9-
appVersion: 3.2.0
8+
version: 3.2.2
9+
appVersion: 3.2.1
1010

1111
icon: https://github.com/kyverno/kyverno/raw/main/img/logo.png
1212
home: https://kyverno.github.io/policy-reporter

charts/policy-reporter/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Policy Reporter watches for PolicyReport Resources.
44
It creates Prometheus Metrics and can send rule validation events to different targets like Loki, Elasticsearch, Slack or Discord
55

6-
![Version: 3.2.1](https://img.shields.io/badge/Version-3.2.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 3.2.0](https://img.shields.io/badge/AppVersion-3.2.0-informational?style=flat-square)
6+
![Version: 3.2.2](https://img.shields.io/badge/Version-3.2.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 3.2.1](https://img.shields.io/badge/AppVersion-3.2.1-informational?style=flat-square)
77

88
## Documentation
99

@@ -259,6 +259,8 @@ Open `http://localhost:8082/` in your browser.
259259
| target.jira.apiToken | string | `""` | JIRA API token (use password or apiToken, not both) |
260260
| target.jira.projectKey | string | `""` | JIRA project key |
261261
| target.jira.issueType | string | `""` | JIRA issue type (default: "Bug") |
262+
| target.jira.components | list | `[]` | JIRA component names list |
263+
| target.jira.summaryTemplate | string | `""` | JIRA summary go template, available values: result, customfield default: "{{ if result.ResourceString }}{{ result.ResourceString }}: {{ end }}Policy Violation: {{ result.Policy }}" |
262264
| target.jira.certificate | string | `""` | Server Certificate file path Can be added under extraVolumes |
263265
| target.jira.skipTLS | bool | `false` | Skip TLS verification |
264266
| target.jira.secretRef | string | `""` | Read configuration from an already existing Secret |

charts/policy-reporter/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,8 @@ target:
634634
projectKey: ""
635635
# -- JIRA issue type (default: "Bug")
636636
issueType: ""
637+
# -- JIRA component names list
638+
components: []
637639
# -- JIRA summary go template, available values: result, customfield
638640
# default: "{{ if result.ResourceString }}{{ result.ResourceString }}: {{ end }}Policy Violation: {{ result.Policy }}"
639641
summaryTemplate: ""

pkg/target/factory/factory.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -627,17 +627,18 @@ func (f *TargetFactory) CreateJiraTarget(config, parent *targetconfig.Config[v1a
627627
ResultFilter: f.createResultFilter(config.Filter, config.MinimumSeverity, config.Sources),
628628
ReportFilter: createReportFilter(config.Filter),
629629
},
630-
Host: config.Config.Host,
631-
Username: config.Config.Username,
632-
Password: config.Config.Password,
633-
APIToken: config.Config.APIToken,
634-
ProjectKey: config.Config.ProjectKey,
635-
IssueType: config.Config.IssueType,
636-
Components: config.Config.Components,
637-
SkipTLS: config.Config.SkipTLS,
638-
Certificate: config.Config.Certificate,
639-
CustomFields: config.CustomFields,
640-
HTTPClient: http.NewClient(config.Config.Certificate, config.Config.SkipTLS),
630+
Host: config.Config.Host,
631+
Username: config.Config.Username,
632+
Password: config.Config.Password,
633+
APIToken: config.Config.APIToken,
634+
ProjectKey: config.Config.ProjectKey,
635+
IssueType: config.Config.IssueType,
636+
Components: config.Config.Components,
637+
SummaryTemplate: config.Config.SummaryTemplate,
638+
SkipTLS: config.Config.SkipTLS,
639+
Certificate: config.Config.Certificate,
640+
CustomFields: config.CustomFields,
641+
HTTPClient: http.NewClient(config.Config.Certificate, config.Config.SkipTLS),
641642
})
642643
if err != nil {
643644
zap.S().Errorf("failed to create Jira client: %v", err)

pkg/target/http/utils.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ func ProcessHTTPResponse(target string, resp *http.Response, err error) {
4141
}
4242
}()
4343

44-
if err != nil {
45-
zap.L().Error(target+": PUSH FAILED", zap.Error(err))
44+
if err != nil && resp != nil {
45+
buf := new(bytes.Buffer)
46+
buf.ReadFrom(resp.Body)
47+
48+
zap.L().Error(target+": PUSH FAILED", zap.Error(err), zap.String("body", buf.String()), zap.Int("statusCode", resp.StatusCode))
49+
} else if err != nil {
50+
zap.L().Error(target+": PUSH FAILED", zap.Int("statusCode", resp.StatusCode))
4651
} else if resp.StatusCode >= 400 {
4752
buf := new(bytes.Buffer)
4853
buf.ReadFrom(resp.Body)

pkg/target/jira/jira.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,28 @@ const summaryTmplate = "{{ if .result.ResourceString }}{{ .result.ResourceString
2222
// Options to configure the JIRA target
2323
type Options struct {
2424
target.ClientOptions
25-
Host string
26-
Username string
27-
Password string
28-
APIToken string
29-
ProjectKey string
30-
IssueType string
31-
SummaryTmplate string
32-
SkipTLS bool
33-
Certificate string
34-
CustomFields map[string]string
35-
Components []string
36-
HTTPClient targethttp.Client
25+
Host string
26+
Username string
27+
Password string
28+
APIToken string
29+
ProjectKey string
30+
IssueType string
31+
SummaryTemplate string
32+
SkipTLS bool
33+
Certificate string
34+
CustomFields map[string]string
35+
Components []string
36+
HTTPClient targethttp.Client
3737
}
3838

3939
type client struct {
4040
target.BaseClient
41-
projectKey string
42-
issueType string
43-
summaryTmplate string
44-
customFields map[string]string
45-
compoenents []string
46-
jira *v2.Client
41+
projectKey string
42+
issueType string
43+
summaryTemplate string
44+
customFields map[string]string
45+
compoenents []string
46+
jira *v2.Client
4747
}
4848

4949
func (e *client) Send(result openreports.ResultAdapter) {
@@ -102,7 +102,7 @@ func (e *client) Send(result openreports.ResultAdapter) {
102102

103103
var summary bytes.Buffer
104104

105-
t, err := template.New("summary").Parse(e.summaryTmplate)
105+
t, err := template.New("summary").Parse(e.summaryTemplate)
106106
if err != nil {
107107
zap.L().Error("failed to parse summary template", zap.String("name", e.Name()), zap.Error(err), zap.Any("result", result))
108108
return
@@ -157,7 +157,7 @@ func NewClient(options Options) (target.Client, error) {
157157
}
158158

159159
if options.APIToken != "" {
160-
jira.Auth.SetBearerToken(options.APIToken)
160+
jira.Auth.SetBasicAuth(options.Username, options.APIToken)
161161
} else {
162162
jira.Auth.SetBasicAuth(options.Username, options.Password)
163163
}
@@ -166,7 +166,7 @@ func NewClient(options Options) (target.Client, error) {
166166
target.NewBaseClient(options.ClientOptions),
167167
options.ProjectKey,
168168
options.IssueType,
169-
helper.Defaults(options.SummaryTmplate, summaryTmplate),
169+
helper.Defaults(options.SummaryTemplate, summaryTmplate),
170170
options.CustomFields,
171171
options.Components,
172172
jira,

pkg/target/jira/jira_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func Test_JiraTarget(t *testing.T) {
4141

4242
// Verify basic auth
4343
token := req.Header.Get("Authorization")
44-
assert.Equal(t, "Bearer test-token", token)
44+
assert.Equal(t, "Basic dGVzdC11c2VyOnRlc3QtdG9rZW4=", token)
4545

4646
// Verify request body
4747
body, err := io.ReadAll(req.Body)
@@ -140,15 +140,15 @@ func Test_JiraTarget(t *testing.T) {
140140
ClientOptions: target.ClientOptions{
141141
Name: "Jira",
142142
},
143-
Host: "https://jira.example.com",
144-
Username: "test-user",
145-
Password: "test-password",
146-
ProjectKey: "TEST",
147-
IssueType: "Bug",
148-
HTTPClient: testClient{callback, 200},
149-
CustomFields: map[string]string{"cluster": "test"},
150-
Components: []string{"policy-reporter"},
151-
SummaryTmplate: "{{ customfield.cluster }}: Policy Violation: {{ result.Policy }}",
143+
Host: "https://jira.example.com",
144+
Username: "test-user",
145+
Password: "test-password",
146+
ProjectKey: "TEST",
147+
IssueType: "Bug",
148+
HTTPClient: testClient{callback, 200},
149+
CustomFields: map[string]string{"cluster": "test"},
150+
Components: []string{"policy-reporter"},
151+
SummaryTemplate: "{{ customfield.cluster }}: Policy Violation: {{ result.Policy }}",
152152
})
153153
if assert.NoError(t, err) {
154154
client.Send(fixtures.CompleteTargetSendResult)

0 commit comments

Comments
 (0)