Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Blaschke <[email protected]>
  • Loading branch information
mblaschke committed Mar 31, 2024
1 parent 4436d7c commit 11cb236
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 11 additions & 10 deletions azure-devops-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ func (c *AzureDevopsClient) SetAccessToken(token string) {
c.accessToken = &token
}

func (c *AzureDevopsClient) UseAzAuth() error {
opts := azidentity.DefaultAzureCredentialOptions{}
cred, err := azidentity.NewDefaultAzureCredential(&opts)
if err != nil {
return err
}

c.azcreds = cred
return nil
}

func (c *AzureDevopsClient) SupportsPatAuthentication() bool {
return c.accessToken != nil && len(*c.accessToken) > 0
}
Expand Down Expand Up @@ -181,16 +192,6 @@ func (c *AzureDevopsClient) restWithAuthentication(domain string) (*resty.Client
if c.SupportsPatAuthentication() {
c.restClient.SetBasicAuth("", *c.accessToken)
} else {
if c.azcreds == nil {
opts := azidentity.DefaultAzureCredentialOptions{}
cred, err := azidentity.NewDefaultAzureCredential(&opts)
if err != nil {
panic(err)
}

c.azcreds = cred
}

ctx := context.Background()
opts := policy.TokenRequestOptions{
Scopes: []string{AZURE_DEVOPS_SCOPE},
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ func initAzureDevOpsConnection() {
AzureDevopsClient.SetOrganization(opts.AzureDevops.Organisation)
if opts.AzureDevops.AccessToken != "" {
AzureDevopsClient.SetAccessToken(opts.AzureDevops.AccessToken)
} else {
if err := AzureDevopsClient.UseAzAuth(); err != nil {
logger.Fatalf(err.Error())
}
}
AzureDevopsClient.SetApiVersion(opts.AzureDevops.ApiVersion)
AzureDevopsClient.SetConcurrency(opts.Request.ConcurrencyLimit)
Expand Down

0 comments on commit 11cb236

Please sign in to comment.