Skip to content

Commit 4a88a05

Browse files
committed
Fix #579: Cloud/Authentication: PATAuthTransport was renamed to APITokenAuthTransport
1 parent 82afaac commit 4a88a05

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

cloud/auth_transport_personal_access_token.go renamed to cloud/auth_transport_api_token.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,39 @@ import (
55
"net/http"
66
)
77

8-
// PATAuthTransport is an http.RoundTripper that authenticates all requests
9-
// using the Personal Access Token specified.
10-
// See here for more info: https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html
11-
type PATAuthTransport struct {
12-
// Token is the key that was provided by Jira when creating the Personal Access Token.
8+
// APITokenAuthTransport is an http.RoundTripper that authenticates all requests
9+
// using a Personal API Token.
10+
//
11+
// Jira docs: https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/
12+
// Create a token: https://id.atlassian.com/manage-profile/security/api-tokens
13+
type APITokenAuthTransport struct {
14+
// Token is the API key.
1315
Token string
1416

1517
// Transport is the underlying HTTP transport to use when making requests.
1618
// It will default to http.DefaultTransport if nil.
1719
Transport http.RoundTripper
1820
}
1921

20-
// RoundTrip implements the RoundTripper interface. We just add the
21-
// basic auth and return the RoundTripper for this transport type.
22-
func (t *PATAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) {
22+
// RoundTrip implements the RoundTripper interface. We just add the
23+
// API token header and return the RoundTripper for this transport type.
24+
func (t *APITokenAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) {
2325
req2 := cloneRequest(req) // per RoundTripper contract
2426

2527
req2.Header.Set("Authorization", fmt.Sprintf("Bearer %s", t.Token))
2628
return t.transport().RoundTrip(req2)
2729
}
2830

2931
// Client returns an *http.Client that makes requests that are authenticated
30-
// using HTTP Basic Authentication. This is a nice little bit of sugar
32+
// using the API token. This is a nice little bit of sugar
3133
// so we can just get the client instead of creating the client in the calling code.
3234
// If it's necessary to send more information on client init, the calling code can
3335
// always skip this and set the transport itself.
34-
func (t *PATAuthTransport) Client() *http.Client {
36+
func (t *APITokenAuthTransport) Client() *http.Client {
3537
return &http.Client{Transport: t}
3638
}
3739

38-
func (t *PATAuthTransport) transport() http.RoundTripper {
40+
func (t *APITokenAuthTransport) transport() http.RoundTripper {
3941
if t.Transport != nil {
4042
return t.Transport
4143
}

cloud/auth_transport_personal_access_token_test.go renamed to cloud/auth_transport_api_token_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66
"testing"
77
)
88

9-
func TestPATAuthTransport_HeaderContainsAuth(t *testing.T) {
9+
func TestAPITokenAuthTransport_HeaderContainsAuth(t *testing.T) {
1010
setup()
1111
defer teardown()
1212

13-
token := "shhh, it's a token"
13+
token := "shhh, it's an API token"
1414

15-
patTransport := &PATAuthTransport{
15+
patTransport := &APITokenAuthTransport{
1616
Token: token,
1717
}
1818

@@ -26,5 +26,4 @@ func TestPATAuthTransport_HeaderContainsAuth(t *testing.T) {
2626

2727
client, _ := NewClient(testServer.URL, patTransport.Client())
2828
client.User.GetSelf(context.Background())
29-
3029
}

0 commit comments

Comments
 (0)