mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 16:55:59 +03:00
[PR #3815] [MERGED] feat: support secret environment variables in CLI #4532
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#4532
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/3815
Author: @jamesgeorge007
Created: 2/8/2024
Status: ✅ Merged
Merged: 2/8/2024
Merged by: @AndrewBastin
Base:
release/2023.12.4← Head:feat/cli-env-secrets📝 Commits (2)
19c0a1bfeat: support secret environment variables in CLIc2890c2test: cleanup📊 Changes
30 files changed (+785 additions, -139 deletions)
View changed files
📝
packages/hoppscotch-cli/package.json(+1 -0)📝
packages/hoppscotch-cli/src/__tests__/commands/test.spec.ts(+201 -85)📝
packages/hoppscotch-cli/src/__tests__/samples/collections/collection-level-headers-auth-coll.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/samples/collections/env-flag-tests-coll.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/samples/collections/fails-coll.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/samples/collections/malformed-coll-2.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/samples/collections/malformed-coll.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/samples/collections/notjson-coll.txt(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/samples/collections/passes-coll.json(+0 -0)➕
packages/hoppscotch-cli/src/__tests__/samples/collections/pre-req-script-env-var-persistence-coll.json(+21 -0)📝
packages/hoppscotch-cli/src/__tests__/samples/collections/req-body-env-vars-coll.json(+0 -0)➕
packages/hoppscotch-cli/src/__tests__/samples/collections/secret-envs-coll.json(+107 -0)➕
packages/hoppscotch-cli/src/__tests__/samples/collections/secret-envs-persistence-coll.json(+143 -0)➕
packages/hoppscotch-cli/src/__tests__/samples/collections/secret-envs-persistence-scripting-coll.json(+30 -0)➕
packages/hoppscotch-cli/src/__tests__/samples/environments/bulk-envs.json(+32 -0)📝
packages/hoppscotch-cli/src/__tests__/samples/environments/env-flag-envs.json(+0 -0)➕
packages/hoppscotch-cli/src/__tests__/samples/environments/malformed-envs.json(+16 -0)📝
packages/hoppscotch-cli/src/__tests__/samples/environments/req-body-env-vars-envs.json(+2 -1)➕
packages/hoppscotch-cli/src/__tests__/samples/environments/secret-envs-persistence-scripting-envs.json(+27 -0)➕
packages/hoppscotch-cli/src/__tests__/samples/environments/secret-envs.json(+40 -0)...and 10 more files
📄 Description
Description
Supersedes #3780.
This PR adds support for secret variables in environments for the CLI.
valuefield associated with an environment entry, the corresponding value is fetched from the system environmentprocess.envwith a fallback to an empty string.Other changes
Environmentinstead of maintaining the schema. verzod is added as adevDependency(gets inlined in the bundle) to achieve the same.displayUrlfield is added under theRequestConfiginterface &effectiveFinalDisplayURLfield under theEffectiveHoppRESTRequestinterface. ThegetEffectiveRESTRequestfunction now includes a new property,effectiveFinalDisplayURLundereffectiveRequest, that includes the secret environment variable values masked. Later, while logging the request endpoint,displayUrlis preferred with a fallback tourlensuring the transformed value is logged (secret environment variables referred to in the request endpoint) if existing or else falling back to the regular URL.--e, --env,-d, --delay).collections&environmentsdirectories with a consistent naming convention (collection files ending incoll.json& environment files inenvs.json).Depends on #3779
Closes HFE-221.
Steps to verify
While at the branch, run
pnpm iso thatverzodgets installed under@hoppscotch/cliand the packages are built.Grab the following collection contents under the name
test-secret-envs-coll.json.A secret environment variable is referred to in the request headers, and relevant tests are added to ensure secret environment variables are picked correctly.
Grab the following environment export file contents under
test-secret-envs-coll.json.While at the
@hoppscotch/clipackage path, invoke the CLI supplying secret environment variable entries as key-value pairs along with the above collection and environment files (assuming they are in the same path). Alternately, create a symlink for the CLI and refer to the binary viahoppin any path.Observe all the tests passing ✅
Try omitting the key-value pairs corresponding to the secret environment variables and observe the tests failing, stating the value yield was an empty string. Similarly, try specifying a value for the secret environment variable entry by adding a
valuefield and observe it overrides the one from the system environment. Values set from the scripting context take the highest precedence, observable by setting a value for the same via pre-request script.Please refer to the test suite for more comprehensive samples.
Checks
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.