Skip to content

Commit

Permalink
Build streams
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Dec 17, 2019
1 parent bc42121 commit 25e1e42
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions x-pack/legacy/plugins/epm/server/datasources/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/

import fetch from 'node-fetch';
import yaml from 'js-yaml';
import { SavedObjectsClientContract } from 'src/core/server/';
import { Asset, Datasource, InputType } from '../../../ingest/server/libs/types';
import { Asset, Datasource, Stream } from '../../../ingest/server/libs/types';
import { SAVED_OBJECT_TYPE_DATASOURCES } from '../../common/constants';
import { AssetReference, Dataset, InstallationStatus, RegistryPackage } from '../../common/types';
import { CallESAsCurrentUser } from '../lib/cluster_access';
Expand Down Expand Up @@ -40,10 +41,14 @@ export async function createDatasource(options: {
const pkg = await Registry.fetchInfo(pkgkey);

// Collect the config for each dataset
const inputs: string[] = [];
const streams: Stream[] = [];
if (pkg.datasets) {
for (const dataset of pkg.datasets) {
inputs.push(await getConfig(pkgkey, dataset));
streams.push({
id: dataset.name,
input: yaml.load(await getConfig(pkgkey, dataset)),
output_id: 'default',
});
}
}

Expand All @@ -56,7 +61,7 @@ export async function createDatasource(options: {
datasets,
toSave,
request,
inputs,
streams,
}),
]);

Expand All @@ -83,9 +88,9 @@ async function saveDatasourceReferences(options: {
datasourceName: string;
toSave: AssetReference[];
request: Request;
inputs: string[];
streams: Stream[];
}) {
const { savedObjectsClient, pkg, toSave, datasets, datasourceName, request, inputs } = options;
const { savedObjectsClient, pkg, toSave, datasets, datasourceName, request, streams } = options;
const savedDatasource = await getDatasource({ savedObjectsClient, pkg });
const savedAssets = savedDatasource?.package.assets;
const assetsReducer = (current: Asset[] = [], pending: Asset) => {
Expand All @@ -100,9 +105,9 @@ async function saveDatasourceReferences(options: {
datasourceName,
datasets,
assets: toInstall,
streams,
});

datasource.inputs = inputs;
// ideally we'd call .create from /x-pack/legacy/plugins/ingest/server/libs/datasources.ts#L22
// or something similar, but it's a class not an object so many pieces are missing
// we'd still need `user` from the request object, but that's not terrible
Expand All @@ -129,29 +134,16 @@ interface CreateFakeDatasource {
datasourceName: string;
datasets: Dataset[];
assets: Asset[] | undefined;
streams: Stream[];
}

function createFakeDatasource({
pkg,
datasourceName,
datasets,
assets = [],
streams,
}: CreateFakeDatasource): Datasource {
const streams = datasets.map(dataset => ({
id: dataset.name,
input: {
type: InputType.Log,
config: { config: 'values', go: 'here' },
ingest_pipelines: ['string'],
id: 'string',
index_template: 'string',
ilm_policy: 'string',
fields: [{}],
},
config: { config: 'values', go: 'here' },
output_id: 'output_id',
processors: ['string'],
}));
return {
id: Registry.pkgToPkgKey(pkg),
name: datasourceName,
Expand Down

0 comments on commit 25e1e42

Please sign in to comment.