Feat/displaying variable hints as secrets (#3268)

* feat: added new utility function `getEnvironmentVariablesMasked`
This commit is contained in:
Pragadesh-45 2024-11-21 15:48:32 +05:30 committed by GitHub
parent 0bec17facd
commit 1b30229903
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 2 deletions

View File

@ -44,8 +44,11 @@ if (!SERVER_RENDERED) {
const into = document.createElement('div'); const into = document.createElement('div');
const descriptionDiv = document.createElement('div'); const descriptionDiv = document.createElement('div');
descriptionDiv.className = 'info-description'; descriptionDiv.className = 'info-description';
if (options?.variables?.maskedEnvVariables?.includes(variableName)) {
descriptionDiv.appendChild(document.createTextNode(variableValue)); descriptionDiv.appendChild(document.createTextNode('*****'));
} else {
descriptionDiv.appendChild(document.createTextNode(variableValue));
}
into.appendChild(descriptionDiv); into.appendChild(descriptionDiv);
return into; return into;

View File

@ -815,6 +815,23 @@ export const getEnvironmentVariables = (collection) => {
return variables; return variables;
}; };
export const getEnvironmentVariablesMasked = (collection) => {
// Return an empty array if the collection is invalid or not provided
if (!collection || !collection.activeEnvironmentUid) {
return [];
}
// Find the active environment in the collection
const environment = findEnvironmentInCollection(collection, collection.activeEnvironmentUid);
if (!environment || !environment.variables) {
return [];
}
// Filter the environment variables to get only the masked (secret) ones
return environment.variables
.filter((variable) => variable.name && variable.value && variable.enabled && variable.secret)
.map((variable) => variable.name);
};
const getPathParams = (item) => { const getPathParams = (item) => {
let pathParams = {}; let pathParams = {};
@ -850,6 +867,13 @@ export const getAllVariables = (collection, item) => {
const { globalEnvironmentVariables = {} } = collection; const { globalEnvironmentVariables = {} } = collection;
const { processEnvVariables = {}, runtimeVariables = {} } = collection; const { processEnvVariables = {}, runtimeVariables = {} } = collection;
const mergedVariables = {
...folderVariables,
...requestVariables,
...runtimeVariables
};
const maskedEnvVariables = getEnvironmentVariablesMasked(collection);
const filteredMaskedEnvVariables = maskedEnvVariables.filter((key) => !(key in mergedVariables));
return { return {
...globalEnvironmentVariables, ...globalEnvironmentVariables,
@ -861,6 +885,7 @@ export const getAllVariables = (collection, item) => {
pathParams: { pathParams: {
...pathParams ...pathParams
}, },
maskedEnvVariables: filteredMaskedEnvVariables,
process: { process: {
env: { env: {
...processEnvVariables ...processEnvVariables