Skip to content

Commit f7cfb23

Browse files
committed
refactoring azure client options
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
1 parent 203955d commit f7cfb23

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

config/opts.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ type (
3636
SummaryMaxAge *time.Duration `long:"stats.summary.maxage" env:"STATS_SUMMARY_MAX_AGE" description:"Stats Summary metrics max age (time.duration)"`
3737
}
3838

39+
// azure settings
40+
Azure struct {
41+
TenantId string `long:"azure.tenant-id" env:"AZURE_TENANT_ID" description:"Azure tenant ID for Service Principal authentication"`
42+
ClientId string `long:"azure.client-id" env:"AZURE_CLIENT_ID" description:"Client ID for Service Principal authentication"`
43+
ClientSecret string `long:"azure.client-secret" env:"AZURE_CLIENT_SECRET" description:"Client secret for Service Principal authentication" json:"-"`
44+
}
45+
3946
// azure settings
4047
AzureDevops struct {
4148
Url *string `long:"azuredevops.url" env:"AZURE_DEVOPS_URL" description:"Azure DevOps URL (empty if hosted by Microsoft)"`
4249
AccessToken string `long:"azuredevops.access-token" env:"AZURE_DEVOPS_ACCESS_TOKEN" description:"Azure DevOps access token" json:"-"`
4350
AccessTokenFile *string `long:"azuredevops.access-token-file" env:"AZURE_DEVOPS_ACCESS_TOKEN_FILE" description:"Azure DevOps access token (from file)"`
44-
TenantId string `long:"azuredevops.tenant-id" env:"AZURE_TENANT_ID" description:"Azure tenant ID for Service Principal authentication" json:"-"`
45-
ClientId string `long:"azuredevops.client-id" env:"AZURE_CLIENT_ID" description:"Client ID for Service Principal authentication" json:"-"`
46-
ClientSecret string `long:"azuredevops.client-secret" env:"AZURE_CLIENT_SECRET" description:"Client secret for Service Principal authentication" json:"-"`
4751
Organisation string `long:"azuredevops.organisation" env:"AZURE_DEVOPS_ORGANISATION" description:"Azure DevOps organization" required:"true"`
4852
ApiVersion string `long:"azuredevops.apiversion" env:"AZURE_DEVOPS_APIVERSION" description:"Azure DevOps API version" default:"5.1"`
4953

main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func initArgparser() {
8282
}
8383
}
8484

85-
if len(opts.AzureDevops.AccessToken) == 0 && (len(opts.AzureDevops.TenantId) == 0 || len(opts.AzureDevops.ClientId) == 0) {
85+
if len(opts.AzureDevops.AccessToken) == 0 && (len(opts.Azure.TenantId) == 0 || len(opts.Azure.ClientId) == 0) {
8686
logger.Fatalf("neither an Azure DevOps PAT token nor client credentials (tenant ID, client ID) for service principal authentication have been provided")
8787
}
8888

@@ -158,20 +158,21 @@ func initAzureDevOpsConnection() {
158158
logger.Infof("using concurrency: %v", opts.Request.ConcurrencyLimit)
159159
logger.Infof("using retries: %v", opts.Request.Retries)
160160

161-
if opts.AzureDevops.TenantId != "" {
162-
if err := os.Setenv("AZURE_TENANT_ID", opts.AzureDevops.TenantId); err != nil {
161+
// ensure AZURE env vars are populated for azidentity
162+
if opts.Azure.TenantId != "" {
163+
if err := os.Setenv("AZURE_TENANT_ID", opts.Azure.TenantId); err != nil {
163164
panic(err)
164165
}
165166
}
166167

167-
if opts.AzureDevops.ClientId != "" {
168-
if err := os.Setenv("AZURE_CLIENT_ID", opts.AzureDevops.ClientId); err != nil {
168+
if opts.Azure.ClientId != "" {
169+
if err := os.Setenv("AZURE_CLIENT_ID", opts.Azure.ClientId); err != nil {
169170
panic(err)
170171
}
171172
}
172173

173-
if opts.AzureDevops.ClientSecret != "" {
174-
if err := os.Setenv("AZURE_CLIENT_SECRET", opts.AzureDevops.ClientSecret); err != nil {
174+
if opts.Azure.ClientSecret != "" {
175+
if err := os.Setenv("AZURE_CLIENT_SECRET", opts.Azure.ClientSecret); err != nil {
175176
panic(err)
176177
}
177178
}

0 commit comments

Comments
 (0)