Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_add(name, method, options, realm) {
Hoek.assert(typeof method === 'function', 'method must be a function');
Hoek.assert(typeof name === 'string', 'name must be a string');
Hoek.assert(name.match(internals.methodNameRx), 'Invalid name:', name);
Hoek.assert(!Hoek.reach(this.methods, name, { functions: false }), 'Server method function name already exists:', name);
options = Config.apply('method', options, name);
const settings = Hoek.clone(options, { shallow: ['bind'] });
settings.generateKey = settings.generateKey || internals.generateKey;
const bind = settings.bind || realm.settings.bind || null;
const bound = !bind ? method : (...args) => method.apply(bind, args);
// Not cached
if (!settings.cache) {
return this._assign(name, bound);
}
// Cached
Hoek.assert(!settings.cache.generateFunc, 'Cannot set generateFunc with method caching:', name);
Hoek.assert(settings.cache.generateTimeout !== undefined, 'Method caching requires a timeout value in generateTimeout:', name);
default(options) {
Hoek.assert(!this.settings.default, 'Cannot set default strategy more than once');
options = Config.apply('auth', options, 'default strategy');
this.settings.default = this._setupRoute(Hoek.clone(options)); // Prevent changes to options
const routes = this._core.router.table();
for (const route of routes) {
route.rebuild();
}
}
const proxyHandler = async (request, h) => {
const options = {};
options.headers = Hoek.clone(request.headers);
delete options.headers.host;
const res = await Wreck.request(request.method, 'http://localhost:' + upstream.info.port + '/headers', options);
return h.response(res).code(res.statusCode);
};
server.auth.strategy('custom_1', 'bell', {
password: 'cookie_encryption_password_secure',
isSecure: false,
clientId: 'test',
clientSecret: 'secret',
provider: Hoek.merge(Hoek.clone(mock.provider), { name: 'custom_1' }),
cookie: 'ring_1'
});
server.auth.strategy('custom_2', 'bell', {
password: 'cookie_encryption_password_secure',
isSecure: false,
clientId: 'test',
clientSecret: 'secret',
provider: Hoek.merge(Hoek.clone(mock.provider), { name: 'custom_2' }),
cookie: 'ring_2'
});
server.route({
method: '*',
path: '/login_1',
options: {
auth: 'custom_1',
handler: function (request, h) {
return request.auth.credentials;
}
}
});
server.route({
async register(plugins, options = {}) {
if (this.realm.modifiers.route.prefix ||
this.realm.modifiers.route.vhost) {
options = Hoek.clone(options);
options.routes = options.routes || {};
options.routes.prefix = (this.realm.modifiers.route.prefix || '') + (options.routes.prefix || '') || undefined;
options.routes.vhost = this.realm.modifiers.route.vhost || options.routes.vhost;
}
options = Config.apply('register', options);
++this._core.registring;
try {
const items = [].concat(plugins);
for (let item of items) {
/*
{ register, ...attributes }
internals.parsePlugin = function (plugin, relativeTo) {
if (typeof plugin === 'string') {
return internals.requireRelativeTo(plugin, relativeTo);
}
if (typeof plugin.plugin === 'string') {
const pluginObject = Hoek.clone(plugin, { shallow: ['options'] });
pluginObject.plugin = internals.requireRelativeTo(plugin.plugin, relativeTo);
return pluginObject;
}
return plugin;
};
server.auth.scheme('udaru', function (server, options) {
Hoek.assert(options, 'Missing service auth strategy options')
if (typeof options.validateFunc === 'undefined' || options.validateFunc === null) options.validateFunc = validate
Hoek.assert(typeof options.validateFunc === 'function', 'options.validateFunc must be a valid function')
const settings = Hoek.clone(options)
const scheme = {
async authenticate (request, h) {
return h.authenticated(await authenticate(server, settings, request))
},
payload (request, h) {
if (server.udaruAuthorization.needTeamsValidation(request)) return request.server.udaruAuthorization.validateTeamsInPayload(server, request, h)
return h.continue
},
options: {
payload: true
}
}
_clearState(name, options = {}) {
const state = { name };
state.options = Hoek.clone(options);
state.options.ttl = 0;
this._states[name] = state;
}
.query()
.skipUndefined()
.where('name', entity.name)
: Promise.resolve([]);
const [role, equalRoles] = await Promise.all([getRoleById, getEqualRoles]);
if (!role) {
throw NSError.RESOURCE_NOT_FOUND();
}
if (equalRoles.length > 0 && equalRoles[0].id !== id) {
throw NSError.RESOURCE_DUPLICATE();
}
Hoek.merge(role, Hoek.clone(entity, { shallow: Repository.Role.model.updateFields }));
return txRoleRepository.update(role);
});
};
register: function (server, options) {
const validateOptions = internals.options.validate(options);
if (validateOptions.error) {
throw validateOptions.error;
}
const settings = Hoek.clone(internals.defaults);
Hoek.merge(settings, options);
if (settings.endpoint[0] !== '/') {
settings.endpoint = `/${settings.endpoint}`;
}
if (settings.endpoint.length > 1 && settings.endpoint[settings.endpoint.length - 1] === '/') {
settings.endpoint = settings.endpoint.slice(0, -1);
}
const cssBaseUrl = `${settings.endpoint === '/' ? '' : settings.endpoint}/css`;
server.dependency(['inert', 'vision'], () => {
server.views({
engines: settings.engines || {