Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.register = (server, options) => {
const opts = joi.attempt(options, schema, 'Invalid hapi-sentry options:');
let Sentry = opts.client;
// initialize own sentry client if none passed as option
if (opts.client.dsn !== undefined) {
Sentry = require('@sentry/node');
Sentry.init(opts.client);
}
// initialize global scope if set via plugin options
if (opts.scope) {
Sentry.configureScope(scope => {
if (opts.scope.tags) opts.scope.tags.forEach(tag => scope.setTag(tag.name, tag.value));
if (opts.scope.level) scope.setLevel(opts.scope.level);
if (opts.scope.extra) {
Object.keys(opts.scope.extra).forEach(key => scope.setExtra(key, opts.scope.extra[key]));
}
function normalizeHooks (hooks) {
const keys = Object.keys(hooks)
// no hooks provided
if (keys.length === 0) {
return hooks
}
// same hooks for all envs
if (_.every(keys, (k) => _.includes(HOOK_STAGES, k))) {
const v = promisifyHooks(Joi.attempt(hooks, hookSchema))
const res = {}
HOOK_ENVS.forEach((env) => {
res[env] = v
})
return res
}
// regular per env hook specification
if (_.every(keys, (k) => _.includes(HOOK_ENVS, k))) {
const res = Joi.attempt(hooks, envSchema)
keys.forEach((key) => {
res[key] = promisifyHooks(res[key])
})
return res
internals.register = function (server, options) {
options = Joi.attempt(options, internals.optionsSchema);
const fixedLogger = function (pinoOptions, destination) {
const logger = Pino({
base: options.name ? {} : null,
serializers: {
err: internals.errSerializer
},
...pinoOptions
}, destination);
// Hack to not log version - will be standard once v6 releases: https://github.com/pinojs/pino/pull/623
logger[Pino.symbols.endSym] = `}${pinoOptions.crlf ? '\r\n' : '\n'}`;
return logger;
getV4RateLimitFromBody(body) {
const parsedBody = JSON.parse(body)
const b = Joi.attempt(parsedBody, bodySchema)
return {
rateLimit: b.data.rateLimit.limit,
totalUsesRemaining: b.data.rateLimit.remaining,
nextReset: Date.parse(b.data.rateLimit.resetAt) / 1000,
}
}
function verifyPluginOptions (opts) {
return joi.attempt(opts, pluginScheme)
}
module.exports = function redirector(attrs) {
const {
name,
category,
route,
transformPath,
transformQueryParams,
overrideTransformedQueryParams,
} = Joi.attempt(attrs, attrSchema, `Redirector for ${attrs.route.base}`)
return class Redirector extends BaseService {
static get name() {
if (name) {
return name
} else {
return `${camelcase(route.base.replace(/\//g, '_'), {
pascalCase: true,
})}Redirect`
}
}
static get category() {
return category
}
function validateExample(example, index, ServiceClass) {
const result = Joi.attempt(
example,
schema,
`Example for ${ServiceClass.name} at index ${index}`
)
const { pattern, namedParams } = result
if (!pattern && !ServiceClass.route.pattern) {
throw new Error(
`Example for ${ServiceClass.name} at index ${index} does not declare a pattern`
)
}
if (pattern === ServiceClass.route.pattern) {
throw new Error(
`Example for ${ServiceClass.name} at index ${index} declares a redundant pattern which should be removed`
)
register(server, options) {
Hoek.assert(Object.keys(options).length === 0, 'Inert does not support registration options');
const settings = Joi.attempt(Hoek.reach(server.settings.plugins, 'inert') || {}, internals.schema, 'Invalid "inert" server options');
server.expose('_etags', settings.etagsCacheMaxSize > 0 ? new Etag.Cache(settings.etagsCacheMaxSize) : null);
server.decorate('handler', 'file', File.handler);
server.decorate('handler', 'directory', Directory.handler);
server.decorate('toolkit', 'file', internals.fileMethod);
}
};
getV3RateLimitFromHeaders(headers) {
const h = Joi.attempt(headers, headerSchema)
return {
rateLimit: h['x-ratelimit-limit'],
totalUsesRemaining: h['x-ratelimit-remaining'],
nextReset: h['x-ratelimit-reset'],
}
}