-
Notifications
You must be signed in to change notification settings - Fork 0
Add support ticket and organization commands #39
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f4e3fc7
Add support ticket and organization commands
lukaskroepfl c065ccb
Use the non-deprecated /support/tickets path
lukaskroepfl dfa6d30
Address review: scope safety, pagination, response validation, and te…
lukaskroepfl 9245a95
Address architecture review: shared tenant scope, one field table, on…
lukaskroepfl 18ec9fb
Address maintainability review: fix abbreviate, restore flag typing, …
lukaskroepfl 97d7a41
Address review: JSON secret masking, honest flags, tighter classifiers
lukaskroepfl a0e5251
Address security review: sanitize at the output boundary
lukaskroepfl 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
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,78 @@ | ||
| import {Flags} from '@oclif/core'; | ||
| import chalk from 'chalk'; | ||
| import {BaseCommand} from '../../../lib/base-command.js'; | ||
| import {loadConfig} from '../../../lib/config.js'; | ||
| import { | ||
| ORGANIZATION_COLUMNS, | ||
| ROOT_ORGANIZATION, | ||
| SUB_ORGANIZATION, | ||
| listOrganizations, | ||
| toOrganizationRows, | ||
| } from '../../../lib/organizations.js'; | ||
|
|
||
| export default class AccountOrganizationsList extends BaseCommand { | ||
| static override description = | ||
| 'List organizations visible to your credentials. Sub-organizations are listed under their parent, with type and parentId shown.'; | ||
|
|
||
| // Deliberately no `tenantOrgFlag`: `/account/organizations` lists what the | ||
| // credential can see and is not scoped by X-Tenant-Org-Id, so `--organization` | ||
| // would be declared and then ignored — and, because the flag rejects an empty | ||
| // value, `--organization "$UNSET_VAR"` would abort a read-only listing over a | ||
| // no-op. Sub-organizations are selected with `--parent` instead. | ||
| static override flags = { | ||
| ...BaseCommand.baseFlags, | ||
| parent: Flags.string({ | ||
| description: 'Show only the sub-organizations of this organization', | ||
| helpValue: '<org-id>', | ||
| exclusive: ['type'], | ||
| }), | ||
| type: Flags.string({ | ||
| description: 'Show only root organizations or only sub-organizations', | ||
| options: ['root', 'sub'], | ||
| }), | ||
| }; | ||
|
|
||
| static override examples = [ | ||
| 'bitmovin account organizations list', | ||
| 'bitmovin account organizations list --type sub', | ||
| 'bitmovin account organizations list --parent 8a7b6c5d-1234-5678-9abc-def012345678', | ||
| 'bitmovin account organizations list --json --jq ".[] | select(.type == \\"SUB_ORGANIZATION\\") | .id"', | ||
| ]; | ||
|
|
||
| async run(): Promise<void> { | ||
| const {flags} = await this.parse(AccountOrganizationsList); | ||
| const config = loadConfig(); | ||
| const scope = await this.requestScope(); | ||
| const orgs = await listOrganizations(scope.apiKey); | ||
| const rows = toOrganizationRows(orgs, config.tenantOrgId); | ||
|
|
||
| let selected = rows; | ||
| if (flags.parent) { | ||
| if (!rows.some((row) => row.id === flags.parent)) { | ||
| this.error( | ||
| `Organization ${flags.parent} is not visible to these credentials.\n` + | ||
| ' Run `bitmovin account organizations list` to see the organizations you can access.', | ||
| {exit: 2}, | ||
| ); | ||
| } | ||
|
|
||
| selected = rows.filter((row) => row.parentId === flags.parent); | ||
| } else if (flags.type) { | ||
| // Filter on the same `type` value the table shows and the --jq example | ||
| // selects on, not on parentId — an org the API types as SUB_ORGANIZATION | ||
| // without a parentId would otherwise be filtered as a root while its own | ||
| // type cell read SUB_ORGANIZATION. | ||
| const wanted = flags.type === 'sub' ? SUB_ORGANIZATION : ROOT_ORGANIZATION; | ||
| selected = rows.filter((row) => row.type === wanted); | ||
| } | ||
|
|
||
| await this.outputList(selected, ORGANIZATION_COLUMNS); | ||
|
|
||
| if (!(await this.isJsonMode()) && !flags.quiet && selected.length > 0) { | ||
| this.log(''); | ||
| this.log(chalk.dim('Set the default organization: bitmovin config set organization <id>')); | ||
| // Named with a command that actually accepts the flag — this one does not. | ||
| this.log(chalk.dim('Target one for a single command: bitmovin support tickets list --organization <id>')); | ||
| } | ||
| } | ||
| } | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.