From 3416d43d0100a6144b2b8ba6bca07f9069d6d41b Mon Sep 17 00:00:00 2001 From: Yan Zhang Date: Mon, 8 Apr 2024 13:41:27 +0800 Subject: [PATCH] Exclude feature flags from loaded settings --- src/AzureAppConfigurationImpl.ts | 6 ++++-- src/JsonKeyValueAdapter.ts | 6 +++--- test/load.test.ts | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/AzureAppConfigurationImpl.ts b/src/AzureAppConfigurationImpl.ts index 41e66a62..ba13e608 100644 --- a/src/AzureAppConfigurationImpl.ts +++ b/src/AzureAppConfigurationImpl.ts @@ -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"; @@ -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; diff --git a/src/JsonKeyValueAdapter.ts b/src/JsonKeyValueAdapter.ts index 4be758a1..e821af70 100644 --- a/src/JsonKeyValueAdapter.ts +++ b/src/JsonKeyValueAdapter.ts @@ -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 { diff --git a/test/load.test.ts b/test/load.test.ts index 63f1cfd1..62713695 100644 --- a/test/load.test.ts +++ b/test/load.test.ts @@ -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); @@ -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, {