ip-list2.js 853 Bytes
'use strict';

const cache = global.yoho.cache.master;
const config = global.yoho.config;
const logger = global.yoho.logger;

const limitKey = 'limit2';

module.exports = (limiter, policy) => {
    const ipBlackKey = `pc:limiter:${limiter.remoteIp}`; // ci ip黑名单
    const ipLimitKey = `${config.app}:${limitKey}:${limiter.remoteIp}`; // 业务黑名单

    return Promise.all([
        cache.getAsync(ipBlackKey),
        cache.getAsync(ipLimitKey)
    ]).then(result => {
        let ipBlackRes = result[0];
        let ipLimitRes = result[1];

        logger.debug(ipBlackKey, ipBlackRes);
        logger.debug(ipLimitKey, ipLimitRes);

        if ((ipBlackRes && +ipBlackRes > 0) || (ipLimitRes && +ipLimitRes > 0)) {
            return Promise.resolve(policy);
        } else {
            return Promise.resolve(true);
        }
    });
};