diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index 24f8ce79d70a6..8e71e717571ce 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -11,11 +11,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; }