Skip to content

Commit

Permalink
return jira.BasicAuthTransport.Client if client certs/CAcert are not …
Browse files Browse the repository at this point in the history
…specified
  • Loading branch information
britcey committed Oct 15, 2020
1 parent 543004f commit c721010
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions cmd/jiralert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ func main() {
return
}

if conf.User != "" && conf.Password != "" {
//lint:ignore SA1019 SetBasicAuth is marked as deprecated but we can't use
// BasicAuthTransport with custom TLS settings, like client certs.
client.Authentication.SetBasicAuth(conf.User, string(conf.Password))
}

if retry, err := notify.NewReceiver(logger, conf, tmpl, client.Issue).Notify(&data); err != nil {
var status int
if retry {
Expand Down Expand Up @@ -191,7 +185,19 @@ func setupLogger(lvl string, fmt string) (logger log.Logger) {
return
}

// createHTTPClient returns a jira.BasicAuthTransport or http Client, depending
// on CAFile/client certificate options
func createHTTPClient(conf *config.ReceiverConfig) (*http.Client, error) {

// if CAFile, CertFile or KeyFile aren't specified, return BasicAuthTransport client
if len(conf.CAFile) == 0 && len(conf.CertFile) == 0 && len(conf.KeyFile) == 0 {
tp := jira.BasicAuthTransport{
Username: conf.User,
Password: string(conf.Password),
}
return tp.Client(), nil
}

tlsConfig, err := newTLSConfig(conf)
if err != nil {
return nil, err
Expand All @@ -204,7 +210,6 @@ func createHTTPClient(conf *config.ReceiverConfig) (*http.Client, error) {
}

return hc, nil

}

func newTLSConfig(conf *config.ReceiverConfig) (*tls.Config, error) {
Expand Down

0 comments on commit c721010

Please sign in to comment.