feat: secret variables in environments (#3779)
Co-authored-by: jamesgeorge007 <jamesgeorge998001@gmail.com>
This commit is contained in:
@@ -8,11 +8,71 @@ import {
|
||||
getGlobalVariables,
|
||||
} from "~/newstore/environments"
|
||||
import { TestResult } from "@hoppscotch/js-sandbox"
|
||||
import { getService } from "~/modules/dioc"
|
||||
import { SecretEnvironmentService } from "~/services/secret-environment.service"
|
||||
|
||||
export const getCombinedEnvVariables = () => ({
|
||||
global: cloneDeep(getGlobalVariables()),
|
||||
selected: cloneDeep(getCurrentEnvironment().variables),
|
||||
})
|
||||
const secretEnvironmentService = getService(SecretEnvironmentService)
|
||||
|
||||
const unsecretEnvironments = (
|
||||
global: Environment["variables"],
|
||||
selected: Environment
|
||||
) => {
|
||||
const resolvedGlobalWithSecrets = global.map((globalVar, index) => {
|
||||
const secretVar = secretEnvironmentService.getSecretEnvironmentVariable(
|
||||
"Global",
|
||||
index
|
||||
)
|
||||
if (secretVar) {
|
||||
return {
|
||||
...globalVar,
|
||||
value: secretVar.value,
|
||||
}
|
||||
} else if (!("value" in globalVar) || !globalVar.value) {
|
||||
return {
|
||||
...globalVar,
|
||||
value: "",
|
||||
}
|
||||
}
|
||||
return globalVar
|
||||
})
|
||||
|
||||
const resolvedSelectedWithSecrets = selected.variables.map(
|
||||
(selectedVar, index) => {
|
||||
const secretVar = secretEnvironmentService.getSecretEnvironmentVariable(
|
||||
selected.id,
|
||||
index
|
||||
)
|
||||
if (secretVar) {
|
||||
return {
|
||||
...selectedVar,
|
||||
value: secretVar.value,
|
||||
}
|
||||
} else if (!("value" in selectedVar) || !selectedVar.value) {
|
||||
return {
|
||||
...selectedVar,
|
||||
value: "",
|
||||
}
|
||||
}
|
||||
return selectedVar
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
global: resolvedGlobalWithSecrets,
|
||||
selected: resolvedSelectedWithSecrets,
|
||||
}
|
||||
}
|
||||
|
||||
export const getCombinedEnvVariables = () => {
|
||||
const reformedVars = unsecretEnvironments(
|
||||
getGlobalVariables(),
|
||||
getCurrentEnvironment()
|
||||
)
|
||||
return {
|
||||
global: cloneDeep(reformedVars.global),
|
||||
selected: cloneDeep(reformedVars.selected),
|
||||
}
|
||||
}
|
||||
|
||||
export const getFinalEnvsFromPreRequest = (
|
||||
script: string,
|
||||
|
||||
Reference in New Issue
Block a user