feat: added masking of secrets in cli in url

This commit is contained in:
Daniel Maurer
2023-07-25 11:04:06 +02:00
committed by nivedin
parent 088f1d6b47
commit e0eb8af6f5
11 changed files with 88 additions and 34 deletions

View File

@@ -5,23 +5,46 @@ import { readJsonFile } from "../../utils/mutators";
/**
* Parses env json file for given path and validates the parsed env json object.
* @param path Path of env.json file to be parsed.
* @param envName Name of the environment that should be used. If undefined first environment is used.
* @returns For successful parsing we get HoppEnvs object.
*/
export async function parseEnvsData(path: string) {
export async function parseEnvsData(path: string, envName: string | undefined) {
const contents = await readJsonFile(path)
if(!(contents && typeof contents === "object" && !Array.isArray(contents))) {
if(!(contents && typeof contents === "object" && Array.isArray(contents))) {
throw error({ code: "MALFORMED_ENV_FILE", path, data: null })
}
const envPairs: Array<HoppEnvPair> = []
for( const [key,value] of Object.entries(contents)) {
if(typeof value !== "string") {
throw error({ code: "MALFORMED_ENV_FILE", path, data: {value: value} })
}
const contentEntries = Object.entries(contents)
let environmentFound = false;
envPairs.push({key, value})
for(const [key, obj] of contentEntries) {
if(!(typeof obj === "object" && "name" in obj && "variables" in obj)) {
throw error({ code: "MALFORMED_ENV_FILE", path, data: { value: obj } })
}
if(envName && envName !== obj.name) {
continue
}
environmentFound = true;
for(const variable of obj.variables) {
if(
!(
typeof variable === "object" &&
"key" in variable &&
"value" in variable &&
"secret" in variable
)
) {
throw error({ code: "MALFORMED_ENV_FILE", path, data: { value: variable } });
}
const { key, value, secret } = variable;
envPairs.push({ key: key, value: value, secret: secret });
}
break
}
if(envName && !environmentFound) {
throw error({ code: "ENVIRONMENT_NAME_NOT_FOUND", data: envName });
}
return <HoppEnvs>{ global: [], selected: envPairs }
}