-
Notifications
You must be signed in to change notification settings - Fork 16
dx | 1201 | get and remove rate limit commands #1543
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
harshithad0703
merged 6 commits into
feat/config-rate-limit
from
feat/dx-1201-get-rate-limit
Sep 4, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b5f33e1
implementation get and remove rate limit commands
harshithad0703 8af316e
resolved the conversations, updated structure of rate limit, removed …
harshithad0703 e99e9f9
removed authentication for remove command
harshithad0703 985ddfa
removed isAuthenticated from import
harshithad0703 cd9ad49
handle delete directly with config handler
harshithad0703 f409fc9
formated get limit, removed message handler
harshithad0703 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
40 changes: 40 additions & 0 deletions
40
packages/contentstack-config/src/commands/config/get/rate-limit.ts
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,40 @@ | ||
| import { cliux, configHandler } from '@contentstack/cli-utilities'; | ||
| import { Command } from '@contentstack/cli-command'; | ||
| import { RateLimitConfig } from '../../../interfaces'; | ||
|
|
||
| export default class RateLimitGetCommand extends Command { | ||
| static description: string = 'Get rate-limit of organizations'; | ||
| static examples = ['$ csdx config:get:rate-limit']; | ||
|
|
||
| async run() { | ||
| try { | ||
| const rateLimit = configHandler.get('rateLimit') || {}; | ||
| const formatLimit = (limit) => (limit ? `${limit.value}(${limit.utilize}%)` : '0'); | ||
| const tableData = Object.entries(rateLimit).map(([org, limits]: [string, RateLimitConfig]) => ({ | ||
| Org: org === 'default' ? 'default' : org, | ||
| 'Get Limit': formatLimit(limits.getLimit), | ||
| Limit: formatLimit(limits.limit), | ||
| 'Bulk Limit': formatLimit(limits.bulkLimit), | ||
| })); | ||
|
|
||
| const columns = { | ||
| Org: { | ||
| minWidth: 10, | ||
| }, | ||
| 'Get Limit': { | ||
| minWidth: 20, | ||
| }, | ||
| Limit: { | ||
| minWidth: 20, | ||
| }, | ||
| 'Bulk Limit': { | ||
| minWidth: 20, | ||
| }, | ||
| }; | ||
|
|
||
| cliux.table(tableData, columns, { printLine: cliux.print }); | ||
| } catch (error) { | ||
| this.log('Unable to retrieve the rate limits configuration', error instanceof Error ? error.message : error); | ||
| } | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
packages/contentstack-config/src/commands/config/remove/rate-limit.ts
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,33 @@ | ||
| import { cliux, configHandler, FlagInput, flags } from '@contentstack/cli-utilities'; | ||
| import { Command } from '@contentstack/cli-command'; | ||
| import { askOrgID } from '../../../utils/interactive'; | ||
|
|
||
| export default class RateLimitRemoveCommand extends Command { | ||
| static description: string = 'Remove rate-limit of the organization'; | ||
|
|
||
harshithad0703 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| static flags: FlagInput = { | ||
| org: flags.string({ | ||
| description: 'Provide the organization UID', | ||
| }), | ||
| }; | ||
| static examples = ['$ csdx config:remove:rate-limit --org <<org_uid>>']; | ||
| async run() { | ||
| try { | ||
| const { flags } = await this.parse(RateLimitRemoveCommand); | ||
| let { org } = flags; | ||
| if (!org) { | ||
| org = await askOrgID(); | ||
| } | ||
| const rateLimit = configHandler.get('rateLimit') || {}; | ||
|
|
||
| if (!rateLimit[org]) { | ||
| cliux.print(`No rate limit found for the organization UID: ${org}`, { color: 'red' }); | ||
| return; | ||
| } | ||
| configHandler.delete(`rateLimit.${org}`); | ||
| cliux.print(`Rate limit entry for organization UID ${org} has been removed.`, { color: 'green' }); | ||
harshithad0703 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } catch (error) { | ||
| this.log('Unable to remove the rate limit entry', error instanceof Error ? error.message : error); | ||
| } | ||
| } | ||
| } | ||
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
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.