Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue where the resty clients weren't initialized correctly #89

Merged
merged 2 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
moredatapls marked this conversation as resolved.
Show resolved Hide resolved
__debug_*
19 changes: 11 additions & 8 deletions azure-devops-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ 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 +171,8 @@ 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 +181,14 @@ 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) {
moredatapls marked this conversation as resolved.
Show resolved Hide resolved

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 +199,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
Loading