Skip to content

Commit

Permalink
refactor utils
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsonpl committed May 23, 2022
1 parent 180a456 commit bdb4a3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ export const readSavedQueryRoute = (router: IRouter, osqueryContext: OsqueryAppC
prebuilt: boolean;
}>(savedQuerySavedObjectType, request.params.id);

const isPrebuilt: boolean = await isSavedQueryPrebuilt(osqueryContext, savedQuery.id);

if (savedQuery.attributes.ecs_mapping) {
// @ts-expect-error update types
savedQuery.attributes.ecs_mapping = convertECSMappingToObject(
savedQuery.attributes.ecs_mapping
);
}

savedQuery.attributes.prebuilt = isPrebuilt;
savedQuery.attributes.prebuilt = await isSavedQueryPrebuilt(osqueryContext, savedQuery.id);

return response.ok({
body: savedQuery,
Expand Down
19 changes: 13 additions & 6 deletions x-pack/plugins/osquery/server/routes/saved_query/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* 2.0.
*/

import { find, mapKeys } from 'lodash';
import { find, reduce } from 'lodash';
import { KibanaAssetReference } from '@kbn/fleet-plugin/common';

import { OSQUERY_INTEGRATION_NAME } from '../../../common';
import { savedQuerySavedObjectType } from '../../../common/types';
import { OsqueryAppContext } from '../../lib/osquery_app_context_services';
Expand All @@ -18,11 +20,16 @@ const getInstallation = async (osqueryContext: OsqueryAppContext) =>
export const getInstalledSavedQueriesMap = async (osqueryContext: OsqueryAppContext) => {
const installation = await getInstallation(osqueryContext);
if (installation) {
return mapKeys(installation.installed_kibana, (value) => {
if (value.type === savedQuerySavedObjectType) {
return value.id;
}
});
return reduce(
installation.installed_kibana,
// @ts-expect-error not sure why it shouts, but still it's properly typed
(acc: Record<string, KibanaAssetReference>, item: KibanaAssetReference) => {
if (item.type === savedQuerySavedObjectType) {
return { ...acc, [item.id]: item };
}
},
{}
);
}

return {};
Expand Down

0 comments on commit bdb4a3b

Please sign in to comment.