From 2516f93c70a727c90ee889e97099671a3fbe095b Mon Sep 17 00:00:00 2001 From: Matt Apperson Date: Wed, 24 Jul 2019 21:01:56 -0400 Subject: [PATCH] [Ingest] cleanup names and files/paths to confirm to a standard format (#41773) * [Maps] Rename modules for clarity (#41608) * [Docs] Add simple phrase highlighting to Logs UI (#41610) * [Docs] Add simple phrase highlighting to Logs UI * Fix heading level * [DOCS] Timelion cleanup (#41381) * [Canvas] Removes doc links from backticks. (#41601) * Upgrade EUI to 12.4.0 (#41577) * eui 12.4.0 * styled-components ts conflict * update combobox test service to always open on open call * Revert "update combobox test service to always open on open call" This reverts commit 43074e60061afcaf5c87e56ae5782aed2a4b68dc. * scroll combobox into view * scroll before filter * Move CSP config default values to csp module (#41676) This gives us a little more control over the default values of these configurations to help ensure (though not guarantee) that any changes here can be audited by the security team. * Remove notifications plugin (#41674) The notifications functionality has been replaced by the features of the actions plugin. This notifications plugin was never actually used by end-user facing features of Kibana. * [Logs UI] Make column configurations reorderable (#41035) * [Logs UI] Make column configurations reorderable * Improve typing aand memoize callback * Guard against index bounds and rename reorderLogColumns * Fix useCallback memoization * Add functional test for reordering log columns * Use browser.keys instead of Key in functional test * [Maps] populate _id in tooltip (#41684) * [ML] Data Frames - search bar on list page (#41415) * add search and filter to df list table * add mode filter to list table * adds id + description search * type fix * ensure search syntax is valid * ensure types are correct * retain filter on refresh * fix progress bar jump * [DOCS] Changed Visual Builder to TSVB (#39539) * [DOCS] Changed Visual Builder to TSVB * Reorg of interface changes * Content reorg * Updated image * Added task content * Content conslidation * Final clean up * Comments from Gail * [DOCS] Adds missing Timelion link (#41709) * [Infra UI] Fix section mapping bug in node detail page (#41641) * [Infra UI] Fix section mapping bug in node detail page * Fixing filter to match TSVB * Adding an enum for the InfraMetricsQueryType * removing unnecessary change * Change id to InfraMetric to make less error prone * Fixing type in Metrics Explorer * [Infra UI] Add UI to customize Metrics Explorer chart style (#41022) * Add UI to customize Metrics Explorer chart style * Re-order chart options form * Adding chart options to TSVB link * Rename line series to series chart * Fixing chart context menu tests * Adding test for calculate domain * Ensure caclulateDomain returns numbers * fixing typo * Bump backport to 4.6.1 (#41720) * hide top nav menu in full screen mode of maps and dashboard (#41672) * hide top nav menu in full screen mode of maps and dashboard * Fixed dashboard full screen mode and added full screen mode test to maps * improve typing (#41563) * [Code] test colorize before load a file (#41645) * [Code] handle status when repo is not exists (#41643) fix can't switch to head on root path * [Code] implement filtree api by using isogit (#41558) * remove obsolete http secutiry settings (#41569) * core doesn't use Record for public API (#41448) * core contracts don't use unknown to support type assignment limitations of https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#-k-string-unknown--is-no-longer-a-wildcard-assignment-target * regenereate docs * remove type over-write * Narrow type of PluginDeps to an object (#40846) * Narrow type of PluginDeps to an object * re-generate docs * [APM] Fix "Show trace logs" link (#41570) * [APM] Fix "Show trace logs" link * Add type for infra link items; escape url.domain param for uptime link * Comment out flakey test steps (#41743) This comments out the problematic portions of the functional test, which caused #41717 to occur. * [ML] Fixes model memory limit for metricbeat system module jobs (#41747) * [i18n] fix i18nrc parsing (#41741) * check for translations in file * update template * Add ownership of new platform security plugin to security team. (#41748) * Clean up top nav \ search bar \ query bar directives (#41636) * Move timepicker (to be deprecated) into old kbn_top_nav * Deleted search-bar and query-bar directives! * moved search bar to kibana_react (it's a generic react component, not a service) * translations * Moved superDatePicker directive to kbn_top_nav (to be deprecated) Deleted unused react_component directives call-out and tool-bar-search-box * TS test fix * Delete relative options * [ML] Use NavigationMenu without angularjs wrapper. (#41343) Follow up to #40830 and #41054 in preparation for single metric viewer migration. The previous PR introduced the navigation menu as a React component. This PR moves dependencies down from the angularjs wrapper directive directly to the React component so the component can also be used stand-alone without the angularjs wrapper. For simple angularjs based HTML templates this stand-alone usage is also part of this PR. Unfortunately the PR turned out to be quite big due to: Most page react components had to be wrapped in another to allow the addition of thus leading to large diffs for the components. All component code inside the was not touched though. * [telemetry] Analytics Package (#41113) * kbn-analytics * kbn-analytics * expose provider * add logger * performance and stats reporters * finalize ui stats metric * functional tests * remove readme file for now * update readme * add types file into to tsconfigs * Update packages/kbn-analytics/src/report.ts Co-Authored-By: Josh Dover * fix typechecks * use enum instead of strings for metric types * getUiStatsReporter -> createUiStatsReporter * fix special typo in README * remove unused stop method * fix tests * default debug to false * use chrome.getInjected * add METRIC_TYPE to jest module mocks * mock create fn * handle enabled:false * init ui_metric in test setup env * regenerator runtime * transform-regenerator * update lock file * update babel configs * runtime dep * add regenerator * babel configs * use env-preset * merge conflicts * fix workpad telemetry tests * regeneratorRuntime attempt to fix number 30000 * env targets * remove module config * try again * try without regenerator * use kbn/babel-preset/webpack_preset only * runtime * just use typescript * update tsconfig * Caches trackers by app value for infra useTrackMetric hook * replace all occurences of placeholder in drilldown url template (#41673) * cleanup names and files/paths to confirm to a standard format * tack down WIP code * remove things not or not yet needed * Added Flexmonster Pivot Table to known plugins list (#41655) * Add Flexmonster Pivot Table to known plugins list * Update docs/plugins/known-plugins.asciidoc Co-Authored-By: Larry Gregory * Fix typo (#41705) * turn on filtering tests (#41202) * turn on filtering tests * run x-pack-firefoxSmoke ciGroup 40 times, run dashboard tests 20 times per job * Revert "run x-pack-firefoxSmoke ciGroup 40 times, run dashboard tests 20 times per job" This reverts commit 5ef02cc53ba5085c3f74431cb6ef20be2d876cde. * GoodBye Notifier (#41663) * Begin notifier removal * Remove remaining notifier traces * Remove dead translations * Remove Angular from config listener * Import angular-sanitize explicitly in map * Revert "lock es snapshot to avoid failing CI" (#41539) This reverts commit 4eca0f3383f5f7746f375c4f1559838a3bedb9df. * fix more types, define SO * [SIEM] - Fix Jest test errors and warnings (#41712) * Fixes #41787 (#41791) * [DOCS] Puts Spaces content on single page (#41536) * [DOCS] Puts Spaces content on single page * [DOCS] Incorporates review comments * [DOCS] Incorporated review comments * [SIEM] - Hosts and Network Tables from LoadMore to Paginated (#41532) * [DOCS] Updates Console doc (#41371) * [DOCS] Updates Console doc * [DOCS] Incorporates comments on Console docs * [DOCS] Updated Console images * Fixed unused variables. Added a few methods to the SO adapter Co-authored-by: Nicolas Chaulet * fix type * Revert "Merge branch 'master' of github.com:elastic/kibana into feature-fleet" This reverts commit 997490feadce9e246e5e3c2123570523e30455f8, reversing changes made to db5fc8fa3feac6f67a36cc33a3aef09b291ae789. * removed blank test file * Fix file path * add i18n --- x-pack/.i18nrc.json | 2 + .../plugins/fleet/common/types/helpers.ts | 2 + x-pack/legacy/plugins/fleet/index.ts | 2 +- .../hooks/with_kuery_autocompletion.tsx | 2 +- .../fleet/public/hooks/with_url_state.tsx | 3 +- .../plugins/fleet/public/lib/elasticsearch.ts | 2 +- x-pack/legacy/plugins/fleet/public/routes.tsx | 16 +-- .../plugins/ingest/server/kibana.index.ts | 11 +- .../adapters/configurations/adapter_types.ts | 8 +- .../libs/adapters/configurations/default.ts | 98 +++++++++++-- .../adapter_types.ts | 36 +---- .../default.ts} | 3 +- .../libs/adapters/framework/adapter_types.ts | 69 ++++----- ...kibana_framework_adapter.ts => default.ts} | 20 ++- .../adapters/so_database/adapter_types.ts | 5 + .../libs/adapters/so_database/default.ts | 134 ++++++++++++++++++ .../ingest/server/libs/compose/kibana.ts | 22 +-- .../ingest/server/libs/compose/testing.ts | 51 ------- .../ingest/server/libs/configuration.ts | 9 +- .../plugins/ingest/server/libs/framework.ts | 5 +- .../plugins/ingest/server/libs/types.ts | 7 +- 21 files changed, 304 insertions(+), 203 deletions(-) rename x-pack/legacy/plugins/ingest/server/libs/adapters/{database => es_database}/adapter_types.ts (84%) rename x-pack/legacy/plugins/ingest/server/libs/adapters/{database/kibana_database_adapter.ts => es_database/default.ts} (97%) rename x-pack/legacy/plugins/ingest/server/libs/adapters/framework/{kibana_framework_adapter.ts => default.ts} (87%) create mode 100644 x-pack/legacy/plugins/ingest/server/libs/adapters/so_database/adapter_types.ts create mode 100644 x-pack/legacy/plugins/ingest/server/libs/adapters/so_database/default.ts delete mode 100644 x-pack/legacy/plugins/ingest/server/libs/compose/testing.ts diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index f8c37c792d51c..945df1747c5b4 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -10,11 +10,13 @@ "xpack.crossClusterReplication": "legacy/plugins/cross_cluster_replication", "xpack.dashboardMode": "legacy/plugins/dashboard_mode", "xpack.fileUpload": "legacy/plugins/file_upload", + "xpack.fleet": "legacy/plugins/fleet", "xpack.graph": "legacy/plugins/graph", "xpack.grokDebugger": "legacy/plugins/grokdebugger", "xpack.idxMgmt": "legacy/plugins/index_management", "xpack.indexLifecycleMgmt": "legacy/plugins/index_lifecycle_management", "xpack.infra": "legacy/plugins/infra", + "xpack.ingest": "legacy/plugins/ingest", "xpack.kueryAutocomplete": "legacy/plugins/kuery_autocomplete", "xpack.licenseMgmt": "legacy/plugins/license_management", "xpack.maps": "legacy/plugins/maps", diff --git a/x-pack/legacy/plugins/fleet/common/types/helpers.ts b/x-pack/legacy/plugins/fleet/common/types/helpers.ts index 4258461310e16..f9d648fd61bb0 100644 --- a/x-pack/legacy/plugins/fleet/common/types/helpers.ts +++ b/x-pack/legacy/plugins/fleet/common/types/helpers.ts @@ -5,3 +5,5 @@ */ export type FlatObject = { [Key in keyof T]: string }; +export type RendererResult = React.ReactElement | null; +export type RendererFunction = (args: RenderArgs) => Result; diff --git a/x-pack/legacy/plugins/fleet/index.ts b/x-pack/legacy/plugins/fleet/index.ts index f129e9a45457c..d4b48a9e23c58 100644 --- a/x-pack/legacy/plugins/fleet/index.ts +++ b/x-pack/legacy/plugins/fleet/index.ts @@ -5,7 +5,7 @@ */ import * as Joi from 'joi'; import { resolve } from 'path'; -import { i18n } from '@kbn/i18n/src'; +import { i18n } from '@kbn/i18n'; import { PLUGIN } from './common/constants'; import { CONFIG_PREFIX } from './common/constants/plugin'; import { initServerWithKibana } from './server/kibana.index'; diff --git a/x-pack/legacy/plugins/fleet/public/hooks/with_kuery_autocompletion.tsx b/x-pack/legacy/plugins/fleet/public/hooks/with_kuery_autocompletion.tsx index 4fbf65653a404..2bfc1a1f4db19 100644 --- a/x-pack/legacy/plugins/fleet/public/hooks/with_kuery_autocompletion.tsx +++ b/x-pack/legacy/plugins/fleet/public/hooks/with_kuery_autocompletion.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; import { FrontendLibs } from '../lib/types'; -import { RendererFunction } from '../utils/typed_react'; +import { RendererFunction } from '../../common/types/helpers'; interface WithKueryAutocompletionLifecycleProps { libs: FrontendLibs; diff --git a/x-pack/legacy/plugins/fleet/public/hooks/with_url_state.tsx b/x-pack/legacy/plugins/fleet/public/hooks/with_url_state.tsx index 0802b4d8ea7e8..2db45f50b2c6c 100644 --- a/x-pack/legacy/plugins/fleet/public/hooks/with_url_state.tsx +++ b/x-pack/legacy/plugins/fleet/public/hooks/with_url_state.tsx @@ -7,8 +7,7 @@ import { parse, stringify } from 'querystring'; import React from 'react'; import { withRouter } from 'react-router-dom'; -import { FlatObject } from '../frontend_types'; -import { RendererFunction } from '../utils/typed_react'; +import { FlatObject, RendererFunction } from '../../common/types/helpers'; type StateCallback = (previousState: T) => T; diff --git a/x-pack/legacy/plugins/fleet/public/lib/elasticsearch.ts b/x-pack/legacy/plugins/fleet/public/lib/elasticsearch.ts index 7ea32a2eb9467..dee7f579ed59b 100644 --- a/x-pack/legacy/plugins/fleet/public/lib/elasticsearch.ts +++ b/x-pack/legacy/plugins/fleet/public/lib/elasticsearch.ts @@ -48,7 +48,7 @@ export class ElasticsearchLib { }); } - return hiddenFieldsCheck.reduce((isvalid, field) => { + return hiddenFieldsCheck.reduce((isvalid: boolean, field) => { if (!isvalid) { return false; } diff --git a/x-pack/legacy/plugins/fleet/public/routes.tsx b/x-pack/legacy/plugins/fleet/public/routes.tsx index 8e65f048bfa84..82fb275784235 100644 --- a/x-pack/legacy/plugins/fleet/public/routes.tsx +++ b/x-pack/legacy/plugins/fleet/public/routes.tsx @@ -7,7 +7,6 @@ import { get } from 'lodash'; import React, { Component } from 'react'; import { Redirect, Route, Switch } from 'react-router-dom'; -import { REQUIRED_ROLES } from '../common/constants/security'; import { Loading } from './components/loading'; import { ChildRoutes } from './components/navigation/child_routes'; import { URLStateProps, WithURLState } from './hooks/with_url_state'; @@ -59,19 +58,6 @@ export class AppRoutes extends Component { /> )} - {/* Make sure the user has correct permissions */} - {!this.props.libs.framework.currentUserHasOneOfRoles( - REQUIRED_ROLES.concat(this.props.libs.framework.info.settings.defaultUserRoles) - ) && ( - - !props.location.pathname.includes('/error') ? ( - - ) : null - } - /> - )} - {/* This app does not make use of a homepage. The mainpage is overview/enrolled_agents */} } /> @@ -80,7 +66,7 @@ export class AppRoutes extends Component { {(URLProps: URLStateProps) => ( { - hapiServer.route({ - method: 'GET', - path: '/api/fleet/load', - handler: (request: any, h: any) => { - return 'Hello World!'; - }, - }); + const libs = compose(hapiServer); + libs.framework.log('Ingest is composed -- debug message'); }; diff --git a/x-pack/legacy/plugins/ingest/server/libs/adapters/configurations/adapter_types.ts b/x-pack/legacy/plugins/ingest/server/libs/adapters/configurations/adapter_types.ts index b4fb6ccbfb851..c29b4c142c818 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/adapters/configurations/adapter_types.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/adapters/configurations/adapter_types.ts @@ -5,7 +5,6 @@ */ import * as t from 'io-ts'; -import { DateFromString } from '../../../../common/types/io_ts'; export const RuntimeDatasourceInput = t.interface( { @@ -48,13 +47,14 @@ export const NewRuntimeBackupConfigurationFile = t.interface( 'BackupConfigurationFile' ); -const ExistingDocument = t.partial({ +const ExistingDocument = t.interface({ id: t.string, shared_id: t.string, version: t.number, - updated_at: DateFromString, + active: t.boolean, + updated_at: t.string, created_by: t.union([t.undefined, t.string]), - updated_on: DateFromString, + updated_on: t.string, updated_by: t.union([t.undefined, t.string]), }); diff --git a/x-pack/legacy/plugins/ingest/server/libs/adapters/configurations/default.ts b/x-pack/legacy/plugins/ingest/server/libs/adapters/configurations/default.ts index dd0a546d1818a..dbbdaa9471f34 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/adapters/configurations/default.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/adapters/configurations/default.ts @@ -4,30 +4,98 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - ConfigurationFile, - NewConfigurationFile, - DatasourceInput, - BackupConfigurationFile, -} from './adapter_types'; - -export class DefaultConfigAdapter { +import { SODatabaseAdapter } from '../so_database/default'; +import { RuntimeConfigurationFile, NewConfigurationFile } from './adapter_types'; + +import { ConfigurationFile, DatasourceInput, BackupConfigurationFile } from './adapter_types'; + +export class ConfigAdapter { + constructor(private readonly so: SODatabaseAdapter) {} + public async create( configuration: NewConfigurationFile ): Promise<{ id: string; shared_id: string; version: number }> { + const newSo = await this.so.create( + 'configurations', + (configuration as any) as ConfigurationFile + ); + return { - id: 'fsdfsdf', - shared_id: 'wjkhefkjhfkjs', - version: 0, + id: newSo.id, + shared_id: newSo.attributes.shared_id, + version: newSo.attributes.version, }; } - public async get(sharedID: string, version?: number): Promise { - return {} as ConfigurationFile; + public async get(id: string): Promise { + const config = await this.so.get('configurations', id); + + if (config.error) { + throw new Error(config.error.message); + } + + if (!config.attributes) { + throw new Error(`No configuration found with ID of ${id}`); + } + if (RuntimeConfigurationFile.decode(config.attributes).isRight()) { + return config.attributes as ConfigurationFile; + } else { + throw new Error(`Invalid ConfigurationFile data. == ${config.attributes}`); + } + } + + public async list(): Promise { + const configs = await this.so.find({ + type: 'configurations', + search: '*', + searchFields: ['shared_id'], + }); + const uniqConfigurationFile = configs.saved_objects + .map(config => { + if (RuntimeConfigurationFile.decode(config.attributes).isRight()) { + return config.attributes; + } else { + throw new Error(`Invalid ConfigurationFile data. == ${config.attributes}`); + } + }) + .reduce((acc, config: ConfigurationFile) => { + if (!acc.has(config.shared_id)) { + acc.set(config.shared_id, config); + } + const prevConfig = acc.get(config.shared_id); + if (prevConfig && prevConfig.version < config.version) { + acc.set(config.shared_id, config); + } + + return acc; + }, new Map()); + + return [...uniqConfigurationFile.values()]; } - public async list(sharedID: string, version?: number): Promise { - return [{} as ConfigurationFile]; + public async listVersions(sharedID: string, activeOnly = true): Promise { + const configs = (await this.so.find({ + type: 'configurations', + search: sharedID, + searchFields: ['shared_id'], + })).saved_objects; + + if (!activeOnly) { + const backupConfigs = await this.so.find({ + type: 'backup_configurations', + search: sharedID, + searchFields: ['shared_id'], + }); + configs.concat(backupConfigs.saved_objects); + } + + return configs.map(config => { + if (RuntimeConfigurationFile.decode(config.attributes).isRight()) { + return config.attributes; + } else { + throw new Error(`Invalid ConfigurationFile data. == ${config.attributes}`); + } + }); } public async update( diff --git a/x-pack/legacy/plugins/ingest/server/libs/adapters/database/adapter_types.ts b/x-pack/legacy/plugins/ingest/server/libs/adapters/es_database/adapter_types.ts similarity index 84% rename from x-pack/legacy/plugins/ingest/server/libs/adapters/database/adapter_types.ts rename to x-pack/legacy/plugins/ingest/server/libs/adapters/es_database/adapter_types.ts index 0a06c3dcc6412..835c75bdb04ce 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/adapters/database/adapter_types.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/adapters/es_database/adapter_types.ts @@ -3,41 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { FrameworkRequest, FrameworkUser } from '../framework/adapter_types'; - -export interface DatabaseAdapter { - get( - user: FrameworkUser, - params: DatabaseGetParams - ): Promise>; - create( - user: FrameworkUser, - params: DatabaseCreateDocumentParams - ): Promise; - index( - user: FrameworkUser, - params: DatabaseIndexDocumentParams - ): Promise; - delete( - user: FrameworkUser, - params: DatabaseDeleteDocumentParams - ): Promise; - deleteByQuery( - user: FrameworkUser, - params: DatabaseSearchParams - ): Promise; - mget(user: FrameworkUser, params: DatabaseMGetParams): Promise>; - bulk( - user: FrameworkUser, - params: DatabaseBulkIndexDocumentsParams - ): Promise; - search(user: FrameworkUser, params: DatabaseSearchParams): Promise>; - searchAll( - user: FrameworkUser, - params: DatabaseSearchParams - ): Promise>; - putTemplate(name: string, template: any): Promise; -} +import { FrameworkRequest } from '../framework/adapter_types'; export interface DatabaseKbnESCluster { callWithInternalUser(esMethod: string, options: {}): Promise; diff --git a/x-pack/legacy/plugins/ingest/server/libs/adapters/database/kibana_database_adapter.ts b/x-pack/legacy/plugins/ingest/server/libs/adapters/es_database/default.ts similarity index 97% rename from x-pack/legacy/plugins/ingest/server/libs/adapters/database/kibana_database_adapter.ts rename to x-pack/legacy/plugins/ingest/server/libs/adapters/es_database/default.ts index 0538dee64be4b..8779d43bc73d0 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/adapters/database/kibana_database_adapter.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/adapters/es_database/default.ts @@ -6,7 +6,6 @@ import { FrameworkUser } from '../framework/adapter_types'; import { internalAuthData } from '../framework/adapter_types'; import { - DatabaseAdapter, DatabaseBulkIndexDocumentsParams, DatabaseCreateDocumentParams, DatabaseCreateDocumentResponse, @@ -23,7 +22,7 @@ import { DatabaseSearchResponse, } from './adapter_types'; -export class KibanaDatabaseAdapter implements DatabaseAdapter { +export class ESDatabaseAdapter { private es: DatabaseKbnESCluster; constructor(kbnElasticSearch: DatabaseKbnESPlugin) { diff --git a/x-pack/legacy/plugins/ingest/server/libs/adapters/framework/adapter_types.ts b/x-pack/legacy/plugins/ingest/server/libs/adapters/framework/adapter_types.ts index 4325e857cce00..e412d61ed9186 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/adapters/framework/adapter_types.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/adapters/framework/adapter_types.ts @@ -8,41 +8,32 @@ import { Lifecycle, ResponseToolkit } from 'hapi'; import * as t from 'io-ts'; -import { LICENSES } from '../../../../common/constants/security'; +import { Legacy } from 'kibana'; +import { Cluster, ClusterConfig } from 'src/legacy/core_plugins/elasticsearch'; +import { ApmOssPlugin } from 'src/legacy/core_plugins/apm_oss'; +import { Request } from 'src/legacy/server/kbn_server'; +import { XPackInfo } from '../../../../../xpack_main/server/lib/xpack_info'; +import { + Feature, + FeatureWithAllOrReadPrivileges, +} from '../../../../../xpack_main/server/lib/feature_registry/feature_registry'; +import { SecurityPlugin } from '../../../../../security'; export const internalAuthData = Symbol('internalAuthData'); export const internalUser: FrameworkInternalUser = { kind: 'internal', }; -export interface XpackInfo { - license: { - getType: () => typeof LICENSES[number]; - /** Is the license expired */ - isActive: () => boolean; - getExpiryDateInMillis: () => number; - }; - feature: (pluginId: string) => any; - isAvailable: () => boolean; -} - -export interface BackendFrameworkAdapter { - internalUser: FrameworkInternalUser; - info: null | FrameworkInfo; - log(text: string): void; - on(event: 'xpack.status.green' | 'elasticsearch.status.green', cb: () => void): void; - getSetting(settingPath: string): any; - getUser(request: KibanaServerRequest): Promise; - exposeMethod(name: string, method: () => any): void; -} - -export interface KibanaLegacyServer { +export interface KibanaLegacyServer extends Legacy.Server { plugins: { xpack_main: { status: { on: (status: 'green' | 'yellow' | 'red', callback: () => void) => void; }; - info: XpackInfo; + info: XPackInfo; + createXPackInfo(options: any): any; + getFeatures(): Feature[]; + registerFeature(feature: FeatureWithAllOrReadPrivileges): void; }; kibana: { status: { @@ -51,18 +42,20 @@ export interface KibanaLegacyServer { }; }; }; - security: { - getUser: (request: KibanaServerRequest) => any; - }; + security: SecurityPlugin; elasticsearch: { status: { on: (status: 'green' | 'yellow' | 'red', callback: () => void) => void; }; - getCluster: () => any; + getCluster(name: string): Cluster; + createCluster(name: string, config: ClusterConfig): Cluster; + waitUntilReady(): Promise; }; - ingest: {}; + spaces: any; + apm_oss: ApmOssPlugin; + ingest: any; }; - expose: (name: string, value: any) => void; + expose: { (key: string, value: any): void; (obj: object): void }; config: () => any; route: (routeConfig: any) => void; log: (message: string) => void; @@ -107,7 +100,6 @@ export const RuntimeKibanaServerRequest = t.interface( }, 'KibanaServerRequest' ); -export interface KibanaServerRequest extends t.TypeOf {} export const RuntimeKibanaUser = t.interface( { @@ -143,32 +135,27 @@ export type FrameworkUser = | FrameworkAuthenticatedUser | FrameworkUnAuthenticatedUser | FrameworkInternalUser; -export interface FrameworkRequest< - KibanaServerRequestGenaric extends Partial = any -> { +export interface FrameworkRequest = Request> { user: FrameworkUser; headers: KibanaServerRequestGenaric['headers']; - info: KibanaServerRequest['info']; + info: Request['info']; payload: KibanaServerRequestGenaric['payload']; params: KibanaServerRequestGenaric['params']; query: KibanaServerRequestGenaric['query']; } -export interface FrameworkRouteOptions< - RouteRequest extends FrameworkRequest = FrameworkRequest, - RouteResponse extends FrameworkResponse = any -> { +export interface FrameworkRouteOptions { path: string; method: string | string[]; vhost?: string; licenseRequired?: string[]; requiredRoles?: string[]; - handler: FrameworkRouteHandler; + handler: FrameworkRouteHandler; config?: {}; } export type FrameworkRouteHandler< - RouteRequest extends KibanaServerRequest, + RouteRequest extends Request, RouteResponse extends FrameworkResponse > = (request: FrameworkRequest, h: ResponseToolkit) => Promise; diff --git a/x-pack/legacy/plugins/ingest/server/libs/adapters/framework/kibana_framework_adapter.ts b/x-pack/legacy/plugins/ingest/server/libs/adapters/framework/default.ts similarity index 87% rename from x-pack/legacy/plugins/ingest/server/libs/adapters/framework/kibana_framework_adapter.ts rename to x-pack/legacy/plugins/ingest/server/libs/adapters/framework/default.ts index e2c2ba68e9b55..30d61e9fa27da 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/adapters/framework/kibana_framework_adapter.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/adapters/framework/default.ts @@ -6,21 +6,20 @@ import { PathReporter } from 'io-ts/lib/PathReporter'; import { get } from 'lodash'; +import { Request } from 'src/legacy/server/kbn_server'; +import { XPackInfo } from '../../../../../xpack_main/server/lib/xpack_info'; // @ts-ignore import { mirrorPluginStatus } from '../../../../../../server/lib/mirror_plugin_status'; import { - BackendFrameworkAdapter, FrameworkInfo, internalUser, KibanaLegacyServer, - KibanaServerRequest, KibanaUser, RuntimeFrameworkInfo, RuntimeKibanaUser, - XpackInfo, } from './adapter_types'; -export class KibanaBackendFrameworkAdapter implements BackendFrameworkAdapter { +export class BackendFrameworkAdapter { public readonly internalUser = internalUser; public info: null | FrameworkInfo = null; @@ -65,7 +64,7 @@ export class KibanaBackendFrameworkAdapter implements BackendFrameworkAdapter { this.server.expose(name, method); } - public async getUser(request: KibanaServerRequest): Promise { + public async getUser(request: Request): Promise { let user; try { user = await this.server.plugins.security.getUser(request); @@ -87,7 +86,7 @@ export class KibanaBackendFrameworkAdapter implements BackendFrameworkAdapter { return user; } - private xpackInfoWasUpdatedHandler = (xpackInfo: XpackInfo) => { + private xpackInfoWasUpdatedHandler = (xpackInfo: XPackInfo) => { let xpackInfoUnpacked: FrameworkInfo; // If, for some reason, we cannot get the license information @@ -103,12 +102,11 @@ export class KibanaBackendFrameworkAdapter implements BackendFrameworkAdapter { version: get(this.server, 'plugins.kibana.status.plugin.version', 'unknown'), }, license: { - type: xpackInfo.license.getType(), + type: xpackInfo.license.getType() || 'oss', expired: !xpackInfo.license.isActive(), - expiry_date_in_millis: - xpackInfo.license.getExpiryDateInMillis() !== undefined - ? xpackInfo.license.getExpiryDateInMillis() - : -1, + expiry_date_in_millis: (xpackInfo.license.getExpiryDateInMillis() !== undefined + ? xpackInfo.license.getExpiryDateInMillis() + : -1) as number, }, security: { enabled: !!xpackInfo.feature('security') && xpackInfo.feature('security').isEnabled(), diff --git a/x-pack/legacy/plugins/ingest/server/libs/adapters/so_database/adapter_types.ts b/x-pack/legacy/plugins/ingest/server/libs/adapters/so_database/adapter_types.ts new file mode 100644 index 0000000000000..41bc2aa258807 --- /dev/null +++ b/x-pack/legacy/plugins/ingest/server/libs/adapters/so_database/adapter_types.ts @@ -0,0 +1,5 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ diff --git a/x-pack/legacy/plugins/ingest/server/libs/adapters/so_database/default.ts b/x-pack/legacy/plugins/ingest/server/libs/adapters/so_database/default.ts new file mode 100644 index 0000000000000..b70d2d2c5e823 --- /dev/null +++ b/x-pack/legacy/plugins/ingest/server/libs/adapters/so_database/default.ts @@ -0,0 +1,134 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { + SavedObjectsService, + SavedObjectsClient as SavedObjectsClientType, + SavedObjectAttributes, + SavedObjectsBulkCreateObject, + SavedObjectsBaseOptions, + SavedObjectsFindOptions, + SavedObjectsFindResponse, + SavedObjectsBulkResponse, + SavedObject, + SavedObjectsUpdateOptions, +} from 'src/core/server'; +import { ElasticsearchPlugin } from 'src/legacy/core_plugins/elasticsearch'; +import { + SavedObjectsCreateOptions, + SavedObjectsBulkGetObject, + SavedObjectsUpdateResponse, +} from 'target/types/server'; + +export class SODatabaseAdapter { + private client: SavedObjectsClientType; + constructor(savedObjects: SavedObjectsService, elasticsearch: ElasticsearchPlugin) { + const { SavedObjectsClient, getSavedObjectsRepository } = savedObjects; + const { callWithInternalUser } = elasticsearch.getCluster('admin'); + const internalRepository = getSavedObjectsRepository(callWithInternalUser); + + this.client = new SavedObjectsClient(internalRepository); + } + + /** + * Persists a SavedObject + * + * @param type + * @param attributes + * @param options + */ + async create( + type: string, + data: T, + options?: SavedObjectsCreateOptions + ) { + return await this.client.create(type, data, options); + } + + /** + * Persists multiple documents batched together as a single request + * + * @param objects + * @param options + */ + async bulkCreate( + objects: Array>, + options?: SavedObjectsCreateOptions + ) { + return await this.client.bulkCreate(objects, options); + } + + /** + * Deletes a SavedObject + * + * @param type + * @param id + * @param options + */ + async delete(type: string, id: string, options: SavedObjectsBaseOptions = {}) { + return await this.client.delete(type, id, options); + } + + /** + * Find all SavedObjects matching the search query + * + * @param options + */ + async find( + options: SavedObjectsFindOptions + ): Promise> { + return await this.client.find(options); + } + + /** + * Returns an array of objects by id + * + * @param objects - an array of ids, or an array of objects containing id, type and optionally fields + * @example + * + * bulkGet([ + * { id: 'one', type: 'config' }, + * { id: 'foo', type: 'index-pattern' } + * ]) + */ + async bulkGet( + objects: SavedObjectsBulkGetObject[] = [], + options: SavedObjectsBaseOptions = {} + ): Promise> { + return await this.client.bulkGet(objects, options); + } + + /** + * Retrieves a single object + * + * @param type - The type of SavedObject to retrieve + * @param id - The ID of the SavedObject to retrieve + * @param options + */ + async get( + type: string, + id: string, + options: SavedObjectsBaseOptions = {} + ): Promise> { + return await this.client.get(type, id, options); + } + + /** + * Updates an SavedObject + * + * @param type + * @param id + * @param options + */ + async update( + type: string, + id: string, + attributes: Partial, + options: SavedObjectsUpdateOptions = {} + ): Promise> { + return await this.client.update(type, id, attributes, options); + } +} diff --git a/x-pack/legacy/plugins/ingest/server/libs/compose/kibana.ts b/x-pack/legacy/plugins/ingest/server/libs/compose/kibana.ts index aeab928b8f3b3..3b3bf058092bc 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/compose/kibana.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/compose/kibana.ts @@ -7,22 +7,28 @@ import { camelCase } from 'lodash'; import { PLUGIN } from '../../../common/constants'; import { CONFIG_PREFIX } from '../../../common/constants/plugin'; - -import { DatabaseKbnESPlugin } from '../adapters/database/adapter_types'; -import { KibanaDatabaseAdapter } from '../adapters/database/kibana_database_adapter'; -import { KibanaLegacyServer } from '../adapters/framework/adapter_types'; -import { KibanaBackendFrameworkAdapter } from '../adapters/framework/kibana_framework_adapter'; - +import { DatabaseKbnESPlugin } from '../adapters/es_database/adapter_types'; +import { ESDatabaseAdapter } from '../adapters/es_database/default'; +import { BackendFrameworkAdapter } from '../adapters/framework/default'; import { ServerLibs } from '../types'; import { BackendFrameworkLib } from './../framework'; +import { ConfigurationLib } from '../configuration'; +import { ConfigAdapter } from '../adapters/configurations/default'; +import { SODatabaseAdapter } from '../adapters/so_database/default'; +import { KibanaLegacyServer } from '../adapters/framework/adapter_types'; export function compose(server: KibanaLegacyServer): ServerLibs { const framework = new BackendFrameworkLib( - new KibanaBackendFrameworkAdapter(camelCase(PLUGIN.ID), server, CONFIG_PREFIX) + new BackendFrameworkAdapter(camelCase(PLUGIN.ID), server, CONFIG_PREFIX) ); - const database = new KibanaDatabaseAdapter(server.plugins.elasticsearch as DatabaseKbnESPlugin); + const database = new ESDatabaseAdapter(server.plugins.elasticsearch as DatabaseKbnESPlugin); + const soDatabase = new SODatabaseAdapter(server.savedObjects, server.plugins.elasticsearch); + + const configAdapter = new ConfigAdapter(soDatabase); + const configuration = new ConfigurationLib(configAdapter); const libs: ServerLibs = { + configuration, framework, database, }; diff --git a/x-pack/legacy/plugins/ingest/server/libs/compose/testing.ts b/x-pack/legacy/plugins/ingest/server/libs/compose/testing.ts deleted file mode 100644 index b5fe6195fc7c7..0000000000000 --- a/x-pack/legacy/plugins/ingest/server/libs/compose/testing.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { MemoryBeatsAdapter } from '../adapters/beats/memory_beats_adapter'; -import { MemoryConfigurationBlockAdapter } from '../adapters/configuration_blocks/memory_tags_adapter'; -import { HapiBackendFrameworkAdapter } from '../adapters/framework/hapi_framework_adapter'; -import { MemoryTagsAdapter } from '../adapters/tags/memory_tags_adapter'; -import { MemoryTokensAdapter } from '../adapters/tokens/memory_tokens_adapter'; -import { BeatEventsLib } from '../beat_events'; -import { CMBeatsDomain } from '../beats'; -import { ConfigurationBlocksLib } from '../configuration_blocks'; -import { BackendFrameworkLib } from '../framework'; -import { CMTagsDomain } from '../tags'; -import { CMTokensDomain } from '../tokens'; -import { CMServerLibs } from '../types'; - -export function compose(server: any): CMServerLibs { - const framework = new BackendFrameworkLib(new HapiBackendFrameworkAdapter(undefined, server)); - - const beatsAdapter = new MemoryBeatsAdapter(server.beatsDB || []); - const configAdapter = new MemoryConfigurationBlockAdapter(server.configsDB || []); - const tags = new CMTagsDomain( - new MemoryTagsAdapter(server.tagsDB || []), - configAdapter, - beatsAdapter - ); - const configurationBlocks = new ConfigurationBlocksLib(configAdapter, tags); - const tokens = new CMTokensDomain(new MemoryTokensAdapter(server.tokensDB || []), { - framework, - }); - const beats = new CMBeatsDomain(beatsAdapter, { - tags, - tokens, - framework, - }); - const beatEvents = new BeatEventsLib({} as any, beats); - - const libs: CMServerLibs = { - beatEvents, - framework, - beats, - tags, - tokens, - configurationBlocks, - }; - - return libs; -} diff --git a/x-pack/legacy/plugins/ingest/server/libs/configuration.ts b/x-pack/legacy/plugins/ingest/server/libs/configuration.ts index 4d0e42b2f327b..6dad8c69c5b39 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/configuration.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/configuration.ts @@ -3,12 +3,13 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { ConfigAdapter } from './adapters/configurations/default'; export class ConfigurationLib { - public async rollForward( - sharedID: string, - version?: number - ): Promise<{ id: string; version: number }> { + constructor(private readonly adapter: ConfigAdapter) {} + + public async rollForward(id: string): Promise<{ id: string; version: number }> { + this.adapter.get(id); return { id: 'fsdfsdf', version: 0, diff --git a/x-pack/legacy/plugins/ingest/server/libs/framework.ts b/x-pack/legacy/plugins/ingest/server/libs/framework.ts index 719902eb6f411..7dadd94c9a246 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/framework.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/framework.ts @@ -4,7 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { BackendFrameworkAdapter, KibanaServerRequest } from './adapters/framework/adapter_types'; +import { Request } from 'src/legacy/server/kbn_server'; +import { BackendFrameworkAdapter } from './adapters/framework/default'; export class BackendFrameworkLib { /** @@ -20,7 +21,7 @@ export class BackendFrameworkLib { public internalUser = this.adapter.internalUser; constructor(private readonly adapter: BackendFrameworkAdapter) {} - public getCurrentUser(request: KibanaServerRequest) { + public getCurrentUser(request: Request) { return this.adapter.getUser(request); } public getSetting(setting: 'defaultUserRoles'): string[]; diff --git a/x-pack/legacy/plugins/ingest/server/libs/types.ts b/x-pack/legacy/plugins/ingest/server/libs/types.ts index a1d5f0b9b3dbd..9c4771945e12e 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/types.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/types.ts @@ -4,10 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { DatabaseAdapter } from './adapters/database/adapter_types'; -import { FrameworkUser } from './adapters/framework/adapter_types'; import { BackendFrameworkLib } from './framework'; +import { ConfigurationLib } from './configuration'; +import { ESDatabaseAdapter } from './adapters/es_database/default'; export interface ServerLibs { + configuration: ConfigurationLib; framework: BackendFrameworkLib; - database?: DatabaseAdapter; + database?: ESDatabaseAdapter; }