Skip to content

Commit

Permalink
Merge pull request #226 from ctreminiom/feature/auth-interface-refactor
Browse files Browse the repository at this point in the history
✨ Added Bearer token support.
  • Loading branch information
ctreminiom authored Jul 25, 2023
2 parents b08439e + 873be88 commit 4b192bc
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions confluence/api_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/ctreminiom/go-atlassian/confluence/internal"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/ctreminiom/go-atlassian/service/common"
Expand Down Expand Up @@ -97,6 +98,10 @@ func (c *Client) NewFormRequest(ctx context.Context, method, apiEndpoint, conten
request.Header.Set("User-Agent", c.Auth.GetUserAgent())
}

if c.Auth.GetBearerToken() != "" {
request.Header.Add("Authorization", fmt.Sprintf("Bearer %v", c.Auth.GetBearerToken()))
}

return request, nil
}

Expand Down
5 changes: 5 additions & 0 deletions confluence/v2/api_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/ctreminiom/go-atlassian/confluence/internal"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/ctreminiom/go-atlassian/service/common"
Expand Down Expand Up @@ -77,6 +78,10 @@ func (c *Client) NewFormRequest(ctx context.Context, method, apiEndpoint, conten
request.Header.Set("User-Agent", c.Auth.GetUserAgent())
}

if c.Auth.GetBearerToken() != "" {
request.Header.Add("Authorization", fmt.Sprintf("Bearer %v", c.Auth.GetBearerToken()))
}

return request, nil
}

Expand Down
5 changes: 5 additions & 0 deletions jira/agile/api_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/ctreminiom/go-atlassian/jira/agile/internal"
model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/ctreminiom/go-atlassian/service/common"
Expand Down Expand Up @@ -94,6 +95,10 @@ func (c *Client) NewRequest(ctx context.Context, method, urlStr, type_ string, b
req.Header.Set("User-Agent", c.Auth.GetUserAgent())
}

if c.Auth.GetBearerToken() != "" {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %v", c.Auth.GetBearerToken()))
}

return req, nil
}

Expand Down
1 change: 1 addition & 0 deletions jira/agile/api_client_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ func TestClient_NewRequest(t *testing.T) {
authMocked := internal.NewAuthenticationService(nil)
authMocked.SetBasicAuth("mail", "token")
authMocked.SetUserAgent("firefox")
authMocked.SetBearerToken("token_sample")

siteAsURL, err := url.Parse("https://ctreminiom.atlassian.net")
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions jira/v2/api_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/ctreminiom/go-atlassian/jira/internal"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/ctreminiom/go-atlassian/service/common"
Expand Down Expand Up @@ -453,6 +454,10 @@ func (c *Client) NewRequest(ctx context.Context, method, urlStr, type_ string, b
req.Header.Set("User-Agent", c.Auth.GetUserAgent())
}

if c.Auth.GetBearerToken() != "" {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %v", c.Auth.GetBearerToken()))
}

return req, nil
}
func (c *Client) Call(request *http.Request, structure interface{}) (*models.ResponseScheme, error) {
Expand Down
1 change: 1 addition & 0 deletions jira/v2/api_client_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func TestClient_NewRequest(t *testing.T) {
authMocked := internal.NewAuthenticationService(nil)
authMocked.SetBasicAuth("mail", "token")
authMocked.SetUserAgent("firefox")
authMocked.SetBearerToken("token_sample")

siteAsURL, err := url.Parse("https://ctreminiom.atlassian.net")
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions jira/v3/api_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/ctreminiom/go-atlassian/jira/internal"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/ctreminiom/go-atlassian/service/common"
Expand Down Expand Up @@ -453,6 +454,10 @@ func (c *Client) NewRequest(ctx context.Context, method, urlStr, type_ string, b
req.Header.Set("User-Agent", c.Auth.GetUserAgent())
}

if c.Auth.GetBearerToken() != "" {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %v", c.Auth.GetBearerToken()))
}

return req, nil
}

Expand Down
1 change: 1 addition & 0 deletions jira/v3/api_client_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func TestClient_NewRequest(t *testing.T) {
authMocked := internal.NewAuthenticationService(nil)
authMocked.SetBasicAuth("mail", "token")
authMocked.SetUserAgent("firefox")
authMocked.SetBearerToken("token_sample")

siteAsURL, err := url.Parse("https://ctreminiom.atlassian.net")
if err != nil {
Expand Down

0 comments on commit 4b192bc

Please sign in to comment.