Skip to content

Commit 776349a

Browse files
committed
feat(#85): support SLL_CERT_FILE env property
1 parent 0ea0284 commit 776349a

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

internal/jira/jira.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func NewApi(apiUrl string, username string, token string, tokenType JiraTokenTyp
6666
return &httpApi{
6767
apiUrl: apiUrl,
6868
client: &http.Client{
69-
Transport: &authInterceptor{core: http.DefaultTransport, token: authToken, authType: authType},
69+
Transport: &authInterceptor{core: defaultHttpTransport, token: authToken, authType: authType},
7070
},
7171
restUrl: baseUrl,
7272
}, nil

internal/jira/transport.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package jira
2+
3+
import (
4+
"crypto/tls"
5+
"crypto/x509"
6+
"fmt"
7+
"github.com/mk-5/fjira/internal/app"
8+
"net"
9+
"net/http"
10+
"os"
11+
"time"
12+
)
13+
14+
var (
15+
defaultHttpTransport = createHttpTransport()
16+
)
17+
18+
func createHttpTransport() *http.Transport {
19+
t := &http.Transport{
20+
Proxy: http.ProxyFromEnvironment,
21+
DialContext: (&net.Dialer{
22+
Timeout: 30 * time.Second,
23+
KeepAlive: 30 * time.Second,
24+
}).DialContext,
25+
ForceAttemptHTTP2: true,
26+
MaxIdleConns: 100,
27+
IdleConnTimeout: 90 * time.Second,
28+
TLSHandshakeTimeout: 10 * time.Second,
29+
ExpectContinueTimeout: 1 * time.Second,
30+
}
31+
if f := os.Getenv("SSL_CERT_FILE"); f != "" {
32+
t.TLSClientConfig = &tls.Config{
33+
MinVersion: tls.VersionTLS12,
34+
}
35+
data, err := os.ReadFile(f)
36+
if err != nil {
37+
app.Error(fmt.Sprintf("Cannot read file for SSL_CERT_FILE. %s", err.Error()))
38+
app.GetApp().Quit()
39+
return t
40+
}
41+
rootCAs := systemCertPool()
42+
rootCAs.AppendCertsFromPEM(data)
43+
t.TLSClientConfig.RootCAs = rootCAs
44+
}
45+
return t
46+
}
47+
48+
func systemCertPool() *x509.CertPool {
49+
pool, err := x509.SystemCertPool()
50+
if err != nil {
51+
return x509.NewCertPool()
52+
}
53+
return pool
54+
}

0 commit comments

Comments
 (0)