fix: secret environment flow bugs (#3817)
This commit is contained in:
@@ -240,7 +240,7 @@
|
|||||||
"profile": "Login to view your profile",
|
"profile": "Login to view your profile",
|
||||||
"protocols": "Protocols are empty",
|
"protocols": "Protocols are empty",
|
||||||
"schema": "Connect to a GraphQL endpoint to view schema",
|
"schema": "Connect to a GraphQL endpoint to view schema",
|
||||||
"secret_environments": "Secret environments are not synced to Hoppscotch hence user has to provide it's value during run-time.",
|
"secret_environments": "Secrets are not synced to Hoppscotch",
|
||||||
"shared_requests": "Shared requests are empty",
|
"shared_requests": "Shared requests are empty",
|
||||||
"shared_requests_logout": "Login to view your shared requests or create a new one",
|
"shared_requests_logout": "Login to view your shared requests or create a new one",
|
||||||
"subscription": "Subscriptions are empty",
|
"subscription": "Subscriptions are empty",
|
||||||
@@ -272,7 +272,7 @@
|
|||||||
"quick_peek": "Environment Quick Peek",
|
"quick_peek": "Environment Quick Peek",
|
||||||
"replace_with_variable": "Replace with variable",
|
"replace_with_variable": "Replace with variable",
|
||||||
"scope": "Scope",
|
"scope": "Scope",
|
||||||
"secret": "Secret",
|
"secrets": "Secrets",
|
||||||
"secret_value": "Secret value",
|
"secret_value": "Secret value",
|
||||||
"select": "Select environment",
|
"select": "Select environment",
|
||||||
"set": "Set environment",
|
"set": "Set environment",
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ const tabsData: ComputedRef<
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "secret",
|
id: "secret",
|
||||||
label: t("environment.secret"),
|
label: t("environment.secrets"),
|
||||||
emptyStateLabel: t("empty.secret_environments"),
|
emptyStateLabel: t("empty.secret_environments"),
|
||||||
isSecret: true,
|
isSecret: true,
|
||||||
variables: secretVars.value,
|
variables: secretVars.value,
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ const tabsData: ComputedRef<
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "secret",
|
id: "secret",
|
||||||
label: t("environment.secret"),
|
label: t("environment.secrets"),
|
||||||
emptyStateLabel: t("empty.secret_environments"),
|
emptyStateLabel: t("empty.secret_environments"),
|
||||||
isSecret: true,
|
isSecret: true,
|
||||||
variables: secretVars.value,
|
variables: secretVars.value,
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) =>
|
|||||||
const envName = tooltipEnv?.sourceEnv ?? "Choose an Environment"
|
const envName = tooltipEnv?.sourceEnv ?? "Choose an Environment"
|
||||||
|
|
||||||
let envValue = "Not Found"
|
let envValue = "Not Found"
|
||||||
|
|
||||||
if (!tooltipEnv?.secret && tooltipEnv?.value) envValue = tooltipEnv.value
|
if (!tooltipEnv?.secret && tooltipEnv?.value) envValue = tooltipEnv.value
|
||||||
else if (tooltipEnv?.secret && tooltipEnv.value) {
|
else if (tooltipEnv?.secret && tooltipEnv.value) {
|
||||||
envValue = "******"
|
envValue = "******"
|
||||||
@@ -92,11 +91,23 @@ const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) =>
|
|||||||
editIcon.className =
|
editIcon.className =
|
||||||
"ml-2 cursor-pointer text-accent hover:text-accentDark"
|
"ml-2 cursor-pointer text-accent hover:text-accentDark"
|
||||||
editIcon.addEventListener("click", () => {
|
editIcon.addEventListener("click", () => {
|
||||||
const isPersonalEnv =
|
let invokeActionType:
|
||||||
envName === "Global" || selectedEnvType !== "TEAM_ENV"
|
| "modals.my.environment.edit"
|
||||||
const action = isPersonalEnv ? "my" : "team"
|
| "modals.team.environment.edit"
|
||||||
invokeAction(`modals.${action}.environment.edit`, {
|
| "modals.global.environment.update" = "modals.my.environment.edit"
|
||||||
envName,
|
|
||||||
|
if (tooltipEnv?.sourceEnv === "Global") {
|
||||||
|
invokeActionType = "modals.global.environment.update"
|
||||||
|
} else if (selectedEnvType === "MY_ENV") {
|
||||||
|
invokeActionType = "modals.my.environment.edit"
|
||||||
|
} else if (selectedEnvType === "TEAM_ENV") {
|
||||||
|
invokeActionType = "modals.team.environment.edit"
|
||||||
|
} else {
|
||||||
|
invokeActionType = "modals.my.environment.edit"
|
||||||
|
}
|
||||||
|
|
||||||
|
invokeAction(invokeActionType, {
|
||||||
|
envName: tooltipEnv?.sourceEnv !== "Global" ? envName : "Global",
|
||||||
variableName: parsedEnvKey,
|
variableName: parsedEnvKey,
|
||||||
isSecret: tooltipEnv?.secret,
|
isSecret: tooltipEnv?.secret,
|
||||||
})
|
})
|
||||||
@@ -185,7 +196,6 @@ export class HoppEnvironmentPlugin {
|
|||||||
|
|
||||||
subscribeToStream(aggregateEnvsWithSecrets$, (envs) => {
|
subscribeToStream(aggregateEnvsWithSecrets$, (envs) => {
|
||||||
this.envs = envs
|
this.envs = envs
|
||||||
|
|
||||||
this.editorView.value?.dispatch({
|
this.editorView.value?.dispatch({
|
||||||
effects: this.compartment.reconfigure([
|
effects: this.compartment.reconfigure([
|
||||||
cursorTooltipField(this.envs),
|
cursorTooltipField(this.envs),
|
||||||
|
|||||||
@@ -367,7 +367,8 @@ export const currentEnvironment$: Observable<Environment | undefined> =
|
|||||||
return environments[selectedEnvironmentIndex.index]
|
return environments[selectedEnvironmentIndex.index]
|
||||||
}
|
}
|
||||||
return selectedEnvironmentIndex.environment
|
return selectedEnvironmentIndex.environment
|
||||||
})
|
}),
|
||||||
|
distinctUntilChanged()
|
||||||
)
|
)
|
||||||
|
|
||||||
export type AggregateEnvironment = {
|
export type AggregateEnvironment = {
|
||||||
@@ -476,7 +477,6 @@ export const aggregateEnvsWithSecrets$: Observable<AggregateEnvironment[]> =
|
|||||||
combineLatest([currentEnvironment$, globalEnv$]).pipe(
|
combineLatest([currentEnvironment$, globalEnv$]).pipe(
|
||||||
map(([selectedEnv, globalVars]) => {
|
map(([selectedEnv, globalVars]) => {
|
||||||
const results: AggregateEnvironment[] = []
|
const results: AggregateEnvironment[] = []
|
||||||
|
|
||||||
selectedEnv?.variables.map((x, index) => {
|
selectedEnv?.variables.map((x, index) => {
|
||||||
let value
|
let value
|
||||||
if (x.secret) {
|
if (x.secret) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
import { invokeAction } from "~/helpers/actions"
|
import { invokeAction } from "~/helpers/actions"
|
||||||
import { computed } from "vue"
|
import { computed } from "vue"
|
||||||
import { useStreamStatic } from "~/composables/stream"
|
import { useStreamStatic } from "~/composables/stream"
|
||||||
|
import { SecretEnvironmentService } from "~/services/secret-environment.service"
|
||||||
|
|
||||||
const HOPP_ENVIRONMENT_REGEX = /(<<[a-zA-Z0-9-_]+>>)/g
|
const HOPP_ENVIRONMENT_REGEX = /(<<[a-zA-Z0-9-_]+>>)/g
|
||||||
|
|
||||||
@@ -39,6 +40,7 @@ export class EnvironmentInspectorService extends Service implements Inspector {
|
|||||||
public readonly inspectorID = "environment"
|
public readonly inspectorID = "environment"
|
||||||
|
|
||||||
private readonly inspection = this.bind(InspectionService)
|
private readonly inspection = this.bind(InspectionService)
|
||||||
|
private readonly secretEnvs = this.bind(SecretEnvironmentService)
|
||||||
|
|
||||||
private aggregateEnvsWithSecrets = useStreamStatic(
|
private aggregateEnvsWithSecrets = useStreamStatic(
|
||||||
aggregateEnvsWithSecrets$,
|
aggregateEnvsWithSecrets$,
|
||||||
@@ -141,10 +143,18 @@ export class EnvironmentInspectorService extends Service implements Inspector {
|
|||||||
if (extractedEnv) {
|
if (extractedEnv) {
|
||||||
extractedEnv.forEach((exEnv: string) => {
|
extractedEnv.forEach((exEnv: string) => {
|
||||||
const formattedExEnv = exEnv.slice(2, -2)
|
const formattedExEnv = exEnv.slice(2, -2)
|
||||||
|
const currentSelectedEnvironment = getCurrentEnvironment()
|
||||||
|
|
||||||
this.aggregateEnvsWithSecrets.value.forEach((env) => {
|
this.aggregateEnvsWithSecrets.value.forEach((env) => {
|
||||||
|
const hasSecretEnv = this.secretEnvs.hasSecretValue(
|
||||||
|
env.sourceEnv !== "Global"
|
||||||
|
? currentSelectedEnvironment.id
|
||||||
|
: "Global",
|
||||||
|
env.key
|
||||||
|
)
|
||||||
|
|
||||||
if (env.key === formattedExEnv) {
|
if (env.key === formattedExEnv) {
|
||||||
if (env.value === "") {
|
if (env.secret ? !hasSecretEnv : env.value === "") {
|
||||||
const itemLocation: InspectorLocation = {
|
const itemLocation: InspectorLocation = {
|
||||||
type: locations.type,
|
type: locations.type,
|
||||||
position:
|
position:
|
||||||
@@ -157,7 +167,6 @@ export class EnvironmentInspectorService extends Service implements Inspector {
|
|||||||
key: element,
|
key: element,
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentSelectedEnvironment = getCurrentEnvironment()
|
|
||||||
const currentEnvironmentType = getSelectedEnvironmentType()
|
const currentEnvironmentType = getSelectedEnvironmentType()
|
||||||
|
|
||||||
let invokeActionType:
|
let invokeActionType:
|
||||||
|
|||||||
@@ -117,6 +117,21 @@ export class SecretEnvironmentService extends Service {
|
|||||||
this.secretEnvironments.delete(oldID)
|
this.secretEnvironments.delete(oldID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param id ID of the environment
|
||||||
|
* @param key Key of the variable to check the value exists
|
||||||
|
* @returns true if the key has a secret value
|
||||||
|
*/
|
||||||
|
public hasSecretValue(id: string, key: string) {
|
||||||
|
return (
|
||||||
|
this.secretEnvironments.has(id) &&
|
||||||
|
this.secretEnvironments
|
||||||
|
.get(id)!
|
||||||
|
.some((secretVar) => secretVar.key === key && secretVar.value !== "")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to update the value of a secret environment variable.
|
* Used to update the value of a secret environment variable.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user