From 8992a457a88a50bbbe665bfb845bdd04e27f1364 Mon Sep 17 00:00:00 2001 From: _Pragadesh M Date: Sun, 15 Dec 2024 16:45:54 +0530 Subject: [PATCH] Feat/displaying variable hints as secrets for Global Environment Secrets (#3591) * feat: added new utility function `getEnvironmentVariablesMasked` * refactor: Update `getAllVariables` function in `collections/index.js` * refactor: Update `brunoVarInfo.js` to handle masked environment variables * code cleanup * feat: Add masked global environment variables functionality * refactor: Rename variables for clarity in RequestTabPanel component * feat: updates * Update index.js --------- Co-authored-by: Pragadesh-45 --- .../src/components/RequestTabPanel/index.js | 4 ++- .../bruno-app/src/utils/collections/index.js | 31 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/packages/bruno-app/src/components/RequestTabPanel/index.js b/packages/bruno-app/src/components/RequestTabPanel/index.js index e1f4b6fda..944b686fc 100644 --- a/packages/bruno-app/src/components/RequestTabPanel/index.js +++ b/packages/bruno-app/src/components/RequestTabPanel/index.js @@ -20,7 +20,7 @@ import { DocExplorer } from '@usebruno/graphql-docs'; import StyledWrapper from './StyledWrapper'; import SecuritySettings from 'components/SecuritySettings'; import FolderSettings from 'components/FolderSettings'; -import { getGlobalEnvironmentVariables } from 'utils/collections/index'; +import { getGlobalEnvironmentVariables, getGlobalEnvironmentVariablesMasked } from 'utils/collections/index'; import { produce } from 'immer'; const MIN_LEFT_PANE_WIDTH = 300; @@ -45,7 +45,9 @@ const RequestTabPanel = () => { if (collection) { // add selected global env variables to the collection object const globalEnvironmentVariables = getGlobalEnvironmentVariables({ globalEnvironments, activeGlobalEnvironmentUid }); + const globalEnvSecrets = getGlobalEnvironmentVariablesMasked({ globalEnvironments, activeGlobalEnvironmentUid }); collection.globalEnvironmentVariables = globalEnvironmentVariables; + collection.globalEnvSecrets = globalEnvSecrets; } }); diff --git a/packages/bruno-app/src/utils/collections/index.js b/packages/bruno-app/src/utils/collections/index.js index a88346a08..3a691e53f 100644 --- a/packages/bruno-app/src/utils/collections/index.js +++ b/packages/bruno-app/src/utils/collections/index.js @@ -805,6 +805,19 @@ export const getGlobalEnvironmentVariables = ({ globalEnvironments, activeGlobal return variables; }; +export const getGlobalEnvironmentVariablesMasked = ({ globalEnvironments, activeGlobalEnvironmentUid }) => { + const environment = globalEnvironments?.find(env => env?.uid === activeGlobalEnvironmentUid); + + if (environment && Array.isArray(environment.variables)) { + return environment.variables + .filter((variable) => variable.name && variable.value && variable.enabled && variable.secret) + .map((variable) => variable.name); + } + + return []; +}; + + export const getEnvironmentVariables = (collection) => { let variables = {}; if (collection) { @@ -878,8 +891,22 @@ export const getAllVariables = (collection, item) => { ...requestVariables, ...runtimeVariables }; - const maskedEnvVariables = getEnvironmentVariablesMasked(collection); + + const mergedVariablesGlobal = { + ...collectionVariables, + ...envVariables, + ...folderVariables, + ...requestVariables, + ...runtimeVariables, + } + + const maskedEnvVariables = getEnvironmentVariablesMasked(collection) || []; + const maskedGlobalEnvVariables = collection?.globalEnvSecrets || []; + const filteredMaskedEnvVariables = maskedEnvVariables.filter((key) => !(key in mergedVariables)); + const filteredMaskedGlobalEnvVariables = maskedGlobalEnvVariables.filter((key) => !(key in mergedVariablesGlobal)); + + const uniqueMaskedVariables = [...new Set([...filteredMaskedEnvVariables, ...filteredMaskedGlobalEnvVariables])]; return { ...globalEnvironmentVariables, @@ -891,7 +918,7 @@ export const getAllVariables = (collection, item) => { pathParams: { ...pathParams }, - maskedEnvVariables: filteredMaskedEnvVariables, + maskedEnvVariables: uniqueMaskedVariables, process: { env: { ...processEnvVariables