-
Notifications
You must be signed in to change notification settings - Fork 3
impr(VLTCLT-68): Add getAccountLimitsByCanonicalIds wrapper for getAccounts #469
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
bert-e
merged 3 commits into
development/8.5
from
improvement/VLTCLT-68/add_getAccountLimitsByCanonicalId
Aug 6, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -348,12 +348,10 @@ class VaultClient { | |
| limits: JSON.stringify(limits), | ||
| }; | ||
| assert(!this.parameterValidation || (limits && typeof limits === 'object'), | ||
| 'Limits must be an object'); | ||
| if (accountName) { | ||
| assert(!this.parameterValidation || typeof accountName === 'string', | ||
| 'the account name, if set, should be a string'); | ||
| data.AccountName = accountName; | ||
| } | ||
| 'limits must be an object'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may be too late here as well, rate limit instead of limits |
||
| assert(!this.parameterValidation || typeof accountName === 'string', | ||
| 'the account name should be a string'); | ||
| data.AccountName = accountName; | ||
| this.request('POST', '/', true, callback, data); | ||
| } | ||
|
|
||
|
|
@@ -370,11 +368,9 @@ class VaultClient { | |
| Version: '2010-05-08', | ||
| }; | ||
|
|
||
| if (accountName) { | ||
| assert(!this.parameterValidation || typeof accountName === 'string', | ||
| 'the account name, if set, should be a string'); | ||
| data.AccountName = accountName; | ||
| } | ||
| assert(!this.parameterValidation || typeof accountName === 'string', | ||
| 'the account name should be a string'); | ||
| data.AccountName = accountName; | ||
| this.request('POST', '/', true, callback, data); | ||
| } | ||
|
|
||
|
|
@@ -391,14 +387,43 @@ class VaultClient { | |
| Version: '2010-05-08', | ||
| }; | ||
|
|
||
| if (accountName) { | ||
| assert(!this.parameterValidation || typeof accountName === 'string', | ||
| 'the account name, if set, should be a string'); | ||
| data.AccountName = accountName; | ||
| } | ||
| assert(!this.parameterValidation || typeof accountName === 'string', | ||
| 'the account name should be a string'); | ||
| data.AccountName = accountName; | ||
| this.request('POST', '/', true, callback, data); | ||
| } | ||
|
|
||
| /** | ||
| * A getter for account rate limit configuration given a list of canonicalIDs | ||
| * @param {String[]} canonicalIds - list of canonicalIDs | ||
| * @param {Object} options - additional arguments | ||
| * @param {string} options.reqUid - the request UID | ||
| * @param {werelogs.RequestLogger} [options.logger] - Logger instance | ||
| * @param {Function} callback - the callback handling the response object | ||
| * and the error, if there is one | ||
| * @returns {undefined} | ||
| */ | ||
| getAccountLimitsByCanonicalIds(canonicalIds, options, callback) { | ||
| this.getAccounts(null, null, canonicalIds, options, (err, res, code) => { | ||
| if (err) { | ||
| return callback(err); | ||
| } | ||
| const body = res.reduce((accounts, account) => { | ||
| // eslint-disable-next-line no-param-reassign | ||
| accounts[account.canId] = account.limits; | ||
| return accounts; | ||
| }, {}); | ||
|
|
||
| return callback(null, { | ||
| message: { | ||
| body, | ||
| code, | ||
| message: 'Attributes retrieved', | ||
| }, | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Get Quota of an account | ||
| * | ||
|
|
||
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 |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| 'use strict'; | ||
|
|
||
| const assert = require('assert'); | ||
| const IAMClient = require('../../lib/IAMClient'); | ||
|
|
||
| const canonicalIds = ['canId1', 'canId2']; | ||
| const opt = { reqUid: 'test.getAccounts.reqUid' }; | ||
| const mockCB = () => {}; | ||
|
|
||
| const expectedData = { | ||
| Action: 'GetAccounts', | ||
| Version: '2010-05-08', | ||
| }; | ||
|
|
||
| describe('getAccountLimitsByCanonicalIds', () => { | ||
| let client; | ||
| let spyArg = null; | ||
|
|
||
| beforeEach('spy on request', done => { | ||
| client = new IAMClient('127.0.0.1', 8500); | ||
| client.request = function spy(...args) { | ||
| spyArg = args; | ||
| }; | ||
| done(); | ||
| }); | ||
|
|
||
| afterEach('reset spyArg', () => { spyArg = null; }); | ||
|
|
||
| it('should send request with correct arguments', () => { | ||
| client.getAccountLimitsByCanonicalIds(canonicalIds, opt, mockCB); | ||
| const [method, path, auth, cb, data, reqUid, contentType] = spyArg; | ||
| assert.strictEqual(method, 'GET'); | ||
| assert.strictEqual(path, '/'); | ||
| assert.strictEqual(auth, false); | ||
| assert.strictEqual(typeof cb, 'function'); | ||
| assert.strictEqual(reqUid, opt.reqUid); | ||
| assert.strictEqual(contentType, null); | ||
| assert.deepStrictEqual( | ||
| data, | ||
| { ...expectedData, canonicalIds }, | ||
| ); | ||
| }); | ||
|
|
||
|
|
||
| it('should throw with invalid arguments', () => { | ||
| assert.throws(() => client.getAccountLimitsByCanonicalIds('foobar', opt, mockCB), | ||
| assert.AssertionError); | ||
| }); | ||
| }); |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be too late for this comment:
Are we gonna support more types of limits other than rate limit.
Limits might confuse the end user/admin, getAccountRateLimitByCanonicalIds might be more descriptive.