* [COMPLIANCE] Add Copyright and License Headers * chore: 🤖 update Copyright headers to satisfy our lint rules --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
36 lines
844 B
JavaScript
36 lines
844 B
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
const { URL } = require('url');
|
|
|
|
module.exports = {
|
|
/**
|
|
* Super paranoid shell quote/escape and validation. Input must be base62.
|
|
* @param {string} str
|
|
*/
|
|
base62EscapeAndValidate: (str) => {
|
|
const candidate = str.toString();
|
|
if (candidate.match(/^[A-Za-z0-9_]*$/)) return candidate;
|
|
throw new Error(`
|
|
Could not invoke command:
|
|
input contained unsafe characters.
|
|
`);
|
|
},
|
|
/**
|
|
* Return a quoted string suitable for using in shell commands.
|
|
* @param {string} str
|
|
* @returns {string}
|
|
*/
|
|
urlValidate: (str) => {
|
|
try {
|
|
const url = new URL(str);
|
|
return `${url.protocol}//${url.host}`;
|
|
} catch (e) {
|
|
// Parse error
|
|
throw new Error(`URL ${str} could not be validated.`);
|
|
}
|
|
},
|
|
};
|