refactor: Create net-request-promise helper for runtimesettin
This commit is contained in:
5 files changed
+18
-9
No files matched your search
@@ -1,7 +1,7 @@
|
||||
const path = require('path');
|
||||
const { spawnSync } = require('../helpers/spawn-promise.js');
|
||||
|
||||
const cliPath = async () => path.resolve(__dirname, '..', 'cli', 'boundary');
|
||||
const cliPath = async () => path.resolve(__dirname, '..', '..', 'cli', 'boundary');
|
||||
|
||||
module.exports = {
|
||||
// Check boundary cli existence
|
||||
|
||||
@@ -22,3 +22,5 @@ const netRequestPromise = (url) =>
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = netRequestPromise;
|
||||
@@ -1,5 +1,5 @@
|
||||
const { spawnAsyncJSONPromise } = require('../helpers/spawn-promise.js');
|
||||
const base62 = require('../utils/base62.js');
|
||||
const sanitizer = require('../utils/sanitizer.js');
|
||||
|
||||
class Session {
|
||||
#id;
|
||||
@@ -77,21 +77,20 @@ class Session {
|
||||
*/
|
||||
cliCommand() {
|
||||
const sanitized = {
|
||||
target_id: base62.escapeAndValidate(this.#targetId),
|
||||
token: base62.escapeAndValidate(this.#token),
|
||||
addr: encodeURI(this.#addr),
|
||||
target_id: sanitizer.base62EscapeAndValidate(this.#targetId),
|
||||
token: sanitizer.base62EscapeAndValidate(this.#token),
|
||||
};
|
||||
|
||||
const command = [
|
||||
'connect',
|
||||
`-target-id=${sanitized.target_id}`,
|
||||
`-token=${sanitized.token}`,
|
||||
`-addr=${sanitized.addr}`,
|
||||
`-addr=${this.#addr}`,
|
||||
'-format=json',
|
||||
];
|
||||
|
||||
if (this.#hostId) {
|
||||
sanitized.host_id = base62.escapeAndValidate(this.#hostId);
|
||||
sanitized.host_id = sanitizer.base62EscapeAndValidate(this.#hostId);
|
||||
command.push(`-host-id=${sanitized.host_id}`);
|
||||
}
|
||||
return command;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const RuntimeSesttings = require('../models/runtime-settings.js');
|
||||
const RuntimeSettings = require('../models/runtime-settings.js');
|
||||
|
||||
// Provides a singleton class instance to enable a consistent view of
|
||||
// runtime settings across the application.
|
||||
|
||||
+9
-1
@@ -1,9 +1,11 @@
|
||||
const { quote } = require('shell-quote');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Super paranoid shell quote/escape and validation. Input must be base62.
|
||||
* @param {string} str
|
||||
*/
|
||||
escapeAndValidate: (str) => {
|
||||
base62EscapeAndValidate: (str) => {
|
||||
const candidate = str.toString();
|
||||
if (candidate.match(/^[A-Za-z0-9_]*$/)) return candidate;
|
||||
throw new Error(`
|
||||
@@ -11,4 +13,10 @@ module.exports = {
|
||||
input contained unsafe characters.
|
||||
`);
|
||||
},
|
||||
/**
|
||||
* Return a quoted string suitable for using in shell commands.
|
||||
* @param {string} str
|
||||
* @returns {string}
|
||||
*/
|
||||
shellEscape: (str) => quote([str]),
|
||||
};
|
||||
Reference in new issue
Block a user