@@ -5,37 +5,39 @@ import (
5
5
"net/http"
6
6
)
7
7
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.
13
15
Token string
14
16
15
17
// Transport is the underlying HTTP transport to use when making requests.
16
18
// It will default to http.DefaultTransport if nil.
17
19
Transport http.RoundTripper
18
20
}
19
21
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 ) {
23
25
req2 := cloneRequest (req ) // per RoundTripper contract
24
26
25
27
req2 .Header .Set ("Authorization" , fmt .Sprintf ("Bearer %s" , t .Token ))
26
28
return t .transport ().RoundTrip (req2 )
27
29
}
28
30
29
31
// 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
31
33
// so we can just get the client instead of creating the client in the calling code.
32
34
// If it's necessary to send more information on client init, the calling code can
33
35
// always skip this and set the transport itself.
34
- func (t * PATAuthTransport ) Client () * http.Client {
36
+ func (t * APITokenAuthTransport ) Client () * http.Client {
35
37
return & http.Client {Transport : t }
36
38
}
37
39
38
- func (t * PATAuthTransport ) transport () http.RoundTripper {
40
+ func (t * APITokenAuthTransport ) transport () http.RoundTripper {
39
41
if t .Transport != nil {
40
42
return t .Transport
41
43
}
0 commit comments