mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 16:55:59 +03:00
[PR #4095] [MERGED] feat(cli): access team workspace collections and environments #4663
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#4663
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/4095
Author: @jamesgeorge007
Created: 5/30/2024
Status: ✅ Merged
Merged: 6/27/2024
Merged by: @jamesgeorge007
Base:
next← Head:feat/cli-access-team-workspaces📝 Commits (10+)
25c704afeat: access team workspace collections and environments from the CLI56a2c51test: add unit tests1a5295atest: e2e & unit test suite updates2f452a7fix: ensure custom error codes take precedence0af39d3chore: add JSDoc commentsa34456bchore: fix spelling36eb964refactor: add handler for non-axios errors2f64f75fix: prevent server URL from being displayed asundefinedwith the error message4824a6brefactor: eliminate redundancyde64e58refactor: updategetResourceContentshelper function signature📊 Changes
48 files changed (+17364 additions, -13197 deletions)
View changed files
➖
packages/hoppscotch-cli/jest.config.ts(+0 -193)➖
packages/hoppscotch-cli/jest.setup.ts(+0 -1)📝
packages/hoppscotch-cli/package.json(+3 -5)➕
packages/hoppscotch-cli/setupFiles.ts(+15 -0)➖
packages/hoppscotch-cli/src/__tests__/commands/test.spec.ts(+0 -345)➕
packages/hoppscotch-cli/src/__tests__/e2e/commands/test.spec.ts(+509 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/coll-v1-req-v0.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/coll-v1-req-v1.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/coll-v2-req-v2.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/coll-v2-req-v3.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/collection-level-auth-headers-coll.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/env-flag-tests-coll.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/fails-coll.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/malformed-coll-2.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/malformed-coll.json(+0 -0)➕
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/multiple-child-collections-auth-headers-coll.json(+655 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/notjson-coll.txt(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/passes-coll.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/pre-req-script-env-var-persistence-coll.json(+0 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/req-body-env-vars-coll.json(+0 -0)...and 28 more files
📄 Description
Description
This PR aims at bringing support for accessing collections and environments within team workspaces (support for personal workspace will be brought down the line) from the CLI by supplying their respective IDs. The following updates are made to the
testcommand:The
testcommand and the-e, --envflag now support specifying an ID in addition to the file path.A new
--tokenflag is added that takes in a personal access token for authorized access to the above resources.By default, the data is fetched from the Hoppscotch cloud instance. Alternatively, an SH instance can be specified using the new
--serverflag.Error codes
There are various scenarios where a workspace access attempt can fail under which the following error codes will be displayed in the CLI:
TOKEN_EXPIRED- The supplied access token<access-token>via the--tokenflag has expired.TOKEN_INVALID- The specified access token<access-token>via the--tokenflag is invalid or might have been deleted.INVALID_ID- The user can supply a file path or ID for a collection (file path argument for thetestcommand) / environment (-e, --env,flag for thetestcommand). If the ID was provided and the above error corresponds to the case in which an invalid ID is supplied or the resource is inaccessible to the user, being from a team that the user isn't part of. In the case of a file path, the above error corresponds to a case in which the supplied file path doesn't exist. We're clubbing both cases since there isn't a way to distinguish between b/w IDs and non-existent file paths if the network call aimed at workspace access fails.INVALID_SERVER_URLThere are multiple cases in which this error can happen:
/v1/access-tokens/{collection/environment}/{path/id}with the network call resulting in a404.application/json, safeguarding against the case where the network call doesn't fail where the route is not valid as above and checking against the content type. For instance, supplying the FE instance URL.ERR_INVALID_URLas the error code from the network call). For instance, missing a protocol (e.g.,http://orhttps://), having an invalid structure, or containing illegal characters.ENOTFOUNDas the error code from the network call). For instance, a typo in the domain name.SERVER_CONNECTION_REFUSED- Found the server, but the server refused to connect (receivedECONNREFUSEDas the error code from the network call).Changes
testcommand.getResourceContents()helper function under ~/utils/getters.ts. It checks for the existence of a file path corresponding to the supplied value and proceeds with the network call if it isn't the case.HoppCollection/HoppEnvironmentformats, and requires transformation before further processing. New helper functionstransformWorkspaceCollection()&transformWorkspaceEnvironment()are added under ~/utils/workspace-access.ts.readJsonFilehelper function under ~/utils/mutators.ts to include an additional parameterfileExistsInPathused to throw an error if the file doesn't exist in path. A check for the same that existed previously is removed in favor of the same performed at an earlier point (proceed with the network call if there isn't a valid file path corresponding to the supplied path/ID).e2etests moved under__tests__/e2eand unit tests under__tests__/unitwith the respective test data maintained underfixturesfor both directories. The pre-existing unit tests under__tests__/functionsare to be revisited separately (Tracked in HFE-326) and moved under__tests__/unit.Closes HFE-502 HFE-503.
Steps to verify (SH)
Spin up the
selfhost-webdev server and the BE container locally.Obtain a new personal access token to access the workspace resources. It can be done via the UI if checking out to #4094. Alternatively, send a post request to the
http://<localhost_server_url>/v1/access-tokens/createendpoint with the following body:Choose a collection to run via the CLI or create one if none exists.
#4141 brings about the support for obtaining the collection/environment ID straightaway from the UI. The CLI command to run a particular collection can be obtained if checking out to the above branch or following the steps below. Grab the collection ID (match the name against the
titlefield from the response within thedata.rootCollectionsOfTeamfield and pick the correspondingidfield value) of interest from theRootCollectionsOfTeamGQL query.Navigate to the
hoppscotch-clipackage path locally and runpnpm build. Run the collection via:Similarly, if running a collection that requires an environment, grab the environment ID (match the name against the
namefield from the response within thedata.team.teamEnvironmentsfield and pick the correspondingidfield value) from theGetTeamEnvironmentsGQL query.Run the collection supplying the environment ID:
Both file path and ID can be supplied while specifying an access token. Try out different combinations and the different error scenarios mentioned above.
Checks
Note to reviewers
E2e additions for the workspace access behavior (tests including the usage of
--token&--serverflags) are skipped for now. It'll be enabled once a proper e2e test environment is set up locally. Unit tests are in place for the new functionality added.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.