Skip to content

Commit cdf174c

Browse files
committed
refactor AddTableStorageService
Related to: #300
1 parent 1418525 commit cdf174c

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/AzureOpenAIProxy.ApiApp/Extensions/ServiceCollectionExtensions.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public static IServiceCollection AddKeyVaultService(this IServiceCollection serv
3737
throw new InvalidOperationException($"{nameof(KeyVaultSettings.VaultUri)} is not defined.");
3838
}
3939

40-
if (string.IsNullOrWhiteSpace(settings.SecretName) == true)
40+
if (string.IsNullOrWhiteSpace(settings.SecretNames["OpenAI"]) == true)
4141
{
42-
throw new InvalidOperationException($"{nameof(KeyVaultSettings.SecretName)} is not defined.");
42+
throw new InvalidOperationException($"{nameof(KeyVaultSettings.SecretNames)}.OpenAI is not defined.");
4343
}
4444

4545
var client = new SecretClient(new Uri(settings.VaultUri), new DefaultAzureCredential());
@@ -148,18 +148,13 @@ public static IServiceCollection AddTableStorageService(this IServiceCollection
148148
var configuration = sp.GetService<IConfiguration>()
149149
?? throw new InvalidOperationException($"{nameof(IConfiguration)} service is not registerd.");
150150

151-
var settings = configuration.GetSection(AzureSettings.Name).GetSection(StorageAccountSettings.Name).Get<StorageAccountSettings>()
152-
?? throw new InvalidOperationException($"{nameof(StorageAccountSettings)} could not be retrieved from the configuration.");
153-
154-
if (string.IsNullOrWhiteSpace(settings.KeyVaultSecretName) == true)
155-
{
156-
throw new InvalidOperationException($"{nameof(StorageAccountSettings.KeyVaultSecretName)} is not defined.");
157-
}
151+
var settings = configuration.GetSection(AzureSettings.Name).GetSection(KeyVaultSettings.Name).Get<KeyVaultSettings>()
152+
?? throw new InvalidOperationException($"{nameof(KeyVaultSettings)} could not be retrieved from the configuration.");
158153

159154
var clientSecret = sp.GetService<SecretClient>()
160155
?? throw new InvalidOperationException($"{nameof(SecretClient)} service is not registered.");
161156

162-
var storageKeyVault = clientSecret.GetSecret(settings.KeyVaultSecretName);
157+
var storageKeyVault = clientSecret.GetSecret(settings.SecretNames["Storage"]!);
163158

164159
var client = new TableServiceClient(storageKeyVault.Value.Value);
165160

0 commit comments

Comments
 (0)