Skip to content

Commit 92513c3

Browse files
committed
fix an issue where the resty clients weren't initialized correctly
1 parent 85f8f63 commit 92513c3

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-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: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ func (c *AzureDevopsClient) SupportsPatAuthentication() bool {
160160
}
161161

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

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

172173
func (c *AzureDevopsClient) restVsrm() *resty.Client {
173-
var client, err = c.restWithAuthentication("vsrm.dev.azure.com")
174+
175+
var client, err = c.restWithAuthentication(&c.restClientVsrm, "vsrm.dev.azure.com")
174176

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

182-
func (c *AzureDevopsClient) restWithAuthentication(domain string) (*resty.Client, error) {
183-
if c.restClient == nil {
184-
c.restClient = c.restWithoutToken(domain)
184+
func (c *AzureDevopsClient) restWithAuthentication(restClient **resty.Client, domain string) (*resty.Client, error) {
185+
186+
if *restClient == nil {
187+
*restClient = c.restWithoutToken(domain)
185188
}
186189

187190
if c.SupportsPatAuthentication() {
188-
c.restClient.SetBasicAuth("", *c.accessToken)
191+
(*restClient).SetBasicAuth("", *c.accessToken)
189192
} else {
190193
ctx := context.Background()
191194
opts := policy.TokenRequestOptions{
@@ -196,10 +199,10 @@ func (c *AzureDevopsClient) restWithAuthentication(domain string) (*resty.Client
196199
panic(err)
197200
}
198201

199-
c.restClient.SetBasicAuth("", accessToken.Token)
202+
(*restClient).SetBasicAuth("", accessToken.Token)
200203
}
201204

202-
return c.restClient, nil
205+
return (*restClient), nil
203206
}
204207

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

0 commit comments

Comments
 (0)