[Admin] Table Storage Connection Setting#299
Conversation
Related to: aliencube#208, aliencube#213
Related to: aliencube#208, aliencube#213
it doesn't use when create TableStorageClient Related to: aliencube#208, aliencube#213
|
bicep 리뷰 코멘트 남겨뒀는데요, 커넥션 스트링을 키볼트에서 가져온다고 가정해 보시면 좋겠습니다: #292 (review) |
해당 리뷰 확인해서 키볼트에서 가져오는 방식으로 변경해보겠습니다. |
get azure storage connection string from key vault Related to: aliencube#300
refactor to use KeyVault Related to: aliencube#300
Related to: aliencube#300
Related to: aliencube#300
Related to: aliencube#300
Related to: aliencube#300
Related to: aliencube#300
Related to: aliencube#300
Related to: aliencube#300
This reverts commit ceaa16b.
c5744db to
71d979a
Compare
|
@justinyoo [Theory]
[InlineData("http://localhost", default(string))]
[InlineData("http://localhost", "")]
public void Given_NullOrEmpty_SecretName_When_Invoked_AddKeyVaultService_Then_It_Should_Throw_Exception(string vaultUri, string? secretName)
{
// Arrange
var services = new ServiceCollection();
var dict = new Dictionary<string, string>()
{
{ "Azure:KeyVault:VaultUri", vaultUri },
{ "Azure:KeyVault:SecretNames:OpenAI", secretName! },
};
#pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
var config = new ConfigurationBuilder().AddInMemoryCollection(dict).Build();
#pragma warning restore CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
services.AddSingleton<IConfiguration>(config);
services.AddKeyVaultService();
// Act
Action action = () => services.BuildServiceProvider().GetService<SecretClient>();
// Assert
action.Should().Throw<InvalidOperationException>();
}두 시나리오 중 첫번째 시나리오인 그래서 추측컨데, 현재 AddKeyVaultService 함수에서 설정값을 객체에 바인드할 때 값이 null이면 Dictionary 객체 바인드가 제대로 동작하지 않고 있는 것 같습니다. AddKeyVaultService 내부에서 중단점을 통해 변수들을 살펴보면, configuration에는 OpenAI 키가 들어있는데, settings의 SecretNames Count가 0으로 나옵니다.(기대값: 1) 로컬에서 테스트를 더 해본 결과, AddKeyVaultService에서 바인딩을 할 때 중첩된 딕셔너리를 명시적으로 지정하여 바인드하면 테스트가 통과하는 것을 확인했습니다. public static IServiceCollection AddKeyVaultService(this IServiceCollection services)
{
services.AddSingleton<SecretClient>(sp =>
{
var configuration = sp.GetService<IConfiguration>()
?? throw new InvalidOperationException($"{nameof(IConfiguration)} service is not registered.");
var settings = configuration.GetSection(AzureSettings.Name).GetSection(KeyVaultSettings.Name).Get<KeyVaultSettings>()
?? throw new InvalidOperationException($"{nameof(KeyVaultSettings)} could not be retrieved from the configuration.");
// Bind SecretNames Dictionary
var secretNamesSection = configuration.GetSection($"{AzureSettings.Name}:{KeyVaultSettings.Name}:SecretNames");
if (string.IsNullOrWhiteSpace(settings.VaultUri) == true)
{
throw new InvalidOperationException($"{nameof(KeyVaultSettings.VaultUri)} is not defined.");
}
if (string.IsNullOrWhiteSpace(secretNamesSection["OpenAI"]) == true)
{
throw new InvalidOperationException($"{nameof(KeyVaultSettings.SecretNames)}.OpenAI is not defined.");
}
var client = new SecretClient(new Uri(settings.VaultUri), new DefaultAzureCredential());
return client;
});
return services;
}KeyVaultSettings의 SecretNames를 다른 방식으로 구현하던가 아니면 바인드 방식을 바꾸던가 하는 조치가 필요해 보입니다. |
src/AzureOpenAIProxy.ApiApp/Extensions/ServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
src/AzureOpenAIProxy.ApiApp/Extensions/ServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
test/AzureOpenAIProxy.ApiApp.Tests/Extensions/ServiceCollectionExtensionsTests.cs
Show resolved
Hide resolved
If a null secretName is given, a KeyNotFoundException is thrown instead of an InvalidOperationException. Related to: aliencube#300
Related to: aliencube#300


Description
TableServiceClient클래스가 필요한 것으로 이해했습니다.Discussion
public TableServiceClient (string connectionString);생성자를 사용했는데, 다른 생성자를 사용하는 것이 적절한지에 대해 논의할 필요가 있을 것 같습니다.Reference
https://learn.microsoft.com/en-us/connectors/azuretables/#connect-to-azure-table-storage-connector-using-table-endpoint
https://learn.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string