Skip to content

Commit 971fce2

Browse files
authored
Use clone of http.DefaultTransport (#449)
Instead of using the DefaultTransport directly clone it and make sure it is what we expect.
1 parent e3cccab commit 971fce2

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

.changeset/smooth-otters-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'grafana-github-datasource': patch
3+
---
4+
5+
Get default http transport from plugin-sdk-go

cspell.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"grafanabot",
2323
"groupby",
2424
"healthcheck",
25+
"httpclient",
2526
"HTMLURL",
2627
"instancemgmt",
2728
"jackspeak",

pkg/github/client/client.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import (
1111

1212
"github.com/bradleyfalzon/ghinstallation/v2"
1313
googlegithub "github.com/google/go-github/v53/github"
14-
"github.com/grafana/github-datasource/pkg/models"
1514
"github.com/grafana/grafana-plugin-sdk-go/backend"
15+
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
1616
"github.com/influxdata/tdigest"
1717
"github.com/shurcooL/githubv4"
1818
"golang.org/x/oauth2"
19+
20+
"github.com/grafana/github-datasource/pkg/models"
1921
)
2022

2123
// Client is a wrapper of GitHub clients that can access the GraphQL and rest API.
@@ -74,7 +76,11 @@ func createAppClient(settings models.Settings) (*Client, error) {
7476
return nil, backend.DownstreamError(errors.New("error parsing installation id"))
7577
}
7678

77-
itr, err := ghinstallation.New(http.DefaultTransport, appId, installationId, []byte(settings.PrivateKey))
79+
transport, err := httpclient.GetDefaultTransport()
80+
if err != nil {
81+
return nil, backend.DownstreamError(errors.New("error: http.DefaultTransport is not of type *http.Transport"))
82+
}
83+
itr, err := ghinstallation.New(transport, appId, installationId, []byte(settings.PrivateKey))
7884
if err != nil {
7985
return nil, backend.DownstreamError(errors.New("error creating token source"))
8086
}

0 commit comments

Comments
 (0)