-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[QA] Add saved objects info svc (#96364)
Add svc and fn to return saved object types in a given index, defaulted to ".kibana" index.
- Loading branch information
1 parent
4a54188
commit 9ec466e
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { Client } from '@elastic/elasticsearch'; | ||
import url from 'url'; | ||
import { Either, fromNullable, chain, getOrElse } from 'fp-ts/Either'; | ||
import { flow } from 'fp-ts/function'; | ||
import { FtrProviderContext } from '../ftr_provider_context'; | ||
|
||
const pluck = (key: string) => (obj: any): Either<Error, string> => | ||
fromNullable(new Error(`Missing ${key}`))(obj[key]); | ||
|
||
const types = (node: string) => async (index: string = '.kibana') => { | ||
let res: unknown; | ||
try { | ||
const { body } = await new Client({ node }).search({ | ||
index, | ||
body: { | ||
aggs: { | ||
savedobjs: { | ||
terms: { | ||
field: 'type', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
res = flow( | ||
pluck('aggregations'), | ||
chain(pluck('savedobjs')), | ||
chain(pluck('buckets')), | ||
getOrElse((err) => `${err.message}`) | ||
)(body); | ||
} catch (err) { | ||
throw new Error(`Error while searching for saved object types: ${err}`); | ||
} | ||
|
||
return res; | ||
}; | ||
|
||
export const SavedObjectInfoProvider: any = ({ getService }: FtrProviderContext) => { | ||
const config = getService('config'); | ||
|
||
return { | ||
types: types(url.format(config.get('servers.elasticsearch'))), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters