@@ -274,7 +274,7 @@ func parseAzureEndpoint(endpoint *url.URL) (cfg azureStoreConfig, err error) {
274
274
return cfg , nil
275
275
}
276
276
277
- func (a * azureBackend ) getAzureServiceClient (endpoint * url.URL ) (client * service.Client , err error ) {
277
+ func (a * azureBackend ) getAzureStorageClient (endpoint * url.URL ) (client * service.Client , err error ) {
278
278
var cfg azureStoreConfig
279
279
280
280
if cfg , err = parseAzureEndpoint (endpoint ); err != nil {
@@ -286,16 +286,22 @@ func (a *azureBackend) getAzureServiceClient(endpoint *url.URL) (client *service
286
286
var accountKey = os .Getenv ("AZURE_ACCOUNT_KEY" )
287
287
288
288
a .mu .Lock ()
289
- client , ok := a .clients [accountName ]
289
+ client , ok := a .clients [accountName + cfg . storageAccountName ]
290
290
a .mu .Unlock ()
291
291
292
292
if ok {
293
293
log .WithFields (log.Fields {
294
294
"storageAccountName" : accountName ,
295
- }).Info ("Re-using cached azure:// service client" )
295
+ "containerName" : cfg .containerName ,
296
+ }).Info ("Re-using cached azure:// storage account client" )
296
297
return client , nil
297
298
}
298
299
300
+ log .WithFields (log.Fields {
301
+ "storageAccountName" : accountName ,
302
+ "containerName" : cfg .containerName ,
303
+ }).Info ("Building new azure:// storage account client" )
304
+
299
305
sharedKeyCred , err := service .NewSharedKeyCredential (accountName , accountKey )
300
306
if err != nil {
301
307
return nil , err
@@ -306,7 +312,7 @@ func (a *azureBackend) getAzureServiceClient(endpoint *url.URL) (client *service
306
312
}
307
313
308
314
a .mu .Lock ()
309
- a .clients [accountName ] = serviceClient
315
+ a .clients [accountName + cfg . storageAccountName ] = serviceClient
310
316
a .mu .Unlock ()
311
317
return serviceClient , nil
312
318
} else if endpoint .Scheme == "azure-ad" {
@@ -316,16 +322,24 @@ func (a *azureBackend) getAzureServiceClient(endpoint *url.URL) (client *service
316
322
var clientSecret = os .Getenv ("AZURE_CLIENT_SECRET" )
317
323
318
324
a .mu .Lock ()
319
- client , ok := a .clients [cfg .accountTenantID ]
325
+ client , ok := a .clients [cfg .accountTenantID + cfg . storageAccountName ]
320
326
a .mu .Unlock ()
321
327
322
328
if ok {
323
329
log .WithFields (log.Fields {
324
- "accountTenantId" : cfg .accountTenantID ,
325
- }).Info ("Re-using cached azure-ad:// service client" )
330
+ "accountTenantId" : cfg .accountTenantID ,
331
+ "storageAccountName" : cfg .storageAccountName ,
332
+ "containerName" : cfg .containerName ,
333
+ }).Info ("Re-using cached azure-ad:// storage account client" )
326
334
return client , nil
327
335
}
328
336
337
+ log .WithFields (log.Fields {
338
+ "accountTenantId" : cfg .accountTenantID ,
339
+ "storageAccountName" : cfg .storageAccountName ,
340
+ "containerName" : cfg .containerName ,
341
+ }).Info ("Building new azure-ad:// storage account client" )
342
+
329
343
identityCreds , err := azidentity .NewClientSecretCredential (
330
344
cfg .accountTenantID ,
331
345
clientId ,
@@ -345,7 +359,7 @@ func (a *azureBackend) getAzureServiceClient(endpoint *url.URL) (client *service
345
359
}
346
360
347
361
a .mu .Lock ()
348
- a .clients [cfg .accountTenantID ] = serviceClient
362
+ a .clients [cfg .accountTenantID + cfg . storageAccountName ] = serviceClient
349
363
a .mu .Unlock ()
350
364
351
365
return serviceClient , nil
@@ -455,12 +469,12 @@ func (a *azureBackend) getUserDelegationCredential(endpoint *url.URL) (*service.
455
469
Expiry : to .Ptr (expTime .UTC ().Format (sas .TimeFormat )),
456
470
}
457
471
458
- var serviceClient , err = a .getAzureServiceClient (endpoint )
472
+ var storageClient , err = a .getAzureStorageClient (endpoint )
459
473
if err != nil {
460
474
return nil , err
461
475
}
462
476
463
- cred , err := serviceClient .GetUserDelegationCredential (context .Background (), info , nil )
477
+ cred , err := storageClient .GetUserDelegationCredential (context .Background (), info , nil )
464
478
if err != nil {
465
479
return nil , err
466
480
}
0 commit comments