-
Notifications
You must be signed in to change notification settings - Fork 6
feat: update the get keys command to show all keys per type #590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| import { expect } from 'vitest' | ||
| import { dvcTest } from '../../../test-utils' | ||
| import { BASE_URL } from '../../api/common' | ||
|
|
||
| describe('keys get', () => { | ||
| const projectKey = 'test-project' | ||
| const authFlags = [ | ||
| '--client-id', | ||
| 'test-client-id', | ||
| '--client-secret', | ||
| 'test-client-secret', | ||
| ] | ||
|
|
||
| const serverKeys = [ | ||
| { | ||
| key: 'dvc_server_old', | ||
| createdAt: '2024-01-01T12:00:00.000Z', | ||
| compromised: false, | ||
| }, | ||
| { | ||
| key: 'dvc_server_new', | ||
| createdAt: '2025-01-01T12:00:00.000Z', | ||
| compromised: false, | ||
| }, | ||
| ] | ||
| const environment = ( | ||
| sdkKeys: Partial<Record<'mobile' | 'client' | 'server', unknown[]>>, | ||
| ) => ({ | ||
| key: 'production', | ||
| name: 'Production', | ||
| _id: '61450f3daec96f5cf4a49961', | ||
| sdkKeys: { mobile: [], client: [], server: [], ...sdkKeys }, | ||
| }) | ||
|
|
||
| const nockEnvironment = (sdkKeys: Record<string, unknown[]>) => | ||
| dvcTest().nock(BASE_URL, (api) => | ||
| api | ||
| .get(`/v1/projects/${projectKey}/environments/production`) | ||
| .reply(200, environment(sdkKeys)), | ||
| ) | ||
|
|
||
| nockEnvironment({ server: serverKeys }) | ||
| .stdout() | ||
| .command([ | ||
| 'keys get', | ||
| '--project', | ||
| projectKey, | ||
| '--env', | ||
| 'production', | ||
| '--type', | ||
| 'server', | ||
| '--headless', | ||
| ...authFlags, | ||
| ]) | ||
| .it('prints every key, most recent first', (ctx) => { | ||
| expect(ctx.stdout.trim().split('\n')).to.eql([ | ||
| 'dvc_server_new', | ||
| 'dvc_server_old', | ||
| ]) | ||
| }) | ||
|
|
||
| nockEnvironment({ server: serverKeys }) | ||
| .stdout() | ||
| .command([ | ||
| 'keys get', | ||
| '--project', | ||
| projectKey, | ||
| '--env', | ||
| 'production', | ||
| '--type', | ||
| 'all', | ||
| '--headless', | ||
| ...authFlags, | ||
| ]) | ||
| .it('supports --type all', (ctx) => { | ||
| expect(JSON.parse(ctx.stdout)).to.eql({ | ||
| mobile: [], | ||
| client: [], | ||
| server: serverKeys, | ||
| }) | ||
| }) | ||
|
|
||
| nockEnvironment({ | ||
| server: [{ ...serverKeys[0], compromised: true }, serverKeys[1]], | ||
| }) | ||
| .stdout() | ||
| .command([ | ||
| 'keys get', | ||
| '--project', | ||
| projectKey, | ||
| '--env', | ||
| 'production', | ||
| '--type', | ||
| 'server', | ||
| '--headless', | ||
| ...authFlags, | ||
| ]) | ||
| .it('marks compromised keys', (ctx) => { | ||
| expect(ctx.stdout.trim().split('\n')).to.eql([ | ||
| 'dvc_server_new', | ||
| 'dvc_server_old (compromised)', | ||
| ]) | ||
| }) | ||
|
|
||
| nockEnvironment({ | ||
| server: [ | ||
| { key: '', createdAt: serverKeys[0].createdAt, compromised: false }, | ||
| ], | ||
| }) | ||
| .stderr() | ||
| .command([ | ||
| 'keys get', | ||
| '--project', | ||
| projectKey, | ||
| '--env', | ||
| 'production', | ||
| '--type', | ||
| 'server', | ||
| '--headless', | ||
| ...authFlags, | ||
| ]) | ||
| .catch((err) => | ||
| expect(err.message).to.contain( | ||
| 'do not have permission to view server SDK keys', | ||
| ), | ||
| ) | ||
| .it('errors when the key is hidden by permissions') | ||
|
|
||
| nockEnvironment({ server: [] }) | ||
| .stderr() | ||
| .command([ | ||
| 'keys get', | ||
| '--project', | ||
| projectKey, | ||
| '--env', | ||
| 'production', | ||
| '--type', | ||
| 'server', | ||
| '--headless', | ||
| ...authFlags, | ||
| ]) | ||
| .catch((err) => | ||
| expect(err.message).to.contain('No server SDK keys found'), | ||
| ) | ||
| .it('errors when there are no keys of that type') | ||
|
|
||
| dvcTest() | ||
| .stderr() | ||
| .command([ | ||
| 'keys get', | ||
| '--project', | ||
| projectKey, | ||
| '--env', | ||
| 'production', | ||
| '--headless', | ||
| ...authFlags, | ||
| ]) | ||
| .catch((err) => | ||
| expect(err.message).to.contain( | ||
| 'In headless mode, the env and type flags are required', | ||
| ), | ||
| ) | ||
| .it('requires the type flag in headless mode') | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we reversing the order here? if we're inverting the API response would that not confuse people on which is accurate? We don't have a
createdattimestamp anywhere.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still an open question, since the dashboard is being updated to show the latest token on the landing page with the details being shown in another view.