Skip to content

Commit 11cb236

Browse files
committed
cleanup
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
1 parent 4436d7c commit 11cb236

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

azure-devops-client/main.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ func (c *AzureDevopsClient) SetAccessToken(token string) {
149149
c.accessToken = &token
150150
}
151151

152+
func (c *AzureDevopsClient) UseAzAuth() error {
153+
opts := azidentity.DefaultAzureCredentialOptions{}
154+
cred, err := azidentity.NewDefaultAzureCredential(&opts)
155+
if err != nil {
156+
return err
157+
}
158+
159+
c.azcreds = cred
160+
return nil
161+
}
162+
152163
func (c *AzureDevopsClient) SupportsPatAuthentication() bool {
153164
return c.accessToken != nil && len(*c.accessToken) > 0
154165
}
@@ -181,16 +192,6 @@ func (c *AzureDevopsClient) restWithAuthentication(domain string) (*resty.Client
181192
if c.SupportsPatAuthentication() {
182193
c.restClient.SetBasicAuth("", *c.accessToken)
183194
} else {
184-
if c.azcreds == nil {
185-
opts := azidentity.DefaultAzureCredentialOptions{}
186-
cred, err := azidentity.NewDefaultAzureCredential(&opts)
187-
if err != nil {
188-
panic(err)
189-
}
190-
191-
c.azcreds = cred
192-
}
193-
194195
ctx := context.Background()
195196
opts := policy.TokenRequestOptions{
196197
Scopes: []string{AZURE_DEVOPS_SCOPE},

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ func initAzureDevOpsConnection() {
179179
AzureDevopsClient.SetOrganization(opts.AzureDevops.Organisation)
180180
if opts.AzureDevops.AccessToken != "" {
181181
AzureDevopsClient.SetAccessToken(opts.AzureDevops.AccessToken)
182+
} else {
183+
if err := AzureDevopsClient.UseAzAuth(); err != nil {
184+
logger.Fatalf(err.Error())
185+
}
182186
}
183187
AzureDevopsClient.SetApiVersion(opts.AzureDevops.ApiVersion)
184188
AzureDevopsClient.SetConcurrency(opts.Request.ConcurrencyLimit)

0 commit comments

Comments
 (0)