Skip to content

Commit e8a5c7c

Browse files
authored
Exclude feature flags from loaded settings (#55)
1 parent 6844f7e commit e8a5c7c

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/AzureAppConfigurationImpl.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

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

152152
for await (const setting of settings) {
153-
loadedSettings.push(setting);
153+
if (!isFeatureFlag(setting)) { // exclude feature flags
154+
loadedSettings.push(setting);
155+
}
154156
}
155157
}
156158
return loadedSettings;

src/JsonKeyValueAdapter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

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

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

1313
canProcess(setting: ConfigurationSetting): boolean {

test/load.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ const mockedKVs = [{
6262
}, {
6363
key: "app5.settings",
6464
value: "placeholder"
65+
}, {
66+
key: ".appconfig.featureflag/Beta",
67+
value: JSON.stringify({
68+
"id": "Beta",
69+
"description": "",
70+
"enabled": true,
71+
"conditions": {
72+
"client_filters": []
73+
}
74+
}),
75+
contentType: "application/vnd.microsoft.appconfig.ff+json;charset=utf-8"
6576
}
6677
].map(createMockedKeyValue);
6778

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

124+
it("should not include feature flags directly in the settings", async () => {
125+
const connectionString = createMockedConnectionString();
126+
const settings = await load(connectionString);
127+
expect(settings).not.undefined;
128+
expect(settings.get(".appconfig.featureflag/Beta")).undefined;
129+
});
130+
113131
it("should filter by key and label, has(key) and get(key) should work", async () => {
114132
const connectionString = createMockedConnectionString();
115133
const settings = await load(connectionString, {

0 commit comments

Comments
 (0)