ip-list.js 821 Bytes
'use strict';

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

module.exports = (limiter, policy) => {
    const ipBlackKey = `pc:limiter:${limiter.remoteIp}`; // ci ip黑名单
    const ipLimitKey = `${config.app}:limiter:${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);
        }
    });
};