FS'Wæhre
FS'Wæhre

Reputation: 366

Azure App Configuration: labelFilter : is it possible to 'prefer' a certain label without excluding other labels?

In Azure App Configuration you can store a key with multiple values, differentiated by labels.

When building the config it is possible to filter which keys to read from the store by using labelFilter="SomeLabel"

In my case i have 50 keys in the app store without any label (No Label), and 4 keys which has two values, one value for label SomeLabel and another value for (No Label).

I want to retrieve all 54 keys. For the 4 keys which have multiple values, i want the value with label SomeLabel.

If i use labelFilter="SomeLabel" i only get the 4 keys with the label, the 50 keys without any label are filtered out.

Is it possible to achieve my desired functionality?

 <configBuilders>
    <builders>
      <add name="SomeAzureAppConfigStore" labelFilter="SomeLabel" mode="Greedy" prefix="My.App:" stripPrefix="true" connectionString="${MyConnectionString}" useAzureKeyVault="true" type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxx" />
    </builders>
  </configBuilders>

Upvotes: 0

Views: 2447

Answers (2)

Mc1brew
Mc1brew

Reputation: 73

You can resolve this by defining multiple configbuilders. The first builder will get all keys (although documentation suggests it should only be keys without labels). The second builder will override any previous key/values with the environment specific key/value. Note that the order in the tag also matters for the order in which the override occurs.

<configBuilders>
    <builders>
        <add name="SomeAzureAppConfigStoreNoLabel"
            labelFilter=""
            mode="Greedy" prefix="My.App:" stripPrefix="true" connectionString="${MyConnectionString}" useAzureKeyVault="true" type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxx" />
        
    <add name="SomeAzureAppConfigStoreSomeLabel"
        labelFilter="SomeLabel"
        mode="Greedy" prefix="My.App:" stripPrefix="true" connectionString="${MyConnectionString}" useAzureKeyVault="true" type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxx" />
    </builders>
</configBuilders>

<appSettings configBuilders="SomeAzureAppConfigStoreNoLabel,SomeAzureAppConfigStoreSomeLabel">

Upvotes: 1

mrm9084
mrm9084

Reputation: 493

The solution to your problem is using multiple labels. If you set "%00" as one of your labels then it is considered an empty label. It will then load both sets of labels and depending on the order they are set in will result in your 4 other labels being used instead of the non labeled versions.

Upvotes: 0

Related Questions