@@ -6,6 +6,7 @@ import AuthInfo, {
66 AuthorizationResults ,
77 AuthV4Results ,
88 AccountCanonicalInfo ,
9+ RateLimitConfig ,
910} from './AuthInfo' ;
1011import { ArsenalCallback } from '../types' ;
1112import 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