Skip to content

Commit

Permalink
Exclude feature flags from loaded settings (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eskibear authored Apr 10, 2024
1 parent 6844f7e commit e8a5c7c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/AzureAppConfigurationImpl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { AppConfigurationClient, ConfigurationSetting, ConfigurationSettingId, GetConfigurationSettingOptions, GetConfigurationSettingResponse, ListConfigurationSettingsOptions } from "@azure/app-configuration";
import { AppConfigurationClient, ConfigurationSetting, ConfigurationSettingId, GetConfigurationSettingOptions, GetConfigurationSettingResponse, ListConfigurationSettingsOptions, isFeatureFlag } from "@azure/app-configuration";
import { RestError } from "@azure/core-rest-pipeline";
import { AzureAppConfiguration, ConfigurationObjectConstructionOptions } from "./AzureAppConfiguration";
import { AzureAppConfigurationOptions } from "./AzureAppConfigurationOptions";
Expand Down Expand Up @@ -150,7 +150,9 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
const settings = this.#client.listConfigurationSettings(listOptions);

for await (const setting of settings) {
loadedSettings.push(setting);
if (!isFeatureFlag(setting)) { // exclude feature flags
loadedSettings.push(setting);
}
}
}
return loadedSettings;
Expand Down
6 changes: 3 additions & 3 deletions src/JsonKeyValueAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { ConfigurationSetting, secretReferenceContentType } from "@azure/app-configuration";
import { ConfigurationSetting, featureFlagContentType, secretReferenceContentType } from "@azure/app-configuration";
import { IKeyValueAdapter } from "./IKeyValueAdapter";

export class JsonKeyValueAdapter implements IKeyValueAdapter {
static readonly #ExcludedJsonContentTypes: string[] = [
secretReferenceContentType
// TODO: exclude application/vnd.microsoft.appconfig.ff+json after feature management is supported
secretReferenceContentType,
featureFlagContentType
];

canProcess(setting: ConfigurationSetting): boolean {
Expand Down
18 changes: 18 additions & 0 deletions test/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ const mockedKVs = [{
}, {
key: "app5.settings",
value: "placeholder"
}, {
key: ".appconfig.featureflag/Beta",
value: JSON.stringify({
"id": "Beta",
"description": "",
"enabled": true,
"conditions": {
"client_filters": []
}
}),
contentType: "application/vnd.microsoft.appconfig.ff+json;charset=utf-8"
}
].map(createMockedKeyValue);

Expand Down Expand Up @@ -110,6 +121,13 @@ describe("load", function () {
return expect(load("invalid-endpoint-url", credential)).eventually.rejectedWith("Invalid endpoint URL.");
});

it("should not include feature flags directly in the settings", async () => {
const connectionString = createMockedConnectionString();
const settings = await load(connectionString);
expect(settings).not.undefined;
expect(settings.get(".appconfig.featureflag/Beta")).undefined;
});

it("should filter by key and label, has(key) and get(key) should work", async () => {
const connectionString = createMockedConnectionString();
const settings = await load(connectionString, {
Expand Down

0 comments on commit e8a5c7c

Please sign in to comment.