Skip to content

Commit

Permalink
Merge pull request #89 from moredatapls/fix-resty-client-reference
Browse files Browse the repository at this point in the history
Fix an issue where the resty clients weren't initialized correctly
  • Loading branch information
mblaschke authored Jun 1, 2024
2 parents 072254f + b08886a commit 4b44572
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
/release-assets
/azure-devops-exporter
*.exe

# VSCode
.vscode/
__debug_*
16 changes: 8 additions & 8 deletions azure-devops-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (c *AzureDevopsClient) SupportsPatAuthentication() bool {
}

func (c *AzureDevopsClient) rest() *resty.Client {
var client, err = c.restWithAuthentication("dev.azure.com")
var client, err = c.restWithAuthentication(c.restClient, "dev.azure.com")

if err != nil {
c.logger.Fatalf("could not create a rest client: %v", err)
Expand All @@ -170,7 +170,7 @@ func (c *AzureDevopsClient) rest() *resty.Client {
}

func (c *AzureDevopsClient) restVsrm() *resty.Client {
var client, err = c.restWithAuthentication("vsrm.dev.azure.com")
var client, err = c.restWithAuthentication(c.restClientVsrm, "vsrm.dev.azure.com")

if err != nil {
c.logger.Fatalf("could not create a rest client: %v", err)
Expand All @@ -179,13 +179,13 @@ func (c *AzureDevopsClient) restVsrm() *resty.Client {
return client
}

func (c *AzureDevopsClient) restWithAuthentication(domain string) (*resty.Client, error) {
if c.restClient == nil {
c.restClient = c.restWithoutToken(domain)
func (c *AzureDevopsClient) restWithAuthentication(restClient *resty.Client, domain string) (*resty.Client, error) {
if restClient == nil {
restClient = c.restWithoutToken(domain)
}

if c.SupportsPatAuthentication() {
c.restClient.SetBasicAuth("", *c.accessToken)
restClient.SetBasicAuth("", *c.accessToken)
} else {
ctx := context.Background()
opts := policy.TokenRequestOptions{
Expand All @@ -196,10 +196,10 @@ func (c *AzureDevopsClient) restWithAuthentication(domain string) (*resty.Client
panic(err)
}

c.restClient.SetBasicAuth("", accessToken.Token)
restClient.SetBasicAuth("", accessToken.Token)
}

return c.restClient, nil
return restClient, nil
}

func (c *AzureDevopsClient) restWithoutToken(domain string) *resty.Client {
Expand Down

0 comments on commit 4b44572

Please sign in to comment.