|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +import { BROWSER_TYPE } from './common/constants'; |
| 8 | +// @ts-ignore untyped module |
| 9 | +import { config as appConfig } from './server/config/config'; |
| 10 | +import { getDefaultChromiumSandboxDisabled } from './server/browsers'; |
| 11 | + |
| 12 | +export async function config(Joi: any) { |
| 13 | + return Joi.object({ |
| 14 | + enabled: Joi.boolean().default(true), |
| 15 | + kibanaServer: Joi.object({ |
| 16 | + protocol: Joi.string().valid(['http', 'https']), |
| 17 | + hostname: Joi.string(), |
| 18 | + port: Joi.number().integer(), |
| 19 | + }).default(), |
| 20 | + queue: Joi.object({ |
| 21 | + indexInterval: Joi.string().default('week'), |
| 22 | + pollEnabled: Joi.boolean().default(true), |
| 23 | + pollInterval: Joi.number() |
| 24 | + .integer() |
| 25 | + .default(3000), |
| 26 | + pollIntervalErrorMultiplier: Joi.number() |
| 27 | + .integer() |
| 28 | + .default(10), |
| 29 | + timeout: Joi.number() |
| 30 | + .integer() |
| 31 | + .default(120000), |
| 32 | + }).default(), |
| 33 | + capture: Joi.object({ |
| 34 | + networkPolicy: Joi.object({ |
| 35 | + enabled: Joi.boolean().default(true), |
| 36 | + rules: Joi.array() |
| 37 | + .items( |
| 38 | + Joi.object({ |
| 39 | + allow: Joi.boolean().required(), |
| 40 | + protocol: Joi.string(), |
| 41 | + host: Joi.string(), |
| 42 | + }) |
| 43 | + ) |
| 44 | + .default([ |
| 45 | + { allow: true, protocol: 'http:' }, |
| 46 | + { allow: true, protocol: 'https:' }, |
| 47 | + { allow: true, protocol: 'ws:' }, |
| 48 | + { allow: true, protocol: 'wss:' }, |
| 49 | + { allow: true, protocol: 'data:' }, |
| 50 | + { allow: false }, // Default action is to deny! |
| 51 | + ]), |
| 52 | + }).default(), |
| 53 | + zoom: Joi.number() |
| 54 | + .integer() |
| 55 | + .default(2), |
| 56 | + viewport: Joi.object({ |
| 57 | + width: Joi.number() |
| 58 | + .integer() |
| 59 | + .default(1950), |
| 60 | + height: Joi.number() |
| 61 | + .integer() |
| 62 | + .default(1200), |
| 63 | + }).default(), |
| 64 | + timeout: Joi.number() |
| 65 | + .integer() |
| 66 | + .default(20000), // deprecated |
| 67 | + loadDelay: Joi.number() |
| 68 | + .integer() |
| 69 | + .default(3000), |
| 70 | + settleTime: Joi.number() |
| 71 | + .integer() |
| 72 | + .default(1000), // deprecated |
| 73 | + concurrency: Joi.number() |
| 74 | + .integer() |
| 75 | + .default(appConfig.concurrency), // deprecated |
| 76 | + browser: Joi.object({ |
| 77 | + type: Joi.any() |
| 78 | + .valid(BROWSER_TYPE) |
| 79 | + .default(BROWSER_TYPE), |
| 80 | + autoDownload: Joi.boolean().when('$dist', { |
| 81 | + is: true, |
| 82 | + then: Joi.default(false), |
| 83 | + otherwise: Joi.default(true), |
| 84 | + }), |
| 85 | + chromium: Joi.object({ |
| 86 | + inspect: Joi.boolean() |
| 87 | + .when('$dev', { |
| 88 | + is: false, |
| 89 | + then: Joi.valid(false), |
| 90 | + else: Joi.default(false), |
| 91 | + }) |
| 92 | + .default(), |
| 93 | + disableSandbox: Joi.boolean().default(await getDefaultChromiumSandboxDisabled()), |
| 94 | + proxy: Joi.object({ |
| 95 | + enabled: Joi.boolean().default(false), |
| 96 | + server: Joi.string() |
| 97 | + .uri({ scheme: ['http', 'https'] }) |
| 98 | + .when('enabled', { |
| 99 | + is: Joi.valid(false), |
| 100 | + then: Joi.valid(null), |
| 101 | + else: Joi.required(), |
| 102 | + }), |
| 103 | + bypass: Joi.array() |
| 104 | + .items(Joi.string().regex(/^[^\s]+$/)) |
| 105 | + .when('enabled', { |
| 106 | + is: Joi.valid(false), |
| 107 | + then: Joi.valid(null), |
| 108 | + else: Joi.default([]), |
| 109 | + }), |
| 110 | + }).default(), |
| 111 | + maxScreenshotDimension: Joi.number() |
| 112 | + .integer() |
| 113 | + .default(1950), |
| 114 | + }).default(), |
| 115 | + }).default(), |
| 116 | + maxAttempts: Joi.number() |
| 117 | + .integer() |
| 118 | + .greater(0) |
| 119 | + .when('$dist', { |
| 120 | + is: true, |
| 121 | + then: Joi.default(3), |
| 122 | + otherwise: Joi.default(1), |
| 123 | + }) |
| 124 | + .default(), |
| 125 | + }).default(), |
| 126 | + csv: Joi.object({ |
| 127 | + checkForFormulas: Joi.boolean().default(true), |
| 128 | + enablePanelActionDownload: Joi.boolean().default(true), |
| 129 | + maxSizeBytes: Joi.number() |
| 130 | + .integer() |
| 131 | + .default(1024 * 1024 * 10), // bytes in a kB * kB in a mB * 10 |
| 132 | + scroll: Joi.object({ |
| 133 | + duration: Joi.string() |
| 134 | + .regex(/^[0-9]+(d|h|m|s|ms|micros|nanos)$/, { name: 'DurationString' }) |
| 135 | + .default('30s'), |
| 136 | + size: Joi.number() |
| 137 | + .integer() |
| 138 | + .default(500), |
| 139 | + }).default(), |
| 140 | + }).default(), |
| 141 | + encryptionKey: Joi.when(Joi.ref('$dist'), { |
| 142 | + is: true, |
| 143 | + then: Joi.string(), |
| 144 | + otherwise: Joi.string().default('a'.repeat(32)), |
| 145 | + }), |
| 146 | + roles: Joi.object({ |
| 147 | + allow: Joi.array() |
| 148 | + .items(Joi.string()) |
| 149 | + .default(['reporting_user']), |
| 150 | + }).default(), |
| 151 | + index: Joi.string().default('.reporting'), |
| 152 | + poll: Joi.object({ |
| 153 | + jobCompletionNotifier: Joi.object({ |
| 154 | + interval: Joi.number() |
| 155 | + .integer() |
| 156 | + .default(10000), |
| 157 | + intervalErrorMultiplier: Joi.number() |
| 158 | + .integer() |
| 159 | + .default(5), |
| 160 | + }).default(), |
| 161 | + jobsRefresh: Joi.object({ |
| 162 | + interval: Joi.number() |
| 163 | + .integer() |
| 164 | + .default(5000), |
| 165 | + intervalErrorMultiplier: Joi.number() |
| 166 | + .integer() |
| 167 | + .default(5), |
| 168 | + }).default(), |
| 169 | + }).default(), |
| 170 | + }).default(); |
| 171 | +} |
0 commit comments