Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
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';

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' });
} catch (error) {
this.log('Unable to remove the rate limit entry', error instanceof Error ? error.message : error);
}
}
}
16 changes: 16 additions & 0 deletions packages/contentstack-config/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@ export interface Region {
personalizeUrl: string;
launchHubUrl: string;
}


export interface RateLimitConfig {
getLimit?: {
value: number;
utilize: number;
};
limit?: {
value: number;
utilize: number;
};
bulkLimit?: {
value: number;
utilize: number;
};
}
8 changes: 8 additions & 0 deletions packages/contentstack-config/src/utils/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,11 @@ export async function askEarlyAccessHeaderAlias(): Promise<string> {
validate: inquireRequireFieldValidation,
});
}

export const askOrgID = async (): Promise<string> => {
return cliux.inquire<string>({
type: 'input',
message: 'Provide the organization UID',
name: 'org',
});
};