feat: add deploy-cli support for Rate Limit Policies (EA)#1395
feat: add deploy-cli support for Rate Limit Policies (EA)#1395ankita10119 wants to merge 7 commits into
Conversation
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
| 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); |
There was a problem hiding this comment.
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 || []); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
same as change.del above (case satisfied only if change.update is truthy)
🔧 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 forblock,log,allow, andredirectactions.New handler:
src/tools/auth0/handlers/rateLimitPolicies.tsconfigurationonly), deleteconsumer_selectorfor config-as-code matchingDirectory context:
src/context/directory/handlers/rateLimitPolicies.tsrate-limit-policies/consumer_selectorid,created_at,updated_aton exportYAML context:
src/context/yaml/handlers/rateLimitPolicies.tsid,created_at,updated_aton export📚 References
🔬 Testing
Unit tests added for all three layers:
test/tools/auth0/handlers/rateLimitPolicies.test.ts- create, update, delete, 403 handling, skip-deletetest/context/directory/rateLimitPolicies.test.ts- parse, dump, empty dir, missing dirtest/context/yaml/rateLimitPolicies.test.ts- parse, dump📝 Checklist