From ba769682d676a6a3e1c93fbb176d7f02f6b4f26e Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 21 May 2018 09:31:36 -0700 Subject: [PATCH] feat: mock plugins with real configs so you no longer need to comment out xpack config in the kibana.dev.yml --- index.js | 39 +++++++---- plugins/apm/index.js | 18 +++++ plugins/constants.js | 1 + plugins/graph/index.js | 16 +++++ plugins/ml/index.js | 12 ++++ plugins/monitoring/index.js | 101 +++++++++++++++++++++++++++ plugins/reporting/index.js | 134 ++++++++++++++++++++++++++++++++++++ plugins/security/index.js | 29 ++++++++ plugins/xpack_main/index.js | 30 ++++++++ 9 files changed, 367 insertions(+), 13 deletions(-) create mode 100644 plugins/apm/index.js create mode 100644 plugins/constants.js create mode 100644 plugins/graph/index.js create mode 100644 plugins/ml/index.js create mode 100644 plugins/monitoring/index.js create mode 100644 plugins/reporting/index.js create mode 100644 plugins/security/index.js create mode 100644 plugins/xpack_main/index.js diff --git a/index.js b/index.js index 54d3f94..bd03b15 100644 --- a/index.js +++ b/index.js @@ -1,17 +1,30 @@ -export default function (kibana) { +import { xpackMain } from "./plugins/xpack_main"; +import { apm } from "./plugins/apm"; +import { graph } from "./plugins/graph"; +import { ml } from "./plugins/ml"; +import { monitoring } from "./plugins/monitoring"; +import { reporting } from "./plugins/reporting"; +import { security } from "./plugins/security"; + +const fakeXpack = kibana => { return new kibana.Plugin({ - require: [], - name: 'xpack_main', - id: 'xpack_main', - configPrefix: 'xpack.xpack_main', - config(Joi) { - return Joi.object({ - enabled: Joi.boolean().default(true), - xpack_api_polling_frequency_millis: Joi.number().default(30000), - }).default(); - }, + name: "fake_xpack", + id: "fake_xpack", init() { - console.log('FAKE X-PACK IN FULL EFFECT! [xpack_main]'); - }, + console.log("FAKE X-PACK IN FULL EFFECT! [xpack_main]"); + } }); +}; + +export default function(kibana) { + return [ + fakeXpack(kibana), + xpackMain(kibana), + apm(kibana), + graph(kibana), + ml(kibana), + monitoring(kibana), + reporting(kibana), + security(kibana) + ]; } diff --git a/plugins/apm/index.js b/plugins/apm/index.js new file mode 100644 index 0000000..aa9fc7a --- /dev/null +++ b/plugins/apm/index.js @@ -0,0 +1,18 @@ +export function apm(kibana) { + return new kibana.Plugin({ + name: 'apm', + id: 'apm', + configPrefix: 'xpack.apm', + config(Joi) { + return Joi.object({ + ui: Joi.object({ + enabled: Joi.boolean().default(true), + }).default(), + enabled: Joi.boolean().default(true), + indexPattern: Joi.string().default('apm*'), + minimumBucketSize: Joi.number().default(15), + bucketTargetCount: Joi.number().default(27), + }).default(); + }, + }); +} diff --git a/plugins/constants.js b/plugins/constants.js new file mode 100644 index 0000000..d261d9d --- /dev/null +++ b/plugins/constants.js @@ -0,0 +1 @@ +export const XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS = 30000; \ No newline at end of file diff --git a/plugins/graph/index.js b/plugins/graph/index.js new file mode 100644 index 0000000..4e381f6 --- /dev/null +++ b/plugins/graph/index.js @@ -0,0 +1,16 @@ +export function graph(kibana) { + return new kibana.Plugin({ + name: 'graph', + id: 'graph', + configPrefix: 'xpack.graph', + config(Joi) { + return Joi.object({ + enabled: Joi.boolean().default(true), + canEditDrillDownUrls: Joi.boolean().default(true), + savePolicy: Joi.string() + .valid(['config', 'configAndDataWithConsent', 'configAndData', 'none']) + .default('configAndData'), + }).default(); + }, + }); +} diff --git a/plugins/ml/index.js b/plugins/ml/index.js new file mode 100644 index 0000000..a94a708 --- /dev/null +++ b/plugins/ml/index.js @@ -0,0 +1,12 @@ +export function ml(kibana) { + return new kibana.Plugin({ + name: 'ml', + id: 'ml', + configPrefix: 'xpack.ml', + config(Joi) { + return Joi.object({ + enabled: Joi.boolean().default(true), + }).default(); + }, + }); +} diff --git a/plugins/monitoring/index.js b/plugins/monitoring/index.js new file mode 100644 index 0000000..23ff941 --- /dev/null +++ b/plugins/monitoring/index.js @@ -0,0 +1,101 @@ +import { + XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS, +} from "../constants"; + +export function monitoring(kibana) { + return new kibana.Plugin({ + name: "monitoring", + id: "monitoring", + configPrefix: "xpack.monitoring", + config(Joi) { + const { array, boolean, number, object, string } = Joi; + const DEFAULT_REQUEST_HEADERS = ["authorization"]; + + return object({ + ccs: object({ + enabled: boolean().default(true) + }).default(), + enabled: boolean().default(true), + ui: object({ + enabled: boolean().default(true), + container: object({ + elasticsearch: object({ + enabled: boolean().default(false) + }).default(), + logstash: object({ + enabled: boolean().default(false) + }).default() + }).default() + }).default(), + index_pattern: string().default(".monitoring-*-2-*,.monitoring-*-6-*"), + kibana: object({ + index_pattern: string().default( + ".monitoring-kibana-2-*,.monitoring-kibana-6-*" + ), + collection: object({ + enabled: boolean().default(true), + interval: number().default(10000) // op status metrics get buffered at `ops.interval` and flushed to the bulk endpoint at this interval + }).default() + }).default(), + logstash: object({ + index_pattern: string().default( + ".monitoring-logstash-2-*,.monitoring-logstash-6-*" + ) + }).default(), + beats: object({ + index_pattern: string().default(".monitoring-beats-6-*") + }).default(), + cluster_alerts: object({ + enabled: boolean().default(true), + index: string().default(".monitoring-alerts-6"), + email_notifications: object({ + enabled: boolean().default(true) + }).default() + }).default(), + xpack_api_polling_frequency_millis: number().default( + XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS + ), + max_bucket_size: number().default(10000), + min_interval_seconds: number().default(10), + show_license_expiration: boolean().default(true), + report_stats: boolean().default(true), + node_resolver: string() + .valid("uuid") + .default("uuid"), // deprecated in 5.6; we can make them set it properly before we remove it + agent: object({ + interval: string() + .regex(/[\d\.]+[yMwdhms]/) + .default("10s") + }).default(), + elasticsearch: object({ + customHeaders: object().default({}), + index_pattern: string().default( + ".monitoring-es-2-*,.monitoring-es-6-*" + ), + logQueries: boolean().default(false), + requestHeadersWhitelist: array() + .items() + .single() + .default(DEFAULT_REQUEST_HEADERS), + url: string().uri({ scheme: ["http", "https"] }), // if empty, use Kibana's connection config + username: string(), + password: string(), + requestTimeout: number().default(30000), + pingTimeout: number().default(30000), + ssl: object({ + verificationMode: string() + .valid("none", "certificate", "full") + .default("full"), + certificateAuthorities: array() + .single() + .items(string()), + certificate: string(), + key: string(), + keyPassphrase: string() + }).default(), + apiVersion: string().default("master") + }).default() + }).default(); + } + }); +} diff --git a/plugins/reporting/index.js b/plugins/reporting/index.js new file mode 100644 index 0000000..b5f5862 --- /dev/null +++ b/plugins/reporting/index.js @@ -0,0 +1,134 @@ +const appConfig = { concurrency: 4 }; +const getDefaultBrowser = async () => 'phantom'; +const getDefaultChromiumSandboxDisabled = async () => true; + +export function reporting(kibana) { + return new kibana.Plugin({ + name: "reporting", + id: "reporting", + configPrefix: "xpack.reporting", + async config(Joi) { + return Joi.object({ + enabled: Joi.boolean().default(true), + kibanaServer: Joi.object({ + protocol: Joi.string().valid(["http", "https"]), + hostname: Joi.string(), + port: Joi.number().integer() + }).default(), + queue: Joi.object({ + indexInterval: Joi.string().default("week"), + pollInterval: Joi.number() + .integer() + .default(3000), + pollIntervalErrorMultiplier: Joi.number() + .integer() + .default(10), + timeout: Joi.number() + .integer() + .default(30000) + }).default(), + capture: Joi.object({ + record: Joi.boolean().default(false), + zoom: Joi.number() + .integer() + .default(2), + viewport: Joi.object({ + width: Joi.number() + .integer() + .default(1950), + height: Joi.number() + .integer() + .default(1200) + }).default(), + timeout: Joi.number() + .integer() + .default(20000), //deprecated + loadDelay: Joi.number() + .integer() + .default(3000), + settleTime: Joi.number() + .integer() + .default(1000), //deprecated + concurrency: Joi.number() + .integer() + .default(appConfig.concurrency), //deprecated + browser: Joi.object({ + type: Joi.any() + .valid("phantom", "chromium") + .default(await getDefaultBrowser()), + autoDownload: Joi.boolean().when("$dev", { + is: true, + then: Joi.default(true), + otherwise: Joi.default(false) + }), + chromium: Joi.object({ + disableSandbox: Joi.boolean().default( + await getDefaultChromiumSandboxDisabled() + ), + proxy: Joi.object({ + enabled: Joi.boolean().default(false), + server: Joi.string() + .uri({ scheme: ["http", "https"] }) + .when("enabled", { + is: Joi.valid(false), + then: Joi.valid(null), + else: Joi.required() + }), + bypass: Joi.array() + .items(Joi.string().regex(/^[^\s]+$/)) + .when("enabled", { + is: Joi.valid(false), + then: Joi.valid(null), + else: Joi.default([]) + }) + }).default(), + maxScreenshotDimension: Joi.number() + .integer() + .default(1950) + }).default() + }).default() + }).default(), + csv: Joi.object({ + maxSizeBytes: Joi.number() + .integer() + .default(1024 * 1024 * 10), // bytes in a kB * kB in a mB * 10 + scroll: Joi.object({ + duration: Joi.string() + .regex(/^[0-9]+(d|h|m|s|ms|micros|nanos)$/, { + name: "DurationString" + }) + .default("30s"), + size: Joi.number() + .integer() + .default(500) + }).default() + }).default(), + encryptionKey: Joi.string(), + roles: Joi.object({ + allow: Joi.array() + .items(Joi.string()) + .default(["reporting_user"]) + }).default(), + index: Joi.string().default(".reporting"), + poll: Joi.object({ + jobCompletionNotifier: Joi.object({ + interval: Joi.number() + .integer() + .default(10000), + intervalErrorMultiplier: Joi.number() + .integer() + .default(5) + }).default(), + jobsRefresh: Joi.object({ + interval: Joi.number() + .integer() + .default(5000), + intervalErrorMultiplier: Joi.number() + .integer() + .default(5) + }).default() + }).default() + }).default(); + } + }); +} diff --git a/plugins/security/index.js b/plugins/security/index.js new file mode 100644 index 0000000..efc4f45 --- /dev/null +++ b/plugins/security/index.js @@ -0,0 +1,29 @@ +export function security(kibana) { + return new kibana.Plugin({ + name: 'security', + id: 'security', + configPrefix: 'xpack.security', + config(Joi) { + return Joi.object({ + authProviders: Joi.array() + .items(Joi.string()) + .default(['basic']), + enabled: Joi.boolean().default(true), + cookieName: Joi.string().default('sid'), + encryptionKey: Joi.string(), + sessionTimeout: Joi.number() + .allow(null) + .default(null), + secureCookies: Joi.boolean().default(false), + public: Joi.object({ + protocol: Joi.string().valid(['http', 'https']), + hostname: Joi.string().hostname(), + port: Joi.number() + .integer() + .min(0) + .max(65535), + }).default(), + }).default(); + }, + }); +} diff --git a/plugins/xpack_main/index.js b/plugins/xpack_main/index.js new file mode 100644 index 0000000..703698f --- /dev/null +++ b/plugins/xpack_main/index.js @@ -0,0 +1,30 @@ +import { XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS } from "../constants"; + +export function xpackMain(kibana) { + return new kibana.Plugin({ + require: [], + name: "xpack_main", + id: "xpack_main", + configPrefix: "xpack.xpack_main", + config(Joi) { + return Joi.object({ + enabled: Joi.boolean().default(true), + telemetry: Joi.object({ + enabled: Joi.boolean().default(true), + url: Joi.when("$dev", { + is: true, + then: Joi.string().default( + "https://telemetry-staging.elastic.co/xpack/v1/send" + ), + otherwise: Joi.string().default( + "https://telemetry.elastic.co/xpack/v1/send" + ) + }) + }).default(), + xpack_api_polling_frequency_millis: Joi.number().default( + XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS + ) + }).default(); + } + }); +}