From d550919ab9ec4d602d1b0184ce57d4b7bf46051f Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Mon, 9 Oct 2023 16:48:09 +0000 Subject: [PATCH 1/7] chore(middleware-endpoint): add getEndpointUrlConfig --- packages/middleware-endpoint/package.json | 1 + .../src/adaptors/getEndpointUrlConfig.spec.ts | 63 +++++++++++++++++++ .../src/adaptors/getEndpointUrlConfig.ts | 35 +++++++++++ yarn.lock | 1 + 4 files changed, 100 insertions(+) create mode 100644 packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts create mode 100644 packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts diff --git a/packages/middleware-endpoint/package.json b/packages/middleware-endpoint/package.json index 4b921b7b712..41e01fdd9c7 100644 --- a/packages/middleware-endpoint/package.json +++ b/packages/middleware-endpoint/package.json @@ -24,6 +24,7 @@ "license": "Apache-2.0", "dependencies": { "@smithy/middleware-serde": "workspace:^", + "@smithy/node-config-provider": "workspace:^", "@smithy/types": "workspace:^", "@smithy/url-parser": "workspace:^", "@smithy/util-middleware": "workspace:^", diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts new file mode 100644 index 00000000000..00347535da8 --- /dev/null +++ b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts @@ -0,0 +1,63 @@ +import { getEndpointUrlConfig } from "./getEndpointUrlConfig"; + +const ENV_ENDPOINT_URL = "AWS_ENDPOINT_URL"; +const CONFIG_ENDPOINT_URL = "endpoint_url"; + +describe(getEndpointUrlConfig.name, () => { + const serviceId = "foo"; + const endpointUrlConfig = getEndpointUrlConfig(serviceId); + + const mockEndpoint = "https://mock-endpoint.com"; + const ORIGINAL_ENV = process.env; + + beforeEach(() => { + process.env = {}; + }); + + afterEach(() => { + process.env = ORIGINAL_ENV; + }); + + describe("environmentVariableSelector", () => { + const serviceMockEndpoint = `${mockEndpoint}/${serviceId}`; + + beforeEach(() => { + process.env[ENV_ENDPOINT_URL] = mockEndpoint; + process.env[`${ENV_ENDPOINT_URL}_${serviceId.toUpperCase()}`] = serviceMockEndpoint; + }); + + it("returns service specific endpoint from environment variable, if available", () => { + expect(endpointUrlConfig.environmentVariableSelector(process.env)).toEqual(serviceMockEndpoint); + }); + + it("returns endpoint from environment variable, if available", () => { + process.env[`${ENV_ENDPOINT_URL}_${serviceId.toUpperCase()}`] = undefined; + expect(endpointUrlConfig.environmentVariableSelector(process.env)).toEqual(mockEndpoint); + }); + + it("returns undefined, if endpoint not available in environment variables", () => { + process.env[ENV_ENDPOINT_URL] = undefined; + process.env[`${ENV_ENDPOINT_URL}_${serviceId.toUpperCase()}`] = undefined; + expect(endpointUrlConfig.environmentVariableSelector(process.env)).toBeUndefined(); + }); + }); + + describe("configFileSelector", () => { + it("returns service specific endpoint from config file, if available", () => { + // ToDo + }); + + it("returns endpoint from config file, if available", () => { + const profile = { [CONFIG_ENDPOINT_URL]: mockEndpoint }; + expect(endpointUrlConfig.configFileSelector(profile)).toEqual(mockEndpoint); + }); + + it("returns undefined, if endpoint not available in config", () => { + expect(endpointUrlConfig.environmentVariableSelector({})).toBeUndefined(); + }); + }); + + it("returns undefined by default", () => { + expect(endpointUrlConfig.default).toBeUndefined(); + }); +}); diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts new file mode 100644 index 00000000000..4ba48b75254 --- /dev/null +++ b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts @@ -0,0 +1,35 @@ +import { LoadedConfigSelectors } from "@smithy/node-config-provider"; + +const ENV_ENDPOINT_URL = "AWS_ENDPOINT_URL"; +const CONFIG_ENDPOINT_URL = "endpoint_url"; + +export const getEndpointUrlConfig = (serviceId: string): LoadedConfigSelectors => ({ + environmentVariableSelector: (env) => { + // The value provided by a service-specific environment variable. + const serviceEndpointUrlSections = [ENV_ENDPOINT_URL, serviceId.toUpperCase()]; + const serviceEndpointUrl = env[serviceEndpointUrlSections.join("_")]; + if (serviceEndpointUrl) return serviceEndpointUrl; + + // The value provided by the global endpoint environment variable. + const endpointUrl = env[ENV_ENDPOINT_URL]; + if (endpointUrl) return endpointUrl; + + return undefined; + }, + + configFileSelector: (profile) => { + // The value provided by a service-specific parameter from a services definition section + // referenced in a profile in the shared configuration file. + + // ToDo: profile is selected one. It does not have access to other 'services' section. + // We should call loadSharedConfigFiles directly. + + // The value provided by the global parameter from a profile in the shared configuration file. + const endpointUrl = profile[CONFIG_ENDPOINT_URL]; + if (endpointUrl) return endpointUrl; + + return undefined; + }, + + default: undefined, +}); diff --git a/yarn.lock b/yarn.lock index c338f9b197c..2fcc014cd3b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2071,6 +2071,7 @@ __metadata: resolution: "@smithy/middleware-endpoint@workspace:packages/middleware-endpoint" dependencies: "@smithy/middleware-serde": "workspace:^" + "@smithy/node-config-provider": "workspace:^" "@smithy/types": "workspace:^" "@smithy/url-parser": "workspace:^" "@smithy/util-middleware": "workspace:^" From e770e34ca63e9563dfbba53a8048f13c8e3509bc Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Mon, 9 Oct 2023 17:03:47 +0000 Subject: [PATCH 2/7] Get endpoint from config before resolving --- packages/middleware-endpoint/package.json | 6 ++++++ .../src/adaptors/getEndpointFromConfig.browser.ts | 1 + .../src/adaptors/getEndpointFromConfig.ts | 5 +++++ .../src/adaptors/getEndpointFromInstructions.ts | 7 +++++++ packages/middleware-endpoint/src/resolveEndpointConfig.ts | 6 ++++++ 5 files changed, 25 insertions(+) create mode 100644 packages/middleware-endpoint/src/adaptors/getEndpointFromConfig.browser.ts create mode 100644 packages/middleware-endpoint/src/adaptors/getEndpointFromConfig.ts diff --git a/packages/middleware-endpoint/package.json b/packages/middleware-endpoint/package.json index 41e01fdd9c7..2389c8e3f87 100644 --- a/packages/middleware-endpoint/package.json +++ b/packages/middleware-endpoint/package.json @@ -50,6 +50,12 @@ "files": [ "dist-*/**" ], + "browser": { + "./dist-es/adaptors/getEndpointFromConfig": "./dist-es/adaptors/getEndpointFromConfig.browser" + }, + "react-native": { + "./dist-es/adaptors/getEndpointFromConfig": "./dist-es/adaptors/getEndpointFromConfig.browser" + }, "homepage": "https://github.com/awslabs/smithy-typescript/tree/main/packages/middleware-endpoint", "repository": { "type": "git", diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointFromConfig.browser.ts b/packages/middleware-endpoint/src/adaptors/getEndpointFromConfig.browser.ts new file mode 100644 index 00000000000..4d3a6450862 --- /dev/null +++ b/packages/middleware-endpoint/src/adaptors/getEndpointFromConfig.browser.ts @@ -0,0 +1 @@ +export const getEndpointFromConfig = async (serviceId: string) => undefined; diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointFromConfig.ts b/packages/middleware-endpoint/src/adaptors/getEndpointFromConfig.ts new file mode 100644 index 00000000000..903f66fbb21 --- /dev/null +++ b/packages/middleware-endpoint/src/adaptors/getEndpointFromConfig.ts @@ -0,0 +1,5 @@ +import { loadConfig } from "@smithy/node-config-provider"; + +import { getEndpointUrlConfig } from "./getEndpointUrlConfig"; + +export const getEndpointFromConfig = async (serviceId: string) => loadConfig(getEndpointUrlConfig(serviceId))(); diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts b/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts index 0feb4965d1a..3ca17f92b78 100644 --- a/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts +++ b/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts @@ -4,6 +4,8 @@ import { EndpointResolvedConfig } from "../resolveEndpointConfig"; import { resolveParamsForS3 } from "../service-customizations"; import { EndpointParameterInstructions } from "../types"; import { createConfigValueProvider } from "./createConfigValueProvider"; +import { getEndpointFromConfig } from "./getEndpointFromConfig"; +import { toEndpointV1 } from "./toEndpointV1"; /** * @internal @@ -36,6 +38,11 @@ export const getEndpointFromInstructions = async < clientConfig: Partial> & Config, context?: HandlerExecutionContext ): Promise => { + const endpointFromConfig = await getEndpointFromConfig(clientConfig.serviceId || ""); + if (endpointFromConfig) { + clientConfig.endpoint = () => Promise.resolve(toEndpointV1(endpointFromConfig)); + } + const endpointParams = await resolveParams(commandInput, instructionsSupplier, clientConfig); if (typeof clientConfig.endpointProvider !== "function") { diff --git a/packages/middleware-endpoint/src/resolveEndpointConfig.ts b/packages/middleware-endpoint/src/resolveEndpointConfig.ts index c786f163383..3bbd3368527 100644 --- a/packages/middleware-endpoint/src/resolveEndpointConfig.ts +++ b/packages/middleware-endpoint/src/resolveEndpointConfig.ts @@ -89,6 +89,12 @@ export interface EndpointResolvedConfig; + + /** + * Unique service identifier. + * @internal + */ + serviceId?: string; } /** From 86d669bcb47f113e122fdd396b363fd189c106f8 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Mon, 9 Oct 2023 17:33:45 +0000 Subject: [PATCH 3/7] Get endpoint from config only if it's not defined --- .../src/adaptors/getEndpointFromInstructions.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts b/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts index 3ca17f92b78..3dcbd5466c3 100644 --- a/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts +++ b/packages/middleware-endpoint/src/adaptors/getEndpointFromInstructions.ts @@ -38,9 +38,11 @@ export const getEndpointFromInstructions = async < clientConfig: Partial> & Config, context?: HandlerExecutionContext ): Promise => { - const endpointFromConfig = await getEndpointFromConfig(clientConfig.serviceId || ""); - if (endpointFromConfig) { - clientConfig.endpoint = () => Promise.resolve(toEndpointV1(endpointFromConfig)); + if (!clientConfig.endpoint) { + const endpointFromConfig = await getEndpointFromConfig(clientConfig.serviceId || ""); + if (endpointFromConfig) { + clientConfig.endpoint = () => Promise.resolve(toEndpointV1(endpointFromConfig)); + } } const endpointParams = await resolveParams(commandInput, instructionsSupplier, clientConfig); From 2c9e2ce5c084896fb75bb17dd3699563dedfd702 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Mon, 9 Oct 2023 19:57:57 +0000 Subject: [PATCH 4/7] Read endpointUrl from services configuration --- .../src/adaptors/getEndpointUrlConfig.spec.ts | 21 ++++++++++++++++++- .../src/adaptors/getEndpointUrlConfig.ts | 14 ++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts index 00347535da8..b7e7aa5e46d 100644 --- a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts +++ b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts @@ -1,3 +1,5 @@ +import { CONFIG_PREFIX_SEPARATOR } from "@smithy/shared-ini-file-loader"; + import { getEndpointUrlConfig } from "./getEndpointUrlConfig"; const ENV_ENDPOINT_URL = "AWS_ENDPOINT_URL"; @@ -43,8 +45,25 @@ describe(getEndpointUrlConfig.name, () => { }); describe("configFileSelector", () => { + const serviceMockEndpoint = `${mockEndpoint}/${serviceId}`; + it("returns service specific endpoint from config file, if available", () => { - // ToDo + const servicesSectionPrefix = "services"; + const servicesSectionName = "config-services"; + + const profile = { + [servicesSectionPrefix]: servicesSectionName, + [CONFIG_ENDPOINT_URL]: mockEndpoint, + }; + + const config = { + [serviceId]: profile, + [[servicesSectionPrefix, servicesSectionName].join(CONFIG_PREFIX_SEPARATOR)]: { + [[serviceId, CONFIG_ENDPOINT_URL].join(CONFIG_PREFIX_SEPARATOR)]: serviceMockEndpoint, + }, + }; + + expect(endpointUrlConfig.configFileSelector(profile, config)).toEqual(serviceMockEndpoint); }); it("returns endpoint from config file, if available", () => { diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts index 4ba48b75254..278768c277e 100644 --- a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts +++ b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts @@ -1,4 +1,5 @@ import { LoadedConfigSelectors } from "@smithy/node-config-provider"; +import { CONFIG_PREFIX_SEPARATOR } from "@smithy/shared-ini-file-loader"; const ENV_ENDPOINT_URL = "AWS_ENDPOINT_URL"; const CONFIG_ENDPOINT_URL = "endpoint_url"; @@ -17,12 +18,15 @@ export const getEndpointUrlConfig = (serviceId: string): LoadedConfigSelectors { + configFileSelector: (profile, config) => { // The value provided by a service-specific parameter from a services definition section - // referenced in a profile in the shared configuration file. - - // ToDo: profile is selected one. It does not have access to other 'services' section. - // We should call loadSharedConfigFiles directly. + if (config && profile.services) { + const servicesSection = config[["services", profile.services].join(CONFIG_PREFIX_SEPARATOR)]; + if (servicesSection) { + const endpointUrl = servicesSection[[serviceId, CONFIG_ENDPOINT_URL].join(CONFIG_PREFIX_SEPARATOR)]; + if (endpointUrl) return endpointUrl; + } + } // The value provided by the global parameter from a profile in the shared configuration file. const endpointUrl = profile[CONFIG_ENDPOINT_URL]; From 5739d6c3754313731226489de1ca50447d7c979e Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Mon, 9 Oct 2023 19:58:46 +0000 Subject: [PATCH 5/7] chore: yarn changeset add --- .changeset/cool-mugs-design.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/cool-mugs-design.md diff --git a/.changeset/cool-mugs-design.md b/.changeset/cool-mugs-design.md new file mode 100644 index 00000000000..dcd865b025f --- /dev/null +++ b/.changeset/cool-mugs-design.md @@ -0,0 +1,5 @@ +--- +"@smithy/middleware-endpoint": minor +--- + +Read service specific endpoints from env/config From 4ebfd1ad29e287978ea0eac071b5e8fd0ce61fc3 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Mon, 9 Oct 2023 20:49:50 +0000 Subject: [PATCH 6/7] Support reading endpoints from env when serviceId contains spaces --- .../src/adaptors/getEndpointUrlConfig.spec.ts | 15 +++++++++------ .../src/adaptors/getEndpointUrlConfig.ts | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts index b7e7aa5e46d..612d22d232f 100644 --- a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts +++ b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts @@ -21,25 +21,28 @@ describe(getEndpointUrlConfig.name, () => { }); describe("environmentVariableSelector", () => { - const serviceMockEndpoint = `${mockEndpoint}/${serviceId}`; - beforeEach(() => { process.env[ENV_ENDPOINT_URL] = mockEndpoint; - process.env[`${ENV_ENDPOINT_URL}_${serviceId.toUpperCase()}`] = serviceMockEndpoint; }); - it("returns service specific endpoint from environment variable, if available", () => { + it.each([ + ["foo", `${ENV_ENDPOINT_URL}_FOO`], + ["foobar", `${ENV_ENDPOINT_URL}_FOOBAR`], + ["foo bar", `${ENV_ENDPOINT_URL}_FOO_BAR`], + ])("returns endpoint for '%s' from environment variable %s", (serviceId, envKey) => { + const serviceMockEndpoint = `${mockEndpoint}/${envKey}`; + process.env[envKey] = serviceMockEndpoint; + + const endpointUrlConfig = getEndpointUrlConfig(serviceId); expect(endpointUrlConfig.environmentVariableSelector(process.env)).toEqual(serviceMockEndpoint); }); it("returns endpoint from environment variable, if available", () => { - process.env[`${ENV_ENDPOINT_URL}_${serviceId.toUpperCase()}`] = undefined; expect(endpointUrlConfig.environmentVariableSelector(process.env)).toEqual(mockEndpoint); }); it("returns undefined, if endpoint not available in environment variables", () => { process.env[ENV_ENDPOINT_URL] = undefined; - process.env[`${ENV_ENDPOINT_URL}_${serviceId.toUpperCase()}`] = undefined; expect(endpointUrlConfig.environmentVariableSelector(process.env)).toBeUndefined(); }); }); diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts index 278768c277e..025a7f4f787 100644 --- a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts +++ b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts @@ -7,7 +7,7 @@ const CONFIG_ENDPOINT_URL = "endpoint_url"; export const getEndpointUrlConfig = (serviceId: string): LoadedConfigSelectors => ({ environmentVariableSelector: (env) => { // The value provided by a service-specific environment variable. - const serviceEndpointUrlSections = [ENV_ENDPOINT_URL, serviceId.toUpperCase()]; + const serviceEndpointUrlSections = [ENV_ENDPOINT_URL, ...serviceId.split(" ").map((w) => w.toUpperCase())]; const serviceEndpointUrl = env[serviceEndpointUrlSections.join("_")]; if (serviceEndpointUrl) return serviceEndpointUrl; From de4a670ec100350512ffdebf856315f04f3eacca Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Mon, 9 Oct 2023 21:03:17 +0000 Subject: [PATCH 7/7] Support reading endpoints from config when serviceId contains spaces --- .../src/adaptors/getEndpointUrlConfig.spec.ts | 16 ++++++++++------ .../src/adaptors/getEndpointUrlConfig.ts | 8 +++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts index 612d22d232f..cf69f78f759 100644 --- a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts +++ b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.spec.ts @@ -37,7 +37,7 @@ describe(getEndpointUrlConfig.name, () => { expect(endpointUrlConfig.environmentVariableSelector(process.env)).toEqual(serviceMockEndpoint); }); - it("returns endpoint from environment variable, if available", () => { + it(`returns endpoint from environment variable ${ENV_ENDPOINT_URL}`, () => { expect(endpointUrlConfig.environmentVariableSelector(process.env)).toEqual(mockEndpoint); }); @@ -48,11 +48,14 @@ describe(getEndpointUrlConfig.name, () => { }); describe("configFileSelector", () => { - const serviceMockEndpoint = `${mockEndpoint}/${serviceId}`; - - it("returns service specific endpoint from config file, if available", () => { + it.each([ + ["foo", "foo"], + ["foobar", "foobar"], + ["foo bar", "foo_bar"], + ])("returns endpoint for '%s' from config file '%s'", (serviceId, serviceConfigId) => { const servicesSectionPrefix = "services"; const servicesSectionName = "config-services"; + const serviceMockEndpoint = `${mockEndpoint}/${serviceConfigId}`; const profile = { [servicesSectionPrefix]: servicesSectionName, @@ -62,14 +65,15 @@ describe(getEndpointUrlConfig.name, () => { const config = { [serviceId]: profile, [[servicesSectionPrefix, servicesSectionName].join(CONFIG_PREFIX_SEPARATOR)]: { - [[serviceId, CONFIG_ENDPOINT_URL].join(CONFIG_PREFIX_SEPARATOR)]: serviceMockEndpoint, + [[serviceConfigId, CONFIG_ENDPOINT_URL].join(CONFIG_PREFIX_SEPARATOR)]: serviceMockEndpoint, }, }; + const endpointUrlConfig = getEndpointUrlConfig(serviceId); expect(endpointUrlConfig.configFileSelector(profile, config)).toEqual(serviceMockEndpoint); }); - it("returns endpoint from config file, if available", () => { + it(`returns endpoint from config ${CONFIG_ENDPOINT_URL}`, () => { const profile = { [CONFIG_ENDPOINT_URL]: mockEndpoint }; expect(endpointUrlConfig.configFileSelector(profile)).toEqual(mockEndpoint); }); diff --git a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts index 025a7f4f787..c045529ad6e 100644 --- a/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts +++ b/packages/middleware-endpoint/src/adaptors/getEndpointUrlConfig.ts @@ -7,8 +7,8 @@ const CONFIG_ENDPOINT_URL = "endpoint_url"; export const getEndpointUrlConfig = (serviceId: string): LoadedConfigSelectors => ({ environmentVariableSelector: (env) => { // The value provided by a service-specific environment variable. - const serviceEndpointUrlSections = [ENV_ENDPOINT_URL, ...serviceId.split(" ").map((w) => w.toUpperCase())]; - const serviceEndpointUrl = env[serviceEndpointUrlSections.join("_")]; + const serviceSuffixParts = serviceId.split(" ").map((w) => w.toUpperCase()); + const serviceEndpointUrl = env[[ENV_ENDPOINT_URL, ...serviceSuffixParts].join("_")]; if (serviceEndpointUrl) return serviceEndpointUrl; // The value provided by the global endpoint environment variable. @@ -23,7 +23,9 @@ export const getEndpointUrlConfig = (serviceId: string): LoadedConfigSelectors w.toLowerCase()); + const endpointUrl = + servicesSection[[servicePrefixParts.join("_"), CONFIG_ENDPOINT_URL].join(CONFIG_PREFIX_SEPARATOR)]; if (endpointUrl) return endpointUrl; } }