Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EPM] Replace wildcard export #52554

Merged
merged 2 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions x-pack/legacy/plugins/epm/server/datasources/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Datasource>(SAVED_OBJECT_TYPE_DATASOURCES, datasource, {
id: pkgToPkgKey(pkg),
id: Registry.pkgToPkgKey(pkg),
overwrite: true,
});

Expand All @@ -98,15 +91,15 @@ async function getDatasource(options: {
}) {
const { savedObjectsClient, pkg } = options;
const datasource = await savedObjectsClient
.get<Datasource>(SAVED_OBJECT_TYPE_DATASOURCES, pkgToPkgKey(pkg))
.get<Datasource>(SAVED_OBJECT_TYPE_DATASOURCES, Registry.pkgToPkgKey(pkg))
.catch(e => undefined);

return datasource?.attributes;
}

function createFakeDatasource(pkg: RegistryPackage, assets: Asset[] = []): Datasource {
return {
id: pkgToPkgKey(pkg),
id: Registry.pkgToPkgKey(pkg),
name: 'name',
read_alias: 'read_alias',
package: {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/legacy/plugins/epm/server/datasources/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 0 additions & 7 deletions x-pack/legacy/plugins/epm/server/datasources/index.ts

This file was deleted.

28 changes: 24 additions & 4 deletions x-pack/legacy/plugins/epm/server/packages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,30 @@ 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) {
super(`${pkgkey} is not installed`);
}
}

// only Kibana Assets use Saved Objects at this point
export const savedObjectTypes: AssetType[] = Object.values(KibanaAssetType);
Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/epm/server/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface SearchParams {
category?: CategoryId;
}

export const pkgToPkgKey = ({ name, version }: RegistryPackage) => `${name}-${version}`;

export async function fetchList(params?: SearchParams): Promise<RegistrySearchResults> {
const { registryUrl } = epmConfigStore.getConfig();
const url = new URL(`${registryUrl}/search`);
Expand Down