Skip to content

feat: add deploy-cli support for Rate Limit Policies (EA)#1395

Open
ankita10119 wants to merge 7 commits into
masterfrom
DXCDT-1674
Open

feat: add deploy-cli support for Rate Limit Policies (EA)#1395
ankita10119 wants to merge 7 commits into
masterfrom
DXCDT-1674

Conversation

@ankita10119

Copy link
Copy Markdown
Contributor

🔧 Changes

Adds deploy-cli support for Rate Limit Policies (EA) - enabling config-as-code management of /api/v2/rate-limit-policies.

Rate limit policies allow tenants to control the number of Authentication API (/oauth/token) requests that client applications can make, with support for block, log, allow, and redirect actions.

New handler: src/tools/auth0/handlers/rateLimitPolicies.ts

  • Full CRUD: list (checkpoint pagination), create, update (PATCH sends configuration only), delete
  • Graceful 403/404/501 handling for tenants without the feature enabled
  • Identified by consumer_selector for config-as-code matching

Directory context: src/context/directory/handlers/rateLimitPolicies.ts

  • Reads/writes policies as individual JSON files under rate-limit-policies/
  • Filename derived from consumer_selector
  • Strips id, created_at, updated_at on export

YAML context: src/context/yaml/handlers/rateLimitPolicies.ts

  • Reads/writes policies inline in the YAML config
  • Strips id, created_at, updated_at on export

📚 References

🔬 Testing

Unit tests added for all three layers:

  • test/tools/auth0/handlers/rateLimitPolicies.test.ts - create, update, delete, 403 handling, skip-delete
  • test/context/directory/rateLimitPolicies.test.ts - parse, dump, empty dir, missing dir
  • test/context/yaml/rateLimitPolicies.test.ts - parse, dump

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@ankita10119 ankita10119 requested a review from a team as a code owner May 29, 2026 07:14
@codecov-commenter

codecov-commenter commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.40741% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.37%. Comparing base (e25b8d2) to head (07200ab).

Files with missing lines Patch % Lines
src/tools/auth0/handlers/rateLimitPolicies.ts 74.24% 7 Missing and 10 partials ⚠️
...rc/context/directory/handlers/rateLimitPolicies.ts 96.00% 0 Missing and 1 partial ⚠️
src/context/yaml/handlers/rateLimitPolicies.ts 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1395      +/-   ##
==========================================
+ Coverage   80.34%   80.37%   +0.03%     
==========================================
  Files         156      159       +3     
  Lines        7225     7333     +108     
  Branches     1595     1616      +21     
==========================================
+ Hits         5805     5894      +89     
- Misses        762      769       +7     
- Partials      658      670      +12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ankita10119 ankita10119 marked this pull request as draft June 1, 2026 08:09
@ankita10119 ankita10119 marked this pull request as ready for review July 1, 2026 08:45
Comment on lines +42 to +54
fs.ensureDirSync(rateLimitPoliciesDirectory);

const removeKeysFromOutput = ['id', 'created_at', 'updated_at'];

rateLimitPolicies.forEach((policy) => {
const policyToWrite = { ...policy };
removeKeysFromOutput.forEach((key) => {
delete policyToWrite[key];
});

const fileName = sanitize(policy.consumer_selector);
const filePath = path.join(rateLimitPoliciesDirectory, `${fileName}.json`);
dumpJSON(filePath, policyToWrite);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a rate limit policy is deleted from the tenant, its .json file remains in rate-limit-policies/ after the next export. On the following deploy, that orphaned file causes the deleted policy to be re-created. connections.ts (lines 134–142) tracks expected filenames and call fs.removeSync() on any files not in that set. This handler needs the same pattern.
We had fixed this for connections here PR #1389

changes.map(async (change) => {
switch (true) {
case change.del && change.del.length > 0:
await this.deleteRateLimitPolicies(change.del || []);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change.del || [] seems like dead code since case already proved change.del is non-empty

await this.createRateLimitPolicies(change.create);
break;
case change.update && change.update.length > 0:
if (change.update) await this.updateRateLimitPolicies(change.update);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as change.del above (case satisfied only if change.update is truthy)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants