Skip to content

Commit 7f3985e

Browse files
committed
add pass-through method
1 parent 64484be commit 7f3985e

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

lib/auth/AuthInfo.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ export type AccountCanonicalInfoResults = {
5252
},
5353
};
5454

55+
export type RateLimitConfig = {
56+
RequestsPerSecond?: { Limit: number };
57+
}
58+
59+
export type AccountRateLimitConfigResults = {
60+
message: {
61+
body: RateLimitConfig,
62+
},
63+
};
64+
5565
/**
5666
* Class containing requester's information received from Vault
5767
* @param {object} info from Vault including arn, canonicalID,

lib/auth/Vault.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import AuthInfo, {
66
AuthorizationResults,
77
AuthV4Results,
88
AccountCanonicalInfo,
9+
RateLimitConfig,
910
} from './AuthInfo';
1011
import { ArsenalCallback } from '../types';
1112
import RequestContext from '../policyEvaluator/RequestContext';
@@ -409,6 +410,41 @@ export default class Vault {
409410
});
410411
}
411412

413+
/**
414+
* A getter for account canonical IDs given a list of account IDs
415+
* @param canonicalId - account canonicalId
416+
* @param log - log object
417+
* @param callback - callback function
418+
* @returns callback with either error or an object from Vault
419+
* containing the rate limit config for the account
420+
*/
421+
getAccountLimitsByCanonicalId(
422+
canonicalId: string,
423+
log: RequestLogger,
424+
callback: ArsenalCallback<RateLimitConfig | undefined>,
425+
) {
426+
if (typeof this.client.getAccountLimitsByCanonicalIds !== 'function') {
427+
callback(null, undefined);
428+
return;
429+
}
430+
431+
log.trace('getting rate limit config from Vault based on canonicalId');
432+
const options = {
433+
reqUid: log.getSerializedUids(),
434+
logger: log,
435+
};
436+
this.client.getAccountLimitsByCanonicalIds([canonicalId], options, (err, res) => {
437+
if (err) {
438+
log.debug('received error message from vault', {
439+
error: err,
440+
canonicalId,
441+
});
442+
return callback(err);
443+
}
444+
return callback(null, res.message.body[canonicalId]);
445+
});
446+
}
447+
412448
/** checkPolicies -- call Vault to evaluate policies
413449
* @param {object} requestContextParams - parameters needed to construct
414450
* requestContext in Vault

0 commit comments

Comments
 (0)