Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async register(config) {
assert(config && config.interfaceName, '[ZookeeperRegistry] register(config) config.interfaceName is required');
assert(config.url, '[ZookeeperRegistry] register(config) config.url is required');
const providerPath = this._buildProviderPath(config);
await this._zkClient.mkdirp(providerPath);
const path = providerPath + '/' + urlencode.encode(config.url);
this._registerMap.set(path, config);
try {
// NOTE: Maybe the path is invalid, so remove it first
if (await this._zkClient.exists(path)) {
await this._remove(path);
}
await this._zkClient.create(path, EMPTY, this.options.ephemeralNode ? CreateMode.EPHEMERAL : CreateMode.PERSISTENT);
} catch (err) {
if (err.name === 'NODE_EXISTS' && err.code === -110) {
return;
}
throw err;
}
}
const generateResetPasswordToken = async (userId) => {
const rawToken = `${userId}_W3GojrLkVLKH9l`
// we are using hashing function as a clean way to generate a random string
const salt = await bcrypt.genSalt(Math.random())
return urlencode.encode(await bcrypt.hash(rawToken, salt))
}
const generateResetPasswordToken = async (userId) => {
const rawToken = `${userId}_W3GojrLkVLKH9l`
// we are using hashing function as a clean way to generate a random string
const salt = await bcrypt.genSalt(SALT_WORK_FACTOR)
return urlencode.encode(await bcrypt.hash(rawToken, salt))
}
const originAddressList = children.map(url => urlencode.decode(url));
const addressList = originAddressList.filter(url => this._isMatch(config, url));
this.logger.info('[ZookeeperRegistry] receive interface:%s:%s@%s address list (%d):\n%s\nvalid providers (%d):\n%s',
config.interfaceName, config.version || '', config.group || '',
originAddressList.length, formatAddrs(originAddressList), addressList.length, formatAddrs(addressList));
this._subscribeMap.set(interfaceName, addressList);
this.emit(interfaceName, addressList);
});
})
.catch(err => { this.emit('error', err); });
const consumerPath = this._buildConsumerPath(config);
const consumerUrl = fmt('%s://%s?uniqueId=%s&version=%s&pid=%s&timeout=%s&appName=%s&serialization=%s&startTime=',
config.protocol || 'bolt', localIp, config.uniqueId || '', '1.0', process.pid, config.timeout, config.appName || '', Date.now());
const path = consumerPath + '/' + urlencode.encode(consumerUrl);
this._zkClient.mkdirp(consumerPath)
.then(() => {
return this._zkClient.create(path, EMPTY, CreateMode.EPHEMERAL);
})
.catch(err => {
this.logger.warn('[ZookeeperRegistry] create consumerPath: %s failed, caused by %s', path, err.message);
});
} else {
const addressList = this._subscribeMap.get(interfaceName);
if (addressList) {
setImmediate(() => { listener(addressList); });
}
}
this.on(interfaceName, listener);
}
async unRegister(config) {
assert(config && config.interfaceName, '[ZookeeperRegistry] unRegister(config) config.interfaceName is required');
assert(config.url, '[ZookeeperRegistry] unRegister(config) config.url is required');
const providerPath = this._buildProviderPath(config);
const path = providerPath + '/' + urlencode.encode(config.url);
this._registerMap.delete(path);
await this._remove(path);
}
return () => {
const request = requestFactory({ proxy: useProxy })
.post(searchUrl)
.type('form')
.field({
do: 'search',
subaction: 'search',
search_start: 0,
full_search: 0,
result_from: 1,
story: encoding ? urlencode.encode(query, encoding) : query
})
.buffer(true)
.charset()
.timeout(timeout)
.set(headers)
return request
}
}
transform: ($el) => urlencode.encode($el.attr('href'))
},
transform: ($el) => urlencode.encode($el.attr('href'))
},