Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude feature flags from loaded settings #55

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Eskibear marked this conversation as resolved.
Show resolved Hide resolved
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
Loading