@@ -31,7 +31,8 @@ bool overwrite
3131 ) ;
3232 }
3333
34- public class BlobService ( ILogger < BlobService > logger ) : IBlobService
34+ public class BlobService ( ILogger < BlobService > logger , IConfiguration configuration )
35+ : IBlobService
3536 {
3637 public async Task < byte [ ] ? > DownloadBlob (
3738 string blobName ,
@@ -114,12 +115,32 @@ public async Task UploadJsonToBlob(
114115
115116 private BlobContainerClient GetBlobContainerClient ( string containerName , string accountName )
116117 {
117- var credential = new DefaultAzureCredential ( ) ;
118+ var authType =
119+ configuration [ $ "BlobStorage:{ accountName } :AuthType"]
120+ ?? configuration [ "BlobStorage:DefaultAuthType" ]
121+ ?? throw new ConfigException (
122+ $ "BlobStorage:DefaultAuthType is required (no per-account AuthType found for '{ accountName } ')"
123+ ) ;
124+
125+ BlobServiceClient serviceClient ;
126+ if ( authType . Equals ( "ConnectionString" , StringComparison . OrdinalIgnoreCase ) )
127+ {
128+ var connectionString =
129+ configuration [ $ "BlobStorage:{ accountName } :ConnectionString"]
130+ ?? throw new ConfigException (
131+ $ "BlobStorage:{ accountName } :ConnectionString is required when AuthType is ConnectionString"
132+ ) ;
133+ serviceClient = new BlobServiceClient ( connectionString ) ;
134+ }
135+ else
136+ {
137+ var credential = new DefaultAzureCredential ( ) ;
138+ serviceClient = new BlobServiceClient (
139+ new Uri ( $ "https://{ accountName } .blob.core.windows.net") ,
140+ credential
141+ ) ;
142+ }
118143
119- var serviceClient = new BlobServiceClient (
120- new Uri ( $ "https://{ accountName } .blob.core.windows.net") ,
121- credential
122- ) ;
123144 var containerClient = serviceClient . GetBlobContainerClient (
124145 containerName . ToLower ( CultureInfo . CurrentCulture )
125146 ) ;
0 commit comments