From 974f076f48adaea620b1b57e5d8a96aefa410fcc Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Thu, 29 Jun 2023 21:06:41 -0700 Subject: [PATCH] Fixed httpsAgent toggle --- src/client/relay/index.js | 9 +++++---- src/external/switcher-api-facade.js | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/client/relay/index.js b/src/client/relay/index.js index 86b7ab2..45329a7 100644 --- a/src/client/relay/index.js +++ b/src/client/relay/index.js @@ -1,9 +1,10 @@ import axios from 'axios'; import https from 'https'; import { StrategiesToRelayDataType, RelayMethods } from '../../models/config'; +import { checkHttpsAgent } from '../../external/switcher-api-facade'; -const agent = async () => { - const rejectUnauthorized = false; +const agent = async (url) => { + const rejectUnauthorized = !(await checkHttpsAgent(url)); return new https.Agent({ rejectUnauthorized }); }; @@ -47,7 +48,7 @@ export async function resolveVerification(relay, environment) { async function post(url, data, headers) { try { - return await axios.post(url, data, { httpsAgent: await agent(), headers }); + return await axios.post(url, data, { httpsAgent: await agent(url), headers }); } catch (error) { throw new Error(`Failed to reach ${url} via POST`); } @@ -55,7 +56,7 @@ async function post(url, data, headers) { async function get(url, data, headers) { try { - return await axios.get(`${url}${data}`, { httpsAgent: await agent(), headers }); + return await axios.get(`${url}${data}`, { httpsAgent: await agent(url), headers }); } catch (error) { throw new Error(`Failed to reach ${url} via GET`); } diff --git a/src/external/switcher-api-facade.js b/src/external/switcher-api-facade.js index 1f2a546..af6f48f 100644 --- a/src/external/switcher-api-facade.js +++ b/src/external/switcher-api-facade.js @@ -17,7 +17,6 @@ const logger = process.env.SWITCHER_API_LOGGER == 'true'; const component = 'switcherapi'; Switcher.buildContext({ url, apiKey, domain: domainName, component, environment }, { logger }); -const switcher = Switcher.factory(); export const SwitcherKeys = Object.freeze({ ELEMENT_CREATION: 'ELEMENT_CREATION', @@ -37,7 +36,9 @@ function switcherFlagResult(flag, message) { } export async function checkFeature(feature, params, restrictTo = SwitcherKeys) { + const switcher = Switcher.factory(); const key = Object.values(restrictTo).find(element => element === feature); + if (!key) throw new BadRequestError('Invalid feature'); @@ -193,6 +194,7 @@ export function notifyAcCreation(adminid) { if (process.env.SWITCHER_API_ENABLE != 'true') return; + const switcher = Switcher.factory(); switcher.isItOn(SwitcherKeys.ACCOUNT_IN_NOTIFY, [ checkValue(adminid)]); } @@ -201,6 +203,7 @@ export function notifyAcDeletion(adminid) { if (process.env.SWITCHER_API_ENABLE != 'true') return; + const switcher = Switcher.factory(); switcher.isItOn(SwitcherKeys.ACCOUNT_OUT_NOTIFY, [ checkValue(adminid)]); }