chore: pr polish (#596)

This commit is contained in:
Anoop M D
2023-10-18 10:25:01 +05:30
parent d767a144f2
commit d809a58deb
12 changed files with 103 additions and 162 deletions

View File

@@ -18,7 +18,6 @@ const { stringifyJson } = require('../utils/common');
const { openCollectionDialog } = require('../app/collections');
const { generateUidBasedOnHash } = require('../utils/common');
const { moveRequestUid, deleteRequestUid } = require('../cache/requestUids');
const { setPreferences } = require('../store/preferences');
const EnvironmentSecretsStore = require('../store/env-secrets');
const environmentSecretsStore = new EnvironmentSecretsStore();

View File

@@ -5,7 +5,7 @@ function isStrPresent(str) {
return str && str !== '' && str !== 'undefined';
}
async function resolveCredentials(request) {
async function resolveAwsV4Credentials(request) {
const awsv4 = request.awsv4config;
if (isStrPresent(awsv4.profileName)) {
try {
@@ -52,5 +52,5 @@ function addAwsV4Interceptor(axiosInstance, request) {
module.exports = {
addAwsV4Interceptor,
resolveCredentials
resolveAwsV4Credentials
};

View File

@@ -16,14 +16,14 @@ const { uuid } = require('../../utils/common');
const interpolateVars = require('./interpolate-vars');
const { interpolateString } = require('./interpolate-string');
const { sortFolder, getAllRequestsInFolderRecursively } = require('./helper');
const { preferences } = require('../../store/preferences');
const { preferencesUtil } = require('../../store/preferences');
const { getProcessEnvVars } = require('../../store/process-env');
const { getBrunoConfig } = require('../../store/bruno-config');
const { HttpsProxyAgent } = require('https-proxy-agent');
const { HttpProxyAgent } = require('http-proxy-agent');
const { SocksProxyAgent } = require('socks-proxy-agent');
const { makeAxiosInstance } = require('./axios-instance');
const { addAwsV4Interceptor, resolveCredentials } = require('./awsv4auth-helper');
const { addAwsV4Interceptor, resolveAwsV4Credentials } = require('./awsv4auth-helper');
const { shouldUseProxy } = require('../../utils/proxy-util');
// override the default escape function to prevent escaping
@@ -86,7 +86,7 @@ const getSize = (data) => {
const configureRequest = async (collectionUid, request, envVars, collectionVariables, processEnvVars) => {
const httpsAgentRequestFields = {};
if (!preferences.isTlsVerification()) {
if (!preferencesUtil.shouldVerifyTls()) {
httpsAgentRequestFields['rejectUnauthorized'] = false;
}
@@ -123,10 +123,10 @@ const configureRequest = async (collectionUid, request, envVars, collectionVaria
let proxyConfig = get(brunoConfig, 'proxy', {});
let proxyEnabled = get(proxyConfig, 'enabled', 'disabled');
if (proxyEnabled === 'global') {
proxyConfig = preferences.getProxyConfig();
proxyConfig = preferencesUtil.getGlobalProxyConfig();
proxyEnabled = get(proxyConfig, 'enabled', false);
}
const shouldProxy = shouldUseProxy(request.url, get(proxyConfig, 'noProxy', ''));
const shouldProxy = shouldUseProxy(request.url, get(proxyConfig, 'bypassProxy', ''));
if ((proxyEnabled === true || proxyEnabled === 'enabled') && shouldProxy) {
const proxyProtocol = interpolateString(get(proxyConfig, 'protocol'), interpolationOptions);
const proxyHostname = interpolateString(get(proxyConfig, 'hostname'), interpolationOptions);
@@ -164,12 +164,12 @@ const configureRequest = async (collectionUid, request, envVars, collectionVaria
const axiosInstance = makeAxiosInstance();
if (request.awsv4config) {
request.awsv4config = await resolveCredentials(request);
request.awsv4config = await resolveAwsV4Credentials(request);
addAwsV4Interceptor(axiosInstance, request);
delete request.awsv4config;
}
request.timeout = preferences.getTimeout();
request.timeout = preferencesUtil.getRequestTimeout();
return axiosInstance;
};
@@ -530,9 +530,9 @@ const registerNetworkIpc = (mainWindow) => {
const collectionRoot = get(collection, 'root', {});
const preparedRequest = prepareGqlIntrospectionRequest(endpoint, envVars, request, collectionRoot);
request.timeout = preferences.getTimeout();
request.timeout = preferencesUtil.getRequestTimeout();
if (!preferences.isTlsVerification()) {
if (!preferencesUtil.shouldVerifyTls()) {
request.httpsAgent = new https.Agent({
rejectUnauthorized: false
});

View File

@@ -1,64 +1,9 @@
const { ipcMain } = require('electron');
const { getPreferences, savePreferences, getPath } = require('../store/preferences');
const { getPreferences, savePreferences } = require('../store/preferences');
const { isDirectory } = require('../utils/filesystem');
const { openCollection } = require('../app/collections');
const stores = require('../store');
const chokidar = require('chokidar');
``;
const registerPreferencesIpc = (mainWindow, watcher, lastOpenedCollections) => {
const change = async (pathname, store) => {
if (store === stores.PREFERENCES) {
mainWindow.webContents.send('main:load-preferences', getPreferences());
}
};
class StoreWatcher {
constructor() {
this.watchers = {};
}
addWatcher(watchPath, store) {
console.log(`watcher add: ${watchPath} for store ${store}`);
if (this.watchers[watchPath]) {
this.watchers[watchPath].close();
}
const self = this;
setTimeout(() => {
const watcher = chokidar.watch(watchPath, {
ignoreInitial: false,
usePolling: false,
persistent: true,
ignorePermissionErrors: true,
awaitWriteFinish: {
stabilityThreshold: 80,
pollInterval: 10
},
depth: 20
});
watcher.on('change', (pathname) => change(pathname, store));
self.watchers[watchPath] = watcher;
}, 100);
}
hasWatcher(watchPath) {
return this.watchers[watchPath];
}
removeWatcher(watchPath) {
if (this.watchers[watchPath]) {
this.watchers[watchPath].close();
this.watchers[watchPath] = null;
}
}
}
const storeWatcher = new StoreWatcher();
storeWatcher.addWatcher(getPath(), stores.PREFERENCES);
ipcMain.handle('renderer:ready', async (event) => {
// load preferences
const preferences = getPreferences();