From d947a47924d6c7b91ea96d4378422a65671429b7 Mon Sep 17 00:00:00 2001 From: John Schulz Date: Mon, 9 Dec 2019 14:41:03 -0500 Subject: [PATCH 1/2] Remove export * for datasources. Import * PackageNotInstalledError -> packages/index.ts * pkgToPkgKey -> registry/index.ts (will convert existing `${name}-${version}` instances later) --- .../plugins/epm/server/datasources/create.ts | 15 ++++----------- .../plugins/epm/server/datasources/handlers.ts | 3 ++- .../plugins/epm/server/datasources/index.ts | 7 ------- .../legacy/plugins/epm/server/packages/index.ts | 6 ++++++ .../legacy/plugins/epm/server/registry/index.ts | 2 ++ 5 files changed, 14 insertions(+), 19 deletions(-) delete mode 100644 x-pack/legacy/plugins/epm/server/datasources/index.ts diff --git a/x-pack/legacy/plugins/epm/server/datasources/create.ts b/x-pack/legacy/plugins/epm/server/datasources/create.ts index c34b0e1cfac78..530c0f6b3c765 100644 --- a/x-pack/legacy/plugins/epm/server/datasources/create.ts +++ b/x-pack/legacy/plugins/epm/server/datasources/create.ts @@ -12,16 +12,9 @@ import { CallESAsCurrentUser } from '../lib/cluster_access'; import { installILMPolicy, policyExists } from '../lib/elasticsearch/ilm/install'; import { installPipelines } from '../lib/elasticsearch/ingest_pipeline/ingest_pipelines'; import { installTemplates } from '../lib/elasticsearch/template/install'; -import { getPackageInfo } from '../packages'; +import { getPackageInfo, PackageNotInstalledError } from '../packages'; import * as Registry from '../registry'; -const pkgToPkgKey = ({ name, version }: RegistryPackage) => `${name}-${version}`; -export class PackageNotInstalledError extends Error { - constructor(pkgkey: string) { - super(`${pkgkey} is not installed`); - } -} - export async function createDatasource(options: { savedObjectsClient: SavedObjectsClientContract; pkgkey: string; @@ -85,7 +78,7 @@ async function saveDatasourceReferences(options: { const toInstall = (toSave as Asset[]).reduce(assetsReducer, savedAssets); const datasource: Datasource = createFakeDatasource(pkg, toInstall); await savedObjectsClient.create(SAVED_OBJECT_TYPE_DATASOURCES, datasource, { - id: pkgToPkgKey(pkg), + id: Registry.pkgToPkgKey(pkg), overwrite: true, }); @@ -98,7 +91,7 @@ async function getDatasource(options: { }) { const { savedObjectsClient, pkg } = options; const datasource = await savedObjectsClient - .get(SAVED_OBJECT_TYPE_DATASOURCES, pkgToPkgKey(pkg)) + .get(SAVED_OBJECT_TYPE_DATASOURCES, Registry.pkgToPkgKey(pkg)) .catch(e => undefined); return datasource?.attributes; @@ -106,7 +99,7 @@ async function getDatasource(options: { function createFakeDatasource(pkg: RegistryPackage, assets: Asset[] = []): Datasource { return { - id: pkgToPkgKey(pkg), + id: Registry.pkgToPkgKey(pkg), name: 'name', read_alias: 'read_alias', package: { diff --git a/x-pack/legacy/plugins/epm/server/datasources/handlers.ts b/x-pack/legacy/plugins/epm/server/datasources/handlers.ts index 5eba8c429d565..da627be015254 100644 --- a/x-pack/legacy/plugins/epm/server/datasources/handlers.ts +++ b/x-pack/legacy/plugins/epm/server/datasources/handlers.ts @@ -6,10 +6,11 @@ import Boom from 'boom'; import { getClusterAccessor } from '../lib/cluster_access'; +import { PackageNotInstalledError } from '../packages'; import { PluginContext } from '../plugin'; import { getClient } from '../saved_objects'; import { Request, ResponseToolkit } from '../types'; -import { createDatasource, PackageNotInstalledError } from './index'; +import { createDatasource } from './create'; // TODO: duplicated from packages/handlers.ts. unduplicate. interface Extra extends ResponseToolkit { diff --git a/x-pack/legacy/plugins/epm/server/datasources/index.ts b/x-pack/legacy/plugins/epm/server/datasources/index.ts deleted file mode 100644 index 09003a9399660..0000000000000 --- a/x-pack/legacy/plugins/epm/server/datasources/index.ts +++ /dev/null @@ -1,7 +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. - */ - -export * from './create'; diff --git a/x-pack/legacy/plugins/epm/server/packages/index.ts b/x-pack/legacy/plugins/epm/server/packages/index.ts index 1c744c67209cf..e44ba5c706501 100644 --- a/x-pack/legacy/plugins/epm/server/packages/index.ts +++ b/x-pack/legacy/plugins/epm/server/packages/index.ts @@ -18,6 +18,12 @@ export * from './handlers'; export * from './install'; export * from './remove'; +export class PackageNotInstalledError extends Error { + constructor(pkgkey: string) { + super(`${pkgkey} is not installed`); + } +} + // only Kibana Assets use Saved Objects at this point export const savedObjectTypes: AssetType[] = Object.values(KibanaAssetType); diff --git a/x-pack/legacy/plugins/epm/server/registry/index.ts b/x-pack/legacy/plugins/epm/server/registry/index.ts index d6a301f318e89..04fc141f9f4fb 100644 --- a/x-pack/legacy/plugins/epm/server/registry/index.ts +++ b/x-pack/legacy/plugins/epm/server/registry/index.ts @@ -27,6 +27,8 @@ export interface SearchParams { category?: CategoryId; } +export const pkgToPkgKey = ({ name, version }: RegistryPackage) => `${name}-${version}`; + export async function fetchList(params?: SearchParams): Promise { const { registryUrl } = epmConfigStore.getConfig(); const url = new URL(`${registryUrl}/search`); From 9e2d78f78ca875d287cbf1ffb3e67d7cd22fb613 Mon Sep 17 00:00:00 2001 From: John Schulz Date: Mon, 9 Dec 2019 15:02:12 -0500 Subject: [PATCH 2/2] Replace export * from packages. There's an argument that the import sites should be updated to import from `packages/get`, `packages/install`, etc but that can wait for a later PR. --- .../plugins/epm/server/packages/index.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/x-pack/legacy/plugins/epm/server/packages/index.ts b/x-pack/legacy/plugins/epm/server/packages/index.ts index e44ba5c706501..1b1851540de48 100644 --- a/x-pack/legacy/plugins/epm/server/packages/index.ts +++ b/x-pack/legacy/plugins/epm/server/packages/index.ts @@ -13,10 +13,24 @@ import { KibanaAssetType, } from '../../common/types'; -export * from './get'; -export * from './handlers'; -export * from './install'; -export * from './remove'; +export { + getCategories, + getFile, + getInstallationObject, + getPackageInfo, + getPackages, + SearchParams, +} from './get'; +export { + handleGetCategories, + handleGetFile, + handleGetInfo, + handleGetList, + handleRequestDelete, + handleRequestInstall, +} from './handlers'; +export { installAssets, installPackage } from './install'; +export { removeInstallation } from './remove'; export class PackageNotInstalledError extends Error { constructor(pkgkey: string) {