mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-11 09:51:30 +00:00
fix(bru-1142): import environment functionality validations and fixes (#5964)
This commit is contained in:
@@ -90,10 +90,11 @@ export const {
|
||||
export const addGlobalEnvironment = ({ name, variables = [] }) => (dispatch) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const uid = uuid();
|
||||
|
||||
let environment = { name, uid, variables };
|
||||
const { ipcRenderer } = window;
|
||||
ipcRenderer
|
||||
.invoke('renderer:create-global-environment', { name, uid, variables })
|
||||
environmentSchema
|
||||
.validate(environment)
|
||||
.then(() => ipcRenderer.invoke('renderer:create-global-environment', { name, uid, variables }))
|
||||
.then((result) => {
|
||||
const finalName = result?.name || name;
|
||||
dispatch(_addGlobalEnvironment({ name: finalName, uid, variables }));
|
||||
@@ -110,11 +111,12 @@ export const copyGlobalEnvironment = ({ name, environmentUid: baseEnvUid }) => (
|
||||
const globalEnvironments = state.globalEnvironments.globalEnvironments;
|
||||
const baseEnv = globalEnvironments?.find(env => env?.uid == baseEnvUid)
|
||||
const uid = uuid();
|
||||
let environment = { uid, name, variables: baseEnv.variables };
|
||||
const { ipcRenderer } = window;
|
||||
ipcRenderer
|
||||
.invoke('renderer:create-global-environment', { uid, name, variables: baseEnv.variables })
|
||||
environmentSchema
|
||||
.validate(environment)
|
||||
.then(() => ipcRenderer.invoke('renderer:create-global-environment', { uid, name, variables: baseEnv.variables }))
|
||||
.then((result) => {
|
||||
// Use the unique name returned by the IPC handler
|
||||
const finalName = result?.name || name;
|
||||
dispatch(_copyGlobalEnvironment({ name: finalName, uid, variables: baseEnv.variables }));
|
||||
})
|
||||
@@ -151,9 +153,11 @@ export const saveGlobalEnvironment = ({ variables, environmentUid }) => (dispatc
|
||||
return reject(new Error('Environment not found'));
|
||||
}
|
||||
|
||||
let environmentToSave = { ...environment, variables };
|
||||
|
||||
const { ipcRenderer } = window;
|
||||
environmentSchema
|
||||
.validate(environment)
|
||||
.validate(environmentToSave)
|
||||
.then(() => ipcRenderer.invoke('renderer:save-global-environment', {
|
||||
environmentUid,
|
||||
variables
|
||||
@@ -228,8 +232,10 @@ export const globalEnvironmentsUpdateEvent = ({ globalEnvironmentVariables }) =>
|
||||
}
|
||||
});
|
||||
|
||||
let environmentToSave = { ...environment, variables };
|
||||
|
||||
environmentSchema
|
||||
.validate(environment)
|
||||
.validate(environmentToSave)
|
||||
.then(() => ipcRenderer.invoke('renderer:save-global-environment', {
|
||||
environmentUid,
|
||||
variables
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { uuid } from './common/index';
|
||||
|
||||
const isPersistableEnvVarForMerge = (persistedNames) => (v) => {
|
||||
return !v?.ephemeral || v?.persistedValue !== undefined || (v?.name && persistedNames.has(v.name));
|
||||
};
|
||||
@@ -30,12 +32,21 @@ export const buildPersistedEnvVariables = (variables, { mode, persistedNames } =
|
||||
return src.map(toPersistedEnvVarForSave);
|
||||
};
|
||||
|
||||
export const buildEnvVariable = (obj) => {
|
||||
return {
|
||||
export const buildEnvVariable = ({ envVariable: obj, withUuid = false }) => {
|
||||
let envVariable = {
|
||||
name: obj.name ?? '',
|
||||
value: !!obj.secret ? '' : (obj.value ?? ''),
|
||||
type: 'text',
|
||||
enabled: obj.enabled !== false,
|
||||
secret: !!obj.secret
|
||||
};
|
||||
|
||||
if (!withUuid) {
|
||||
return envVariable;
|
||||
}
|
||||
|
||||
return {
|
||||
uid: uuid(),
|
||||
...envVariable
|
||||
};
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ export const exportBrunoEnvironment = async ({ environments, environmentType, fi
|
||||
|
||||
let cleanEnvironments = environments.map((environment) => ({
|
||||
name: environment.name,
|
||||
variables: (environment.variables || []).map(buildEnvVariable)
|
||||
variables: (environment.variables || []).map((envVariable) => buildEnvVariable({ envVariable }))
|
||||
}));
|
||||
|
||||
await ipcRenderer.invoke('renderer:export-environment', {
|
||||
|
||||
@@ -22,7 +22,7 @@ const validateBrunoEnvironment = (env) => {
|
||||
|
||||
return {
|
||||
name: env.name || 'Imported Environment',
|
||||
variables: env.variables.map(buildEnvVariable)
|
||||
variables: env.variables.map((envVariable) => buildEnvVariable({ envVariable, withUuid: true }))
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -412,7 +412,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
fs.mkdirSync(exportPath, { recursive: true });
|
||||
|
||||
for (const environment of environments) {
|
||||
const baseFileName = `${environment.name.replace(/[^a-zA-Z0-9-_]/g, '_')}`;
|
||||
const baseFileName = environment.name ? `${environment.name.replace(/[^a-zA-Z0-9-_]/g, '_')}` : 'environment';
|
||||
const uniqueFileName = generateUniqueName(baseFileName, (name) => fs.existsSync(path.join(exportPath, `${name}.json`)));
|
||||
const fullPath = path.join(exportPath, `${uniqueFileName}.json`);
|
||||
|
||||
@@ -444,7 +444,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
}
|
||||
|
||||
const environment = environments[0];
|
||||
const baseFileName = `${environment.name.replace(/[^a-zA-Z0-9-_]/g, '_')}`;
|
||||
const baseFileName = environment.name ? `${environment.name.replace(/[^a-zA-Z0-9-_]/g, '_')}` : 'environment';
|
||||
const uniqueFileName = generateUniqueName(baseFileName, (name) => fs.existsSync(path.join(filePath, `${name}.json`)));
|
||||
const fullPath = path.join(filePath, `${uniqueFileName}.json`);
|
||||
const jsonContent = JSON.stringify(environmentWithInfo(environment), null, 2);
|
||||
|
||||
Reference in New Issue
Block a user