@@ -366,15 +366,15 @@ TokenAwarePolicy.prototype.getOptions = function () {
366366
367367/**
368368 * Create a new policy that wraps the provided child policy but only "allow" hosts
369- * from the provided while list.
369+ * from the provided list.
370370 * @class
371371 * @classdesc
372372 * A load balancing policy wrapper that ensure that only hosts from a provided
373- * white list will ever be returned.
373+ * allow list will ever be returned.
374374 * <p>
375375 * This policy wraps another load balancing policy and will delegate the choice
376376 * of hosts to the wrapped policy with the exception that only hosts contained
377- * in the white list provided when constructing this policy will ever be
377+ * in the allow list provided when constructing this policy will ever be
378378 * returned. Any host not in the while list will be considered ignored
379379 * and thus will not be connected to.
380380 * <p>
@@ -386,39 +386,36 @@ TokenAwarePolicy.prototype.getOptions = function () {
386386 * data-center then you should use DCAwareRoundRobinPolicy and *not* this policy
387387 * in particular.
388388 * @param {LoadBalancingPolicy } childPolicy the wrapped policy.
389- * @param {Array.<string> } whiteList the white listed hosts address in the format ipAddress:port.
389+ * @param {Array.<string> } allowList The hosts address in the format ipAddress:port.
390390 * Only hosts from this list may get connected
391391 * to (whether they will get connected to or not depends on the child policy).
392392 * @extends LoadBalancingPolicy
393393 * @constructor
394394 */
395- function WhiteListPolicy ( childPolicy , whiteList ) {
395+ function AllowListPolicy ( childPolicy , allowList ) {
396396 if ( ! childPolicy ) {
397397 throw new Error ( "You must specify a child load balancing policy" ) ;
398398 }
399- if ( ! Array . isArray ( whiteList ) ) {
400- throw new Error ( "You must provide the white list of host addresses" ) ;
399+ if ( ! Array . isArray ( allowList ) ) {
400+ throw new Error ( "You must provide the list of allowed host addresses" ) ;
401401 }
402+
402403 this . childPolicy = childPolicy ;
403- const map = { } ;
404- whiteList . forEach ( function ( address ) {
405- map [ address ] = true ;
406- } ) ;
407- this . whiteList = map ;
404+ this . allowList = new Map ( allowList . map ( address => [ address , true ] ) ) ;
408405}
409406
410- util . inherits ( WhiteListPolicy , LoadBalancingPolicy ) ;
407+ util . inherits ( AllowListPolicy , LoadBalancingPolicy ) ;
411408
412- WhiteListPolicy . prototype . init = function ( client , hosts , callback ) {
409+ AllowListPolicy . prototype . init = function ( client , hosts , callback ) {
413410 this . childPolicy . init ( client , hosts , callback ) ;
414411} ;
415412
416413/**
417- * Uses the child policy to return the distance to the host if included in the white list.
414+ * Uses the child policy to return the distance to the host if included in the allow list.
418415 * Any host not in the while list will be considered ignored.
419416 * @param host
420417 */
421- WhiteListPolicy . prototype . getDistance = function ( host ) {
418+ AllowListPolicy . prototype . getDistance = function ( host ) {
422419 if ( ! this . _contains ( host ) ) {
423420 return types . distance . ignored ;
424421 }
@@ -430,14 +427,14 @@ WhiteListPolicy.prototype.getDistance = function (host) {
430427 * @returns {boolean }
431428 * @private
432429 */
433- WhiteListPolicy . prototype . _contains = function ( host ) {
434- return ! ! this . whiteList [ host . address ] ;
430+ AllowListPolicy . prototype . _contains = function ( host ) {
431+ return ! ! this . allowList . get ( host . address ) ;
435432} ;
436433
437434/**
438- * Returns the hosts to use for a new query filtered by the white list.
435+ * Returns the hosts to use for a new query filtered by the allow list.
439436 */
440- WhiteListPolicy . prototype . newQueryPlan = function ( keyspace , info , callback ) {
437+ AllowListPolicy . prototype . newQueryPlan = function ( keyspace , info , callback ) {
441438 const self = this ;
442439 this . childPolicy . newQueryPlan ( keyspace , info , function ( err , iterator ) {
443440 if ( err ) {
@@ -447,7 +444,7 @@ WhiteListPolicy.prototype.newQueryPlan = function (keyspace, info, callback) {
447444 } ) ;
448445} ;
449446
450- WhiteListPolicy . prototype . _filter = function ( childIterator ) {
447+ AllowListPolicy . prototype . _filter = function ( childIterator ) {
451448 const self = this ;
452449 return {
453450 next : function ( ) {
@@ -463,13 +460,31 @@ WhiteListPolicy.prototype._filter = function (childIterator) {
463460/**
464461 * Gets an associative array containing the policy options.
465462 */
466- WhiteListPolicy . prototype . getOptions = function ( ) {
463+ AllowListPolicy . prototype . getOptions = function ( ) {
467464 return new Map ( [
468465 [ 'childPolicy' , this . childPolicy . constructor !== undefined ? this . childPolicy . constructor . name : null ] ,
469- [ 'whitelist ' , Object . keys ( this . whiteList ) ]
466+ [ 'allowList ' , Array . from ( this . allowList . keys ( ) ) ]
470467 ] ) ;
471468} ;
472469
470+ /**
471+ * Creates a new instance of the policy.
472+ * @classdesc
473+ * Exposed for backward-compatibility only, it's recommended that you use {@link AllowListPolicy} instead.
474+ * @param {LoadBalancingPolicy } childPolicy the wrapped policy.
475+ * @param {Array.<string> } allowList The hosts address in the format ipAddress:port.
476+ * Only hosts from this list may get connected to (whether they will get connected to or not depends on the child
477+ * policy).
478+ * @extends AllowListPolicy
479+ * @deprecated Use allow-list instead. It will be removed in future major versions.
480+ * @constructor
481+ */
482+ function WhiteListPolicy ( childPolicy , allowList ) {
483+ AllowListPolicy . call ( this , childPolicy , allowList ) ;
484+ }
485+
486+ util . inherits ( WhiteListPolicy , AllowListPolicy ) ;
487+
473488/**
474489 * A load-balancing policy implementation that attempts to fairly distribute the load based on the amount of in-flight
475490 * request per hosts. The local replicas are initially shuffled and
@@ -856,9 +871,13 @@ function getDataCenters(hosts) {
856871 return new Set ( hosts . values ( ) . map ( h => h . datacenter ) ) ;
857872}
858873
859- exports . DCAwareRoundRobinPolicy = DCAwareRoundRobinPolicy ;
860- exports . DefaultLoadBalancingPolicy = DefaultLoadBalancingPolicy ;
861- exports . LoadBalancingPolicy = LoadBalancingPolicy ;
862- exports . RoundRobinPolicy = RoundRobinPolicy ;
863- exports . TokenAwarePolicy = TokenAwarePolicy ;
864- exports . WhiteListPolicy = WhiteListPolicy ;
874+ module . exports = {
875+ AllowListPolicy,
876+ DCAwareRoundRobinPolicy,
877+ DefaultLoadBalancingPolicy,
878+ LoadBalancingPolicy,
879+ RoundRobinPolicy,
880+ TokenAwarePolicy,
881+ // Deprecated: for backward compatibility only.
882+ WhiteListPolicy
883+ } ;
0 commit comments