-
Notifications
You must be signed in to change notification settings - Fork 0
[DX-264] Rename channel-rules to apps rules and alias legacy command paths #164
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
4 commits
Select commit
Hold shift + click to select a range
ed96936
Rename channel-rules to apps rules and alias legacy command paths
umair-ably 5f14348
Fix double this.fail() in base command and address PR #164 review fee…
umair-ably 377a61c
address json formatting issue + add deprecation warning for aliases
umair-ably 5e6b612
extend human readable output to include ably error code and error url
umair-ably 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,184 +1,19 @@ | ||
| import { Flags } from "@oclif/core"; | ||
| import { Command } from "@oclif/core"; | ||
|
|
||
| import { ControlBaseCommand } from "../../../control-base-command.js"; | ||
| import { formatChannelRuleDetails } from "../../../utils/channel-rule-display.js"; | ||
| import { | ||
| formatLabel, | ||
| formatSuccess, | ||
| formatWarning, | ||
| } from "../../../utils/output.js"; | ||
| import RulesCreate from "../rules/create.js"; | ||
|
|
||
| export default class ChannelRulesCreateCommand extends ControlBaseCommand { | ||
| static description = "Create a channel rule"; | ||
|
|
||
| static examples = [ | ||
| '$ ably apps channel-rules create --name "chat" --persisted', | ||
| '$ ably apps channel-rules create --name "chat" --mutable-messages', | ||
| '$ ably apps channel-rules create --name "events" --push-enabled', | ||
| '$ ably apps channel-rules create --name "notifications" --persisted --push-enabled --app "My App"', | ||
| '$ ably apps channel-rules create --name "chat" --persisted --json', | ||
| ]; | ||
|
|
||
| static flags = { | ||
| ...ControlBaseCommand.globalFlags, | ||
| app: Flags.string({ | ||
| description: "The app ID or name (defaults to current app)", | ||
| required: false, | ||
| }), | ||
| authenticated: Flags.boolean({ | ||
| description: | ||
| "Whether channels matching this rule require clients to be authenticated", | ||
| required: false, | ||
| }), | ||
| "batching-enabled": Flags.boolean({ | ||
| description: | ||
| "Whether to enable batching for messages on channels matching this rule", | ||
| required: false, | ||
| }), | ||
| "batching-interval": Flags.integer({ | ||
| description: | ||
| "The batching interval for messages on channels matching this rule", | ||
| required: false, | ||
| }), | ||
| "conflation-enabled": Flags.boolean({ | ||
| description: | ||
| "Whether to enable conflation for messages on channels matching this rule", | ||
| required: false, | ||
| }), | ||
| "conflation-interval": Flags.integer({ | ||
| description: | ||
| "The conflation interval for messages on channels matching this rule", | ||
| required: false, | ||
| }), | ||
| "conflation-key": Flags.string({ | ||
| description: | ||
| "The conflation key for messages on channels matching this rule", | ||
| required: false, | ||
| }), | ||
| "expose-time-serial": Flags.boolean({ | ||
| description: | ||
| "Whether to expose the time serial for messages on channels matching this rule", | ||
| required: false, | ||
| }), | ||
| "mutable-messages": Flags.boolean({ | ||
| description: | ||
| "Whether messages on channels matching this rule can be updated or deleted after publishing. Automatically enables message persistence.", | ||
| required: false, | ||
| }), | ||
| name: Flags.string({ | ||
| description: "Name of the channel rule", | ||
| required: true, | ||
| }), | ||
| "persist-last": Flags.boolean({ | ||
| description: | ||
| "Whether to persist only the last message on channels matching this rule", | ||
| required: false, | ||
| }), | ||
| persisted: Flags.boolean({ | ||
| default: false, | ||
| description: | ||
| "Whether messages on channels matching this rule should be persisted", | ||
| required: false, | ||
| }), | ||
| "populate-channel-registry": Flags.boolean({ | ||
| description: | ||
| "Whether to populate the channel registry for channels matching this rule", | ||
| required: false, | ||
| }), | ||
| "push-enabled": Flags.boolean({ | ||
| default: false, | ||
| description: | ||
| "Whether push notifications should be enabled for channels matching this rule", | ||
| required: false, | ||
| }), | ||
| "tls-only": Flags.boolean({ | ||
| description: "Whether to enforce TLS for channels matching this rule", | ||
| required: false, | ||
| }), | ||
| }; | ||
| export default class ChannelRulesCreateCommand extends Command { | ||
| static override args = RulesCreate.args; | ||
| static override description = 'Alias for "ably apps rules create"'; | ||
| static override flags = RulesCreate.flags; | ||
| static override hidden = true; | ||
| static isAlias = true; | ||
|
|
||
| async run(): Promise<void> { | ||
| const { flags } = await this.parse(ChannelRulesCreateCommand); | ||
|
|
||
| const appId = await this.requireAppId(flags); | ||
|
|
||
| try { | ||
| const controlApi = this.createControlApi(flags); | ||
|
|
||
| // When mutableMessages is enabled, persisted must also be enabled | ||
| const mutableMessages = flags["mutable-messages"]; | ||
| let persisted = flags.persisted; | ||
|
|
||
| if (mutableMessages) { | ||
| persisted = true; | ||
| if (!this.shouldOutputJson(flags)) { | ||
| this.logToStderr( | ||
| formatWarning( | ||
| "Message persistence is automatically enabled when mutable messages is enabled.", | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| const namespaceData = { | ||
| authenticated: flags.authenticated, | ||
| batchingEnabled: flags["batching-enabled"], | ||
| batchingInterval: flags["batching-interval"], | ||
| id: flags.name, | ||
| conflationEnabled: flags["conflation-enabled"], | ||
| conflationInterval: flags["conflation-interval"], | ||
| conflationKey: flags["conflation-key"], | ||
| exposeTimeSerial: flags["expose-time-serial"], | ||
| mutableMessages, | ||
| persistLast: flags["persist-last"], | ||
| persisted, | ||
| populateChannelRegistry: flags["populate-channel-registry"], | ||
| pushEnabled: flags["push-enabled"], | ||
| tlsOnly: flags["tls-only"], | ||
| }; | ||
|
|
||
| const createdNamespace = await controlApi.createNamespace( | ||
| appId, | ||
| namespaceData, | ||
| ); | ||
|
|
||
| if (this.shouldOutputJson(flags)) { | ||
| this.logJsonResult( | ||
| { | ||
| appId, | ||
| rule: { | ||
| authenticated: createdNamespace.authenticated, | ||
| batchingEnabled: createdNamespace.batchingEnabled, | ||
| batchingInterval: createdNamespace.batchingInterval, | ||
| conflationEnabled: createdNamespace.conflationEnabled, | ||
| conflationInterval: createdNamespace.conflationInterval, | ||
| conflationKey: createdNamespace.conflationKey, | ||
| created: new Date(createdNamespace.created).toISOString(), | ||
| exposeTimeSerial: createdNamespace.exposeTimeSerial, | ||
| id: createdNamespace.id, | ||
| mutableMessages: createdNamespace.mutableMessages, | ||
| name: flags.name, | ||
| persistLast: createdNamespace.persistLast, | ||
| persisted: createdNamespace.persisted, | ||
| populateChannelRegistry: createdNamespace.populateChannelRegistry, | ||
| pushEnabled: createdNamespace.pushEnabled, | ||
| tlsOnly: createdNamespace.tlsOnly, | ||
| }, | ||
| timestamp: new Date().toISOString(), | ||
| }, | ||
| flags, | ||
| ); | ||
| } else { | ||
| this.log(formatSuccess("Channel rule created.")); | ||
| this.log(`${formatLabel("ID")} ${createdNamespace.id}`); | ||
| for (const line of formatChannelRuleDetails(createdNamespace, { | ||
| formatDate: (t) => this.formatDate(t), | ||
| })) { | ||
| this.log(line); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| this.fail(error, flags, "channelRuleCreate", { appId }); | ||
| } | ||
| this.warn( | ||
| '"apps channel-rules create" is deprecated. Use "apps rules create" instead.', | ||
| ); | ||
| const command = new RulesCreate(this.argv, this.config); | ||
| await command.run(); | ||
| } | ||
| } |
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.