fix: code refactor and handle secret var in req var
This commit is contained in:
@@ -79,10 +79,7 @@ import { history, historyKeymap } from "@codemirror/commands"
|
|||||||
import { inputTheme } from "~/helpers/editor/themes/baseTheme"
|
import { inputTheme } from "~/helpers/editor/themes/baseTheme"
|
||||||
import { HoppReactiveEnvPlugin } from "~/helpers/editor/extensions/HoppEnvironment"
|
import { HoppReactiveEnvPlugin } from "~/helpers/editor/extensions/HoppEnvironment"
|
||||||
import { useReadonlyStream } from "@composables/stream"
|
import { useReadonlyStream } from "@composables/stream"
|
||||||
import {
|
import { AggregateEnvironment, aggregateEnvs$ } from "~/newstore/environments"
|
||||||
AggregateEnvironment,
|
|
||||||
aggregateEnvsWithSecrets$,
|
|
||||||
} from "~/newstore/environments"
|
|
||||||
import { platform } from "~/platform"
|
import { platform } from "~/platform"
|
||||||
import { onClickOutside, useDebounceFn } from "@vueuse/core"
|
import { onClickOutside, useDebounceFn } from "@vueuse/core"
|
||||||
import { InspectorResult } from "~/services/inspection"
|
import { InspectorResult } from "~/services/inspection"
|
||||||
@@ -356,56 +353,51 @@ watch(
|
|||||||
let clipboardEv: ClipboardEvent | null = null
|
let clipboardEv: ClipboardEvent | null = null
|
||||||
let pastedValue: string | null = null
|
let pastedValue: string | null = null
|
||||||
|
|
||||||
const aggregateEnvs = useReadonlyStream(aggregateEnvsWithSecrets$, []) as Ref<
|
const aggregateEnvs = useReadonlyStream(aggregateEnvs$, []) as Ref<
|
||||||
AggregateEnvironment[]
|
AggregateEnvironment[]
|
||||||
>
|
>
|
||||||
|
|
||||||
const tabs = useService(RESTTabService)
|
const tabs = useService(RESTTabService)
|
||||||
|
|
||||||
const envVars = computed(() => {
|
const envVars = computed(() => {
|
||||||
return props.envs
|
if (props.envs) {
|
||||||
? props.envs.map((x) => {
|
return props.envs.map((x) => {
|
||||||
if (x.secret) {
|
const { key, secret } = x
|
||||||
return {
|
const value = secret ? "********" : x.value
|
||||||
key: x.key,
|
const sourceEnv = "sourceEnv" in x ? x.sourceEnv : null
|
||||||
sourceEnv: "sourceEnv" in x ? x.sourceEnv : null,
|
return {
|
||||||
value: "********",
|
key,
|
||||||
secret: true,
|
value,
|
||||||
}
|
sourceEnv,
|
||||||
}
|
secret,
|
||||||
return {
|
}
|
||||||
key: x.key,
|
})
|
||||||
value: x.value,
|
}
|
||||||
sourceEnv: "sourceEnv" in x ? x.sourceEnv : null,
|
return [
|
||||||
secret: false,
|
...tabs.currentActiveTab.value.document.request.requestVariables.map(
|
||||||
}
|
({ active, key, value }) =>
|
||||||
})
|
active
|
||||||
: [
|
? {
|
||||||
...tabs.currentActiveTab.value.document.request.requestVariables.map(
|
key,
|
||||||
(x) =>
|
value,
|
||||||
x.active
|
sourceEnv: "RequestVariable",
|
||||||
? {
|
secret: false,
|
||||||
key: x.key,
|
}
|
||||||
value: x.value,
|
: ({} as AggregateEnvironment)
|
||||||
sourceEnv: "RequestVariable",
|
),
|
||||||
secret: false,
|
...aggregateEnvs.value,
|
||||||
}
|
]
|
||||||
: ([] as unknown as AggregateEnvironment)
|
|
||||||
),
|
|
||||||
...aggregateEnvs.value,
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function envAutoCompletion(context: CompletionContext) {
|
function envAutoCompletion(context: CompletionContext) {
|
||||||
const options = envVars.value
|
const options = (envVars.value ?? [])
|
||||||
? envVars.value.map((env) => {
|
.map((env) => ({
|
||||||
return {
|
label: env?.key ? `<<${env.key}>>` : "",
|
||||||
label: `<<${env.key}>>`,
|
info: env?.value ?? "",
|
||||||
info: env.value,
|
apply: env?.key ? `<<${env.key}>>` : "",
|
||||||
apply: `<<${env.key}>>`,
|
}))
|
||||||
}
|
.filter((x) => x)
|
||||||
})
|
|
||||||
: []
|
|
||||||
const nodeBefore = syntaxTree(context.state).resolveInner(context.pos, -1)
|
const nodeBefore = syntaxTree(context.state).resolveInner(context.pos, -1)
|
||||||
const textBefore = context.state.sliceDoc(nodeBefore.from, context.pos)
|
const textBefore = context.state.sliceDoc(nodeBefore.from, context.pos)
|
||||||
const tagBefore = /<<\w*$/.exec(textBefore)
|
const tagBefore = /<<\w*$/.exec(textBefore)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { StreamSubscriberFunc } from "@composables/stream"
|
|||||||
import {
|
import {
|
||||||
AggregateEnvironment,
|
AggregateEnvironment,
|
||||||
aggregateEnvsWithSecrets$,
|
aggregateEnvsWithSecrets$,
|
||||||
getAggregateEnvsWithSecrets,
|
getAggregateEnvs,
|
||||||
getCurrentEnvironment,
|
getCurrentEnvironment,
|
||||||
getSelectedEnvironmentType,
|
getSelectedEnvironmentType,
|
||||||
} from "~/newstore/environments"
|
} from "~/newstore/environments"
|
||||||
@@ -100,7 +100,12 @@ const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) =>
|
|||||||
|
|
||||||
const result = parseTemplateStringE(envValue, aggregateEnvs)
|
const result = parseTemplateStringE(envValue, aggregateEnvs)
|
||||||
|
|
||||||
const finalEnv = E.isLeft(result) ? "error" : result.right
|
let finalEnv = E.isLeft(result) ? "error" : result.right
|
||||||
|
|
||||||
|
// If the request variable has an secret variable
|
||||||
|
// parseTemplateStringE is passed the secret value which has value undefined
|
||||||
|
// So, we need to check if the result is undefined and then set the finalEnv to ******
|
||||||
|
if (finalEnv === "undefined") finalEnv = "******"
|
||||||
|
|
||||||
const selectedEnvType = getSelectedEnvironmentType()
|
const selectedEnvType = getSelectedEnvironmentType()
|
||||||
|
|
||||||
@@ -224,7 +229,7 @@ export class HoppEnvironmentPlugin {
|
|||||||
subscribeToStream: StreamSubscriberFunc,
|
subscribeToStream: StreamSubscriberFunc,
|
||||||
private editorView: Ref<EditorView | undefined>
|
private editorView: Ref<EditorView | undefined>
|
||||||
) {
|
) {
|
||||||
const aggregateEnvs = getAggregateEnvsWithSecrets()
|
const aggregateEnvs = getAggregateEnvs()
|
||||||
const currentTab = restTabs.currentActiveTab.value
|
const currentTab = restTabs.currentActiveTab.value
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|||||||
Reference in New Issue
Block a user