File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed
src/AzureOpenAIProxy.ApiApp/Extensions Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change 1- using Azure . Data . Tables ;
1+ using Azure ;
2+ using Azure . Data . Tables ;
23using Azure . Identity ;
34using Azure . Security . KeyVault . Secrets ;
45
@@ -145,17 +146,22 @@ public static IServiceCollection AddTableStorageService(this IServiceCollection
145146 {
146147 services . AddSingleton < TableServiceClient > ( sp => {
147148 var configuration = sp . GetService < IConfiguration > ( )
148- ?? throw new InvalidOperationException ( $ "{ nameof ( IConfiguration ) } service is not registered .") ;
149-
150- var settings = configuration . GetSection ( AzureSettings . Name ) . GetSection ( StorageAccountSettings . Name ) . Get < StorageAccountSettings > ( )
149+ ?? throw new InvalidOperationException ( $ "{ nameof ( IConfiguration ) } service is not registerd .") ;
150+
151+ var settings = configuration . GetSection ( StorageAccountSettings . Name ) . Get < StorageAccountSettings > ( )
151152 ?? throw new InvalidOperationException ( $ "{ nameof ( StorageAccountSettings ) } could not be retrieved from the configuration.") ;
152153
153- if ( string . IsNullOrWhiteSpace ( settings . ConnectionString ) == true )
154+ if ( string . IsNullOrWhiteSpace ( settings . KeyVaultSecretName ) == true )
154155 {
155- throw new InvalidOperationException ( $ "{ nameof ( StorageAccountSettings . ConnectionString ) } is not defined.") ;
156+ throw new InvalidOperationException ( $ "{ nameof ( StorageAccountSettings . KeyVaultSecretName ) } is not defined.") ;
156157 }
157158
158- var client = new TableServiceClient ( settings . ConnectionString ) ;
159+ var clientSecret = sp . GetService < SecretClient > ( )
160+ ?? throw new InvalidOperationException ( $ "{ nameof ( SecretClient ) } service is not registered.") ;
161+
162+ var storageKeyVault = clientSecret . GetSecret ( settings . KeyVaultSecretName ) ;
163+
164+ var client = new TableServiceClient ( storageKeyVault . Value . Value ) ;
159165
160166 return client ;
161167 } ) ;
You can’t perform that action at this time.
0 commit comments