Skip to content

Commit 4b44572

Browse files
authored
Merge pull request #89 from moredatapls/fix-resty-client-reference
Fix an issue where the resty clients weren't initialized correctly
2 parents 072254f + b08886a commit 4b44572

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
/release-assets
33
/azure-devops-exporter
44
*.exe
5+
6+
# VSCode
7+
.vscode/
8+
__debug_*

azure-devops-client/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (c *AzureDevopsClient) SupportsPatAuthentication() bool {
160160
}
161161

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

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

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

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

182-
func (c *AzureDevopsClient) restWithAuthentication(domain string) (*resty.Client, error) {
183-
if c.restClient == nil {
184-
c.restClient = c.restWithoutToken(domain)
182+
func (c *AzureDevopsClient) restWithAuthentication(restClient *resty.Client, domain string) (*resty.Client, error) {
183+
if restClient == nil {
184+
restClient = c.restWithoutToken(domain)
185185
}
186186

187187
if c.SupportsPatAuthentication() {
188-
c.restClient.SetBasicAuth("", *c.accessToken)
188+
restClient.SetBasicAuth("", *c.accessToken)
189189
} else {
190190
ctx := context.Background()
191191
opts := policy.TokenRequestOptions{
@@ -196,10 +196,10 @@ func (c *AzureDevopsClient) restWithAuthentication(domain string) (*resty.Client
196196
panic(err)
197197
}
198198

199-
c.restClient.SetBasicAuth("", accessToken.Token)
199+
restClient.SetBasicAuth("", accessToken.Token)
200200
}
201201

202-
return c.restClient, nil
202+
return restClient, nil
203203
}
204204

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

0 commit comments

Comments
 (0)