From 00862eb192f4df30f564d408b48ba9843d48b0c8 Mon Sep 17 00:00:00 2001 From: Nivedin <53208152+nivedin@users.noreply.github.com> Date: Thu, 8 Feb 2024 21:58:42 +0530 Subject: [PATCH] feat: secret variables in environments (#3779) Co-authored-by: jamesgeorge007 --- packages/hoppscotch-common/locales/en.json | 8 + .../src/components/environments/Add.vue | 4 +- .../components/environments/ImportExport.vue | 10 +- .../src/components/environments/Selector.vue | 21 +- .../src/components/environments/index.vue | 28 +- .../components/environments/my/Details.vue | 300 ++++++++++---- .../environments/my/Environment.vue | 5 + .../src/components/environments/my/index.vue | 11 +- .../components/environments/teams/Details.vue | 381 ++++++++++++------ .../environments/teams/Environment.vue | 9 +- .../components/environments/teams/index.vue | 11 +- .../src/components/http/CodegenModal.vue | 2 + .../src/components/http/Headers.vue | 5 +- .../components/http/OAuth2Authorization.vue | 2 +- .../src/components/http/TabHead.vue | 1 - .../src/components/http/TestResult.vue | 11 +- .../src/components/smart/EnvInput.vue | 115 ++++-- .../src/composables/codemirror.ts | 7 + .../src/helpers/RequestRunner.ts | 99 ++++- .../hoppscotch-common/src/helpers/actions.ts | 9 +- .../mutations/CreateTeamEnvironment.graphql | 11 +- .../editor/extensions/HoppEnvironment.ts | 20 +- .../import-export/export/environment.ts | 2 - .../helpers/import-export/import/hoppEnv.ts | 21 +- .../import-export/import/insomniaEnv.ts | 11 +- .../import-export/import/postmanEnv.ts | 5 +- .../src/helpers/preRequest.ts | 68 +++- .../helpers/teams/TeamEnvironmentAdapter.ts | 6 + .../src/helpers/utils/EffectiveURL.ts | 26 +- .../src/newstore/environments.ts | 178 ++++++-- .../secret-environment.service.spec.ts | 194 +++++++++ .../__tests__/environment.inspector.spec.ts | 120 +++++- .../inspectors/environment.inspector.ts | 194 +++++++-- .../inspection/inspectors/header.inspector.ts | 2 +- .../inspectors/response.inspector.ts | 2 +- .../persistence/__tests__/__mocks__/index.ts | 29 +- .../persistence/__tests__/index.spec.ts | 128 +++++- .../src/services/persistence/index.ts | 58 +++ .../persistence/validation-schemas/index.ts | 57 ++- .../services/secret-environment.service.ts | 130 ++++++ .../searchers/environment.searcher.ts | 4 +- .../hoppscotch-data/src/environment/index.ts | 104 ++++- .../hoppscotch-data/src/environment/v/0.ts | 4 +- .../hoppscotch-data/src/environment/v/1.ts | 42 ++ .../src/__tests__/preRequest.spec.ts | 22 +- .../testing/base64-helper-functions.spec.ts | 4 +- .../src/__tests__/testing/envs/get.spec.ts | 5 + .../__tests__/testing/envs/getResolve.spec.ts | 8 + .../__tests__/testing/envs/resolve.spec.ts | 6 + .../src/__tests__/testing/envs/set.spec.ts | 9 + .../src/__tests__/testing/envs/unset.spec.ts | 14 + .../hoppscotch-js-sandbox/src/types/index.ts | 13 +- packages/hoppscotch-js-sandbox/src/utils.ts | 24 +- .../environments/environments.platform.ts | 2 + .../environments/environments.sync.ts | 18 +- 55 files changed, 2141 insertions(+), 439 deletions(-) create mode 100644 packages/hoppscotch-common/src/services/__tests__/secret-environment.service.spec.ts create mode 100644 packages/hoppscotch-common/src/services/secret-environment.service.ts create mode 100644 packages/hoppscotch-data/src/environment/v/1.ts diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json index 301448130..45b5420c8 100644 --- a/packages/hoppscotch-common/locales/en.json +++ b/packages/hoppscotch-common/locales/en.json @@ -24,6 +24,7 @@ "go_back": "Go back", "go_forward": "Go forward", "group_by": "Group by", + "hide_secret": "Hide secret", "label": "Label", "learn_more": "Learn more", "less": "Less", @@ -43,6 +44,7 @@ "search": "Search", "send": "Send", "share": "Share", + "show_secret": "Show secret", "start": "Start", "starting": "Starting", "stop": "Stop", @@ -238,6 +240,7 @@ "profile": "Login to view your profile", "protocols": "Protocols are empty", "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.", "shared_requests": "Shared requests are empty", "shared_requests_logout": "Login to view your shared requests or create a new one", "subscription": "Subscriptions are empty", @@ -269,6 +272,8 @@ "quick_peek": "Environment Quick Peek", "replace_with_variable": "Replace with variable", "scope": "Scope", + "secret": "Secret", + "secret_value": "Secret value", "select": "Select environment", "set": "Set environment", "set_as_environment": "Set as environment", @@ -277,6 +282,7 @@ "updated": "Environment updated", "value": "Value", "variable": "Variable", + "variables":"Variables", "variable_list": "Variable List" }, "error": { @@ -413,6 +419,8 @@ "description": "Inspect possible errors", "environment": { "add_environment": "Add to Environment", + "add_environment_value": "Add value", + "empty_value": "Environment value is empty for the variable '{variable}' ", "not_found": "Environment variable “{environment}” not found." }, "header": { diff --git a/packages/hoppscotch-common/src/components/environments/Add.vue b/packages/hoppscotch-common/src/components/environments/Add.vue index 3d81d1116..3446d2349 100644 --- a/packages/hoppscotch-common/src/components/environments/Add.vue +++ b/packages/hoppscotch-common/src/components/environments/Add.vue @@ -21,7 +21,7 @@ - { addGlobalEnvVariable({ key: editingName.value, value: editingValue.value, + secret: false, }) toast.success(`${t("environment.updated")}`) } else if (scope.value.type === "my-environment") { addEnvironmentVariable(scope.value.index, { key: editingName.value, value: editingValue.value, + secret: false, }) toast.success(`${t("environment.updated")}`) } else { diff --git a/packages/hoppscotch-common/src/components/environments/ImportExport.vue b/packages/hoppscotch-common/src/components/environments/ImportExport.vue index d092aedbd..56c2f3869 100644 --- a/packages/hoppscotch-common/src/components/environments/ImportExport.vue +++ b/packages/hoppscotch-common/src/components/environments/ImportExport.vue @@ -9,7 +9,7 @@ diff --git a/packages/hoppscotch-common/src/components/environments/my/Environment.vue b/packages/hoppscotch-common/src/components/environments/my/Environment.vue index 04a272442..e5f8a80ea 100644 --- a/packages/hoppscotch-common/src/components/environments/my/Environment.vue +++ b/packages/hoppscotch-common/src/components/environments/my/Environment.vue @@ -135,6 +135,8 @@ import { useToast } from "@composables/toast" import { TippyComponent } from "vue-tippy" import { HoppSmartItem } from "@hoppscotch/ui" import { exportAsJSON } from "~/helpers/import-export/export/environment" +import { useService } from "dioc/vue" +import { SecretEnvironmentService } from "~/services/secret-environment.service" const t = useI18n() const toast = useToast() @@ -150,6 +152,8 @@ const emit = defineEmits<{ const confirmRemove = ref(false) +const secretEnvironmentService = useService(SecretEnvironmentService) + const exportEnvironmentAsJSON = () => { const { environment, environmentIndex } = props exportAsJSON(environment, environmentIndex) @@ -168,6 +172,7 @@ const removeEnvironment = () => { if (props.environmentIndex === null) return if (props.environmentIndex !== "Global") { deleteEnvironment(props.environmentIndex, props.environment.id) + secretEnvironmentService.deleteSecretEnvironment(props.environment.id) } toast.success(`${t("state.deleted")}`) } diff --git a/packages/hoppscotch-common/src/components/environments/my/index.vue b/packages/hoppscotch-common/src/components/environments/my/index.vue index f066df1e4..9eaa2f00c 100644 --- a/packages/hoppscotch-common/src/components/environments/my/index.vue +++ b/packages/hoppscotch-common/src/components/environments/my/index.vue @@ -67,6 +67,7 @@ :action="action" :editing-environment-index="editingEnvironmentIndex" :editing-variable-name="editingVariableName" + :is-secret-option-selected="secretOptionSelected" @hide-modal="displayModalEdit(false)" /> ("edit") const editingEnvironmentIndex = ref(null) const editingVariableName = ref("") +const secretOptionSelected = ref(false) const displayModalAdd = (shouldDisplay: boolean) => { action.value = "new" @@ -120,18 +122,23 @@ const editEnvironment = (environmentIndex: number) => { } const resetSelectedData = () => { editingEnvironmentIndex.value = null + editingVariableName.value = "" + secretOptionSelected.value = false } defineActionHandler( "modals.my.environment.edit", - ({ envName, variableName }) => { + ({ envName, variableName, isSecret }) => { if (variableName) editingVariableName.value = variableName const envIndex: number = environments.value.findIndex( (environment: Environment) => { return environment.name === envName } ) - if (envName !== "Global") editEnvironment(envIndex) + if (envName !== "Global") { + editEnvironment(envIndex) + secretOptionSelected.value = isSecret ?? false + } } ) diff --git a/packages/hoppscotch-common/src/components/environments/teams/Details.vue b/packages/hoppscotch-common/src/components/environments/teams/Details.vue index d54d18034..906a7a608 100644 --- a/packages/hoppscotch-common/src/components/environments/teams/Details.vue +++ b/packages/hoppscotch-common/src/components/environments/teams/Details.vue @@ -16,90 +16,112 @@ @submit="saveEnvironment" /> -
- -
- - -
-
-
- {{ t("environment.nested_overflow") }} -
-
+
- - -
- -
+ {{ t("environment.nested_overflow") }}
- - -