Skip to content

Commit 22ebd3c

Browse files
committed
restructure into tpOptions
Signed-off-by: Afzal Ansari <[email protected]>
1 parent 5b32611 commit 22ebd3c

File tree

12 files changed

+162
-115
lines changed

12 files changed

+162
-115
lines changed

pkg/services/alertmanager.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,14 @@ type AlertmanagerNotification struct {
3333

3434
// AlertmanagerOptions cluster configuration
3535
type AlertmanagerOptions struct {
36-
Targets []string `json:"targets"`
37-
Scheme string `json:"scheme"`
38-
APIPath string `json:"apiPath"`
39-
BasicAuth *BasicAuth `json:"basicAuth"`
40-
BearerToken string `json:"bearerToken"`
41-
Timeout int `json:"timeout"`
42-
InsecureSkipVerify bool `json:"insecureSkipVerify"`
43-
MaxIdleConns int `json:"maxIdleConns"`
44-
MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost"`
45-
MaxConnsPerHost int `json:"maxConnsPerHost"`
46-
IdleConnTimeout string `json:"idleConnTimeout"`
36+
Targets []string `json:"targets"`
37+
Scheme string `json:"scheme"`
38+
APIPath string `json:"apiPath"`
39+
BasicAuth *BasicAuth `json:"basicAuth"`
40+
BearerToken string `json:"bearerToken"`
41+
Timeout int `json:"timeout"`
42+
InsecureSkipVerify bool `json:"insecureSkipVerify"`
43+
httputil.TransportOptions
4744
}
4845

4946
// NewAlertmanagerService new service
@@ -211,7 +208,13 @@ func (s alertmanagerService) Send(notification Notification, dest Destination) e
211208
func (s alertmanagerService) sendOneTarget(ctx context.Context, target string, rawBody []byte) (err error) {
212209
rawURL := fmt.Sprintf("%v://%v%v", s.opts.Scheme, target, s.opts.APIPath)
213210

214-
client, err := httputil.NewServiceHTTPClient(s.opts.MaxIdleConns, s.opts.MaxIdleConnsPerHost, s.opts.MaxConnsPerHost, s.opts.IdleConnTimeout, s.opts.InsecureSkipVerify, rawURL, "alertmanager")
211+
tp := httputil.TransportOptions{
212+
MaxIdleConns: s.opts.MaxIdleConns,
213+
MaxIdleConnsPerHost: s.opts.MaxIdleConnsPerHost,
214+
MaxConnsPerHost: s.opts.MaxConnsPerHost,
215+
IdleConnTimeout: s.opts.IdleConnTimeout,
216+
}
217+
client, err := httputil.NewServiceHTTPClient(tp, s.opts.InsecureSkipVerify, rawURL, "alertmanager")
215218
if err != nil {
216219
return err
217220
}

pkg/services/github.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ var (
2525
)
2626

2727
type GitHubOptions struct {
28-
AppID interface{} `json:"appID"`
29-
InstallationID interface{} `json:"installationID"`
30-
PrivateKey string `json:"privateKey"`
31-
EnterpriseBaseURL string `json:"enterpriseBaseURL"`
32-
InsecureSkipVerify bool `json:"insecureSkipVerify"`
33-
MaxIdleConns int `json:"maxIdleConns"`
34-
MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost"`
35-
MaxConnsPerHost int `json:"maxConnsPerHost"`
36-
IdleConnTimeout string `json:"idleConnTimeout"`
28+
AppID interface{} `json:"appID"`
29+
InstallationID interface{} `json:"installationID"`
30+
PrivateKey string `json:"privateKey"`
31+
EnterpriseBaseURL string `json:"enterpriseBaseURL"`
32+
InsecureSkipVerify bool `json:"insecureSkipVerify"`
33+
httputil.TransportOptions
3734
}
3835

3936
type GitHubNotification struct {
@@ -399,7 +396,14 @@ func NewGitHubService(opts GitHubOptions) (*gitHubService, error) {
399396
return nil, err
400397
}
401398

402-
client, err := httputil.NewServiceHTTPClient(opts.MaxIdleConns, opts.MaxIdleConnsPerHost, opts.MaxConnsPerHost, opts.IdleConnTimeout, opts.InsecureSkipVerify, url, "github")
399+
tp := httputil.TransportOptions{
400+
MaxIdleConns: opts.MaxIdleConns,
401+
MaxIdleConnsPerHost: opts.MaxIdleConnsPerHost,
402+
MaxConnsPerHost: opts.MaxConnsPerHost,
403+
IdleConnTimeout: opts.IdleConnTimeout,
404+
}
405+
406+
client, err := httputil.NewServiceHTTPClient(tp, opts.InsecureSkipVerify, url, "github")
403407
if err != nil {
404408
return nil, err
405409
}

pkg/services/googlechat.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,9 @@ func (n *GoogleChatNotification) GetTemplater(name string, f texttemplate.FuncMa
7979
}
8080

8181
type GoogleChatOptions struct {
82-
WebhookUrls map[string]string `json:"webhooks"`
83-
InsecureSkipVerify bool `json:"insecureSkipVerify"`
84-
MaxIdleConns int `json:"maxIdleConns"`
85-
MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost"`
86-
MaxConnsPerHost int `json:"maxConnsPerHost"`
87-
IdleConnTimeout string `json:"idleConnTimeout"`
82+
WebhookUrls map[string]string `json:"webhooks"`
83+
InsecureSkipVerify bool `json:"insecureSkipVerify"`
84+
httputil.TransportOptions
8885
}
8986

9087
type googleChatService struct {
@@ -111,7 +108,13 @@ func (s googleChatService) getClient(recipient string) (googlechatclient *google
111108
return nil, fmt.Errorf("no Google chat webhook configured for recipient %s", recipient)
112109
}
113110

114-
client, err := httputil.NewServiceHTTPClient(s.opts.MaxIdleConns, s.opts.MaxIdleConnsPerHost, s.opts.MaxConnsPerHost, s.opts.IdleConnTimeout, s.opts.InsecureSkipVerify, webhookUrl, "googlechat")
111+
tp := httputil.TransportOptions{
112+
MaxIdleConns: s.opts.MaxIdleConns,
113+
MaxIdleConnsPerHost: s.opts.MaxIdleConnsPerHost,
114+
MaxConnsPerHost: s.opts.MaxConnsPerHost,
115+
IdleConnTimeout: s.opts.IdleConnTimeout,
116+
}
117+
client, err := httputil.NewServiceHTTPClient(tp, s.opts.InsecureSkipVerify, webhookUrl, "googlechat")
115118
if err != nil {
116119
return nil, err
117120
}

pkg/services/grafana.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ import (
1717
)
1818

1919
type GrafanaOptions struct {
20-
ApiUrl string `json:"apiUrl"`
21-
ApiKey string `json:"apiKey"`
22-
InsecureSkipVerify bool `json:"insecureSkipVerify"`
23-
MaxIdleConns int `json:"maxIdleConns"`
24-
MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost"`
25-
MaxConnsPerHost int `json:"maxConnsPerHost"`
26-
IdleConnTimeout string `json:"idleConnTimeout"`
20+
ApiUrl string `json:"apiUrl"`
21+
ApiKey string `json:"apiKey"`
22+
InsecureSkipVerify bool `json:"insecureSkipVerify"`
23+
httputil.TransportOptions
2724
}
2825

2926
type grafanaService struct {
@@ -53,7 +50,13 @@ func (s *grafanaService) Send(notification Notification, dest Destination) (err
5350
log.Warnf("Message is an empty string or not provided in the notifications template")
5451
}
5552

56-
client, err := httputil.NewServiceHTTPClient(s.opts.MaxIdleConns, s.opts.MaxIdleConnsPerHost, s.opts.MaxConnsPerHost, s.opts.IdleConnTimeout, s.opts.InsecureSkipVerify, s.opts.ApiUrl, "grafana")
53+
tp := httputil.TransportOptions{
54+
MaxIdleConns: s.opts.MaxIdleConns,
55+
MaxIdleConnsPerHost: s.opts.MaxIdleConnsPerHost,
56+
MaxConnsPerHost: s.opts.MaxConnsPerHost,
57+
IdleConnTimeout: s.opts.IdleConnTimeout,
58+
}
59+
client, err := httputil.NewServiceHTTPClient(tp, s.opts.InsecureSkipVerify, s.opts.ApiUrl, "grafana")
5760
if err != nil {
5861
return err
5962
}

pkg/services/mattermost.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,10 @@ func (n *MattermostNotification) GetTemplater(name string, f texttemplate.FuncMa
3535
}
3636

3737
type MattermostOptions struct {
38-
ApiURL string `json:"apiURL"`
39-
Token string `json:"token"`
40-
InsecureSkipVerify bool `json:"insecureSkipVerify"`
41-
MaxIdleConns int `json:"maxIdleConns"`
42-
MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost"`
43-
MaxConnsPerHost int `json:"maxConnsPerHost"`
44-
IdleConnTimeout string `json:"idleConnTimeout"`
38+
ApiURL string `json:"apiURL"`
39+
Token string `json:"token"`
40+
InsecureSkipVerify bool `json:"insecureSkipVerify"`
41+
httputil.TransportOptions
4542
}
4643

4744
type mattermostService struct {
@@ -53,7 +50,13 @@ func NewMattermostService(opts MattermostOptions) NotificationService {
5350
}
5451

5552
func (m *mattermostService) Send(notification Notification, dest Destination) (err error) {
56-
client, err := httputil.NewServiceHTTPClient(m.opts.MaxIdleConns, m.opts.MaxIdleConnsPerHost, m.opts.MaxConnsPerHost, m.opts.IdleConnTimeout, m.opts.InsecureSkipVerify, m.opts.ApiURL, "mattermost")
53+
tp := httputil.TransportOptions{
54+
MaxIdleConns: m.opts.MaxIdleConns,
55+
MaxIdleConnsPerHost: m.opts.MaxIdleConnsPerHost,
56+
MaxConnsPerHost: m.opts.MaxConnsPerHost,
57+
IdleConnTimeout: m.opts.IdleConnTimeout,
58+
}
59+
client, err := httputil.NewServiceHTTPClient(tp, m.opts.InsecureSkipVerify, m.opts.ApiURL, "mattermost")
5760
if err != nil {
5861
return err
5962
}

pkg/services/newrelic.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ import (
1515
)
1616

1717
type NewrelicOptions struct {
18-
ApiKey string `json:"apiKey"`
19-
ApiURL string `json:"apiURL"`
20-
InsecureSkipVerify bool `json:"insecureSkipVerify"`
21-
MaxIdleConns int `json:"maxIdleConns"`
22-
MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost"`
23-
MaxConnsPerHost int `json:"maxConnsPerHost"`
24-
IdleConnTimeout string `json:"idleConnTimeout"`
18+
ApiKey string `json:"apiKey"`
19+
ApiURL string `json:"apiURL"`
20+
InsecureSkipVerify bool `json:"insecureSkipVerify"`
21+
httputil.TransportOptions
2522
}
2623

2724
type NewrelicNotification struct {
@@ -137,7 +134,13 @@ func (s newrelicService) Send(notification Notification, dest Destination) (err
137134
},
138135
}
139136

140-
client, err := httputil.NewServiceHTTPClient(s.opts.MaxIdleConns, s.opts.MaxIdleConnsPerHost, s.opts.MaxConnsPerHost, s.opts.IdleConnTimeout, s.opts.InsecureSkipVerify, s.opts.ApiURL, "newrelic")
137+
tp := httputil.TransportOptions{
138+
MaxIdleConns: s.opts.MaxIdleConns,
139+
MaxIdleConnsPerHost: s.opts.MaxIdleConnsPerHost,
140+
MaxConnsPerHost: s.opts.MaxConnsPerHost,
141+
IdleConnTimeout: s.opts.IdleConnTimeout,
142+
}
143+
client, err := httputil.NewServiceHTTPClient(tp, s.opts.InsecureSkipVerify, s.opts.ApiURL, "newrelic")
141144
if err != nil {
142145
return err
143146
}

pkg/services/opsgenie.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ import (
1313
)
1414

1515
type OpsgenieOptions struct {
16-
ApiUrl string `json:"apiUrl"`
17-
ApiKeys map[string]string `json:"apiKeys"`
18-
InsecureSkipVerify bool `json:"insecureSkipVerify"`
19-
MaxIdleConns int `json:"maxIdleConns"`
20-
MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost"`
21-
MaxConnsPerHost int `json:"maxConnsPerHost"`
22-
IdleConnTimeout string `json:"idleConnTimeout"`
16+
ApiUrl string `json:"apiUrl"`
17+
ApiKeys map[string]string `json:"apiKeys"`
18+
InsecureSkipVerify bool `json:"insecureSkipVerify"`
19+
httputil.TransportOptions
2320
}
2421

2522
type OpsgenieNotification struct {
@@ -252,7 +249,14 @@ func (s *opsgenieService) Send(notification Notification, dest Destination) (err
252249
if !ok {
253250
return fmt.Errorf("no API key configured for recipient %s", dest.Recipient)
254251
}
255-
opsclient, err := httputil.NewServiceHTTPClient(s.opts.MaxIdleConns, s.opts.MaxIdleConnsPerHost, s.opts.MaxConnsPerHost, s.opts.IdleConnTimeout, s.opts.InsecureSkipVerify, s.opts.ApiUrl, "opsgenie")
252+
253+
tp := httputil.TransportOptions{
254+
MaxIdleConns: s.opts.MaxIdleConns,
255+
MaxIdleConnsPerHost: s.opts.MaxIdleConnsPerHost,
256+
MaxConnsPerHost: s.opts.MaxConnsPerHost,
257+
IdleConnTimeout: s.opts.IdleConnTimeout,
258+
}
259+
opsclient, err := httputil.NewServiceHTTPClient(tp, s.opts.InsecureSkipVerify, s.opts.ApiUrl, "opsgenie")
256260
if err != nil {
257261
return err
258262
}

pkg/services/slack.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,15 @@ func (n *SlackNotification) GetTemplater(name string, f texttemplate.FuncMap) (T
9595
}
9696

9797
type SlackOptions struct {
98-
Username string `json:"username"`
99-
Icon string `json:"icon"`
100-
Token string `json:"token"`
101-
SigningSecret string `json:"signingSecret"`
102-
Channels []string `json:"channels"`
103-
ApiURL string `json:"apiURL"`
104-
DisableUnfurl bool `json:"disableUnfurl"`
105-
InsecureSkipVerify bool `json:"insecureSkipVerify"`
106-
MaxIdleConns int `json:"maxIdleConns"`
107-
MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost"`
108-
MaxConnsPerHost int `json:"maxConnsPerHost"`
109-
IdleConnTimeout string `json:"idleConnTimeout"`
98+
Username string `json:"username"`
99+
Icon string `json:"icon"`
100+
Token string `json:"token"`
101+
SigningSecret string `json:"signingSecret"`
102+
Channels []string `json:"channels"`
103+
ApiURL string `json:"apiURL"`
104+
DisableUnfurl bool `json:"disableUnfurl"`
105+
InsecureSkipVerify bool `json:"insecureSkipVerify"`
106+
httputil.TransportOptions
110107
}
111108

112109
type slackService struct {
@@ -204,7 +201,14 @@ func newSlackClient(opts SlackOptions) (slackclient *slack.Client, err error) {
204201
if opts.ApiURL != "" {
205202
apiURL = opts.ApiURL
206203
}
207-
client, err := httputil.NewServiceHTTPClient(opts.MaxIdleConns, opts.MaxIdleConnsPerHost, opts.MaxConnsPerHost, opts.IdleConnTimeout, opts.InsecureSkipVerify, apiURL, "slack")
204+
205+
tp := httputil.TransportOptions{
206+
MaxIdleConns: opts.MaxIdleConns,
207+
MaxIdleConnsPerHost: opts.MaxIdleConnsPerHost,
208+
MaxConnsPerHost: opts.MaxConnsPerHost,
209+
IdleConnTimeout: opts.IdleConnTimeout,
210+
}
211+
client, err := httputil.NewServiceHTTPClient(tp, opts.InsecureSkipVerify, apiURL, "slack")
208212
if err != nil {
209213
return nil, err
210214
}

pkg/services/teams.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,9 @@ func (n *TeamsNotification) GetTemplater(name string, f texttemplate.FuncMap) (T
136136
}
137137

138138
type TeamsOptions struct {
139-
RecipientUrls map[string]string `json:"recipientUrls"`
140-
InsecureSkipVerify bool `json:"insecureSkipVerify"`
141-
MaxIdleConns int `json:"maxIdleConns"`
142-
MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost"`
143-
MaxConnsPerHost int `json:"maxConnsPerHost"`
144-
IdleConnTimeout string `json:"idleConnTimeout"`
139+
RecipientUrls map[string]string `json:"recipientUrls"`
140+
InsecureSkipVerify bool `json:"insecureSkipVerify"`
141+
httputil.TransportOptions
145142
}
146143

147144
type teamsService struct {
@@ -157,7 +154,14 @@ func (s teamsService) Send(notification Notification, dest Destination) (err err
157154
if !ok {
158155
return fmt.Errorf("no teams webhook configured for recipient %s", dest.Recipient)
159156
}
160-
client, err := httputil.NewServiceHTTPClient(s.opts.MaxIdleConns, s.opts.MaxIdleConnsPerHost, s.opts.MaxConnsPerHost, s.opts.IdleConnTimeout, s.opts.InsecureSkipVerify, webhookUrl, "teams")
157+
158+
tp := httputil.TransportOptions{
159+
MaxIdleConns: s.opts.MaxIdleConns,
160+
MaxIdleConnsPerHost: s.opts.MaxIdleConnsPerHost,
161+
MaxConnsPerHost: s.opts.MaxConnsPerHost,
162+
IdleConnTimeout: s.opts.IdleConnTimeout,
163+
}
164+
client, err := httputil.NewServiceHTTPClient(tp, s.opts.InsecureSkipVerify, webhookUrl, "teams")
161165
if err != nil {
162166
return err
163167
}

pkg/services/webex.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ import (
1313
)
1414

1515
type WebexOptions struct {
16-
Token string `json:"token"`
17-
ApiURL string `json:"apiURL"`
18-
InsecureSkipVerify bool `json:"insecureSkipVerify"`
19-
MaxIdleConns int `json:"maxIdleConns"`
20-
MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost"`
21-
MaxConnsPerHost int `json:"maxConnsPerHost"`
22-
IdleConnTimeout string `json:"idleConnTimeout"`
16+
Token string `json:"token"`
17+
ApiURL string `json:"apiURL"`
18+
InsecureSkipVerify bool `json:"insecureSkipVerify"`
19+
httputil.TransportOptions
2320
}
2421

2522
type webexService struct {
@@ -46,7 +43,13 @@ var validEmail = regexp.MustCompile(`^\S+@\S+\.\S+$`)
4643
func (w webexService) Send(notification Notification, dest Destination) (err error) {
4744
requestURL := fmt.Sprintf("%s/v1/messages", w.opts.ApiURL)
4845

49-
client, err := httputil.NewServiceHTTPClient(w.opts.MaxIdleConns, w.opts.MaxIdleConnsPerHost, w.opts.MaxConnsPerHost, w.opts.IdleConnTimeout, w.opts.InsecureSkipVerify, requestURL, "webex")
46+
tp := httputil.TransportOptions{
47+
MaxIdleConns: w.opts.MaxIdleConns,
48+
MaxIdleConnsPerHost: w.opts.MaxIdleConnsPerHost,
49+
MaxConnsPerHost: w.opts.MaxConnsPerHost,
50+
IdleConnTimeout: w.opts.IdleConnTimeout,
51+
}
52+
client, err := httputil.NewServiceHTTPClient(tp, w.opts.InsecureSkipVerify, requestURL, "webex")
5053
if err != nil {
5154
return err
5255
}

0 commit comments

Comments
 (0)