allow environment variables in request body. (#1942)

* feat: allow environment variables in request body

* chore(ui): minor ui improvements

* chore(deps): bump

* fix: track env vars changes

* feat: allow environment variables in request body

* refactor: better implementation

Co-authored-by: liyasthomas <liyascthomas@gmail.com>
Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
0xc0Der
2021-11-10 16:22:11 +02:00
committed by GitHub
parent a2f1e37ad2
commit 0ac84b58e3
3 changed files with 15 additions and 4 deletions

View File

@@ -461,7 +461,8 @@ export default defineComponent({
return "choose an environment"
},
getEnvValue(value) {
if (value) return value
if (value) return value.replace(/"/g, "&quot;")
// it does not filter special characters before adding them to HTML.
return "not found"
},
},

View File

@@ -1,6 +1,16 @@
import { Environment } from "~/newstore/environments"
export default function parseTemplateString(
export function parseBodyEnvVariables(
body: string,
env: Environment["variables"]
) {
return body.replace(/<<\w+>>/g, (key) => {
const found = env.find((envVar) => envVar.key === key.replace(/[<>]/g, ""))
return found ? found.value : key
})
}
export function parseTemplateString(
str: string,
variables: Environment["variables"]
) {

View File

@@ -1,7 +1,7 @@
import { combineLatest, Observable } from "rxjs"
import { map } from "rxjs/operators"
import { FormDataKeyValue, HoppRESTRequest } from "../types/HoppRESTRequest"
import parseTemplateString from "../templating"
import { parseTemplateString, parseBodyEnvVariables } from "../templating"
import { Environment, getGlobalVariables } from "~/newstore/environments"
export interface EffectiveHoppRESTRequest extends HoppRESTRequest {
@@ -46,7 +46,7 @@ function getFinalBodyFromRequest(
})
return formData
} else return request.body.body
} else return parseBodyEnvVariables(request.body.body, env.variables)
}
/**