bagetter/BaGetter

Incorrect AzureTable name when using a custom AzureTable name

Closed this issue · 1 comments

Describe the bug

When using a custom Azure Table name, the table is created on startup but when connecting to the table in the TableSearchService the wrong table name is used.

To Reproduce

Steps to reproduce the behaviour:

  1. Using the latest version of BaGetter.
  2. Run the project with AzureTable setup.
  3. When setting the table name property use any value other than "Packages".
  4. An error occurs immediately on startup.

Expected behaviour

This error should not be thrown and the correct table should be connected to and checked for values.

Screenshots

N/a

Additional context

Registering the TableServiceClient correctly creates the table with the right name, as shown below (line 30):

app.Services.AddSingleton(provider =>
{
var options = provider.GetRequiredService<IOptions<AzureTableOptions>>().Value;
var tableServiceClient = new TableServiceClient(options.ConnectionString);
tableServiceClient.CreateTableIfNotExists(options.TableName);
return tableServiceClient;
});

When using the TableServiceClient in the TableSearchService class, a TableClient is created but the table name used is a const string set to "Packages". See line 15 being used at line 27:

private const string TableName = "Packages";
private readonly TableClient _table;
private readonly ISearchResponseBuilder _responseBuilder;
public TableSearchService(
TableServiceClient client,
ISearchResponseBuilder responseBuilder)
{
ArgumentNullException.ThrowIfNull(client, nameof(client));
ArgumentNullException.ThrowIfNull(responseBuilder, nameof(responseBuilder));
_table = client.GetTableClient(TableName);
_responseBuilder = responseBuilder;
}

Therefore when any name other than "Packages" is specified the TableSearchService fails with a 404 Not Found from Azure.

This is fixed with version 1.4.3.