Skip to content

Commit

Permalink
add KeyVaultSecretNames.cs
Browse files Browse the repository at this point in the history
Related to: aliencube#300
  • Loading branch information
sikutisa committed Sep 11, 2024
1 parent 4ba8666 commit 02946bc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static IOpenAISettingsBuilder WithKeyVault(this IOpenAISettingsBuilder bu
var client = sp.GetService<SecretClient>()
?? throw new InvalidOperationException($"{nameof(SecretClient)} service is not registered.");

var value = client.GetSecret(settings.SecretNames["OpenAI"]!).Value.Value;
var value = client.GetSecret(settings.SecretNames[KeyVaultSecretNames.OpenAI]!).Value.Value;

var instances = JsonSerializer.Deserialize<List<OpenAIInstanceSettings>>(value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public static IServiceCollection AddKeyVaultService(this IServiceCollection serv
throw new InvalidOperationException($"{nameof(KeyVaultSettings.VaultUri)} is not defined.");
}
if (string.IsNullOrWhiteSpace(settings.SecretNames["OpenAI"]) == true)
if (string.IsNullOrWhiteSpace(settings.SecretNames[KeyVaultSecretNames.OpenAI]) == true)
{
throw new InvalidOperationException($"{nameof(KeyVaultSettings.SecretNames)}.OpenAI is not defined.");
throw new InvalidOperationException($"{nameof(KeyVaultSettings.SecretNames)}.{KeyVaultSecretNames.OpenAI} is not defined.");
}
var client = new SecretClient(new Uri(settings.VaultUri), new DefaultAzureCredential());
Expand Down Expand Up @@ -154,7 +154,7 @@ public static IServiceCollection AddTableStorageService(this IServiceCollection
var clientSecret = sp.GetService<SecretClient>()
?? throw new InvalidOperationException($"{nameof(SecretClient)} service is not registered.");
var storageKeyVault = clientSecret.GetSecret(settings.SecretNames["Storage"]!);
var storageKeyVault = clientSecret.GetSecret(settings.SecretNames[KeyVaultSecretNames.Storage]!);
var client = new TableServiceClient(storageKeyVault.Value.Value);
Expand Down
18 changes: 18 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/KeyVaultSecretNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace AzureOpenAIProxy.ApiApp;

/// <summary>
/// This represents the keyvault secret names in appsettings.json
/// </summary>
public static class KeyVaultSecretNames
{
/// <summary>
/// Keyvault secret name for OpenAI instance settings
/// </summary>
public const string OpenAI = "OpenAI";

/// <summary>
/// Keyvault secret name for table storage connection string
/// </summary>
public const string Storage = "Storage";

}

0 comments on commit 02946bc

Please sign in to comment.