From 881ef65d6e66e462aa0625b171e7a3ae8706ff47 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 19 Feb 2020 09:16:51 -0700 Subject: [PATCH 1/5] Remove old route ref, no longer used --- x-pack/legacy/plugins/file_upload/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/legacy/plugins/file_upload/index.js b/x-pack/legacy/plugins/file_upload/index.js index d29226c802b069..4a45626508690a 100644 --- a/x-pack/legacy/plugins/file_upload/index.js +++ b/x-pack/legacy/plugins/file_upload/index.js @@ -29,7 +29,6 @@ export const fileUpload = kibana => { // legacy dependencies const __LEGACY = { - route: server.route.bind(server), plugins: { elasticsearch: server.plugins.elasticsearch, }, From 8fe9aece67fae753ac4c179f8bfd958011fe047c Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 19 Feb 2020 15:21:10 -0700 Subject: [PATCH 2/5] Use core elasticsearch service --- x-pack/legacy/plugins/file_upload/index.js | 3 --- .../call_with_internal_user_factory.d.ts | 2 +- .../client/call_with_internal_user_factory.js | 11 +++++----- .../client/call_with_request_factory.js | 15 ++++++++----- .../server/kibana_server_services.js | 14 ++++++++++++ .../plugins/file_upload/server/plugin.js | 6 ++--- .../file_upload/server/routes/file_upload.js | 10 ++++----- .../telemetry/file_upload_usage_collector.ts | 6 ++--- .../file_upload/server/telemetry/telemetry.ts | 22 +++++-------------- 9 files changed, 45 insertions(+), 44 deletions(-) create mode 100644 x-pack/legacy/plugins/file_upload/server/kibana_server_services.js diff --git a/x-pack/legacy/plugins/file_upload/index.js b/x-pack/legacy/plugins/file_upload/index.js index 4a45626508690a..18cb8e3a0c2f64 100644 --- a/x-pack/legacy/plugins/file_upload/index.js +++ b/x-pack/legacy/plugins/file_upload/index.js @@ -29,9 +29,6 @@ export const fileUpload = kibana => { // legacy dependencies const __LEGACY = { - plugins: { - elasticsearch: server.plugins.elasticsearch, - }, savedObjects: { getSavedObjectsRepository: server.savedObjects.getSavedObjectsRepository, }, diff --git a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.d.ts b/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.d.ts index 9c1000db8cb569..3282be64e96e80 100644 --- a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.d.ts +++ b/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.d.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export function callWithInternalUserFactory(elasticsearchPlugin: any): any; +export function callWithInternalUserFactory(): any; diff --git a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.js b/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.js index 2e5431bdd6ce2d..e9606b39d9656e 100644 --- a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.js +++ b/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.js @@ -5,14 +5,15 @@ */ import { once } from 'lodash'; +import { getAdminClient } from '../kibana_server_services'; -const _callWithInternalUser = once(elasticsearchPlugin => { - const { callWithInternalUser } = elasticsearchPlugin.getCluster('admin'); - return callWithInternalUser; +const _callWithInternalUser = once(() => { + const { callAsInternalUser } = getAdminClient(); + return callAsInternalUser; }); -export const callWithInternalUserFactory = elasticsearchPlugin => { +export const callWithInternalUserFactory = () => { return (...args) => { - return _callWithInternalUser(elasticsearchPlugin)(...args); + return _callWithInternalUser()(...args); }; }; diff --git a/x-pack/legacy/plugins/file_upload/server/client/call_with_request_factory.js b/x-pack/legacy/plugins/file_upload/server/client/call_with_request_factory.js index a0b0d2d1c7ce35..bef6c369fd9acb 100644 --- a/x-pack/legacy/plugins/file_upload/server/client/call_with_request_factory.js +++ b/x-pack/legacy/plugins/file_upload/server/client/call_with_request_factory.js @@ -5,14 +5,17 @@ */ import { once } from 'lodash'; +import { getDataClient } from '../kibana_server_services'; -const callWithRequest = once(elasticsearchPlugin => { - const cluster = elasticsearchPlugin.getCluster('data'); - return cluster.callWithRequest; -}); +const callWithRequest = once(() => getDataClient()); -export const callWithRequestFactory = (elasticsearchPlugin, request) => { +export const callWithRequestFactory = request => { return (...args) => { - return callWithRequest(elasticsearchPlugin)(request, ...args); + return ( + callWithRequest() + .asScoped(request) + // @ts-ignore + .callAsCurrentUser(...args) + ); }; }; diff --git a/x-pack/legacy/plugins/file_upload/server/kibana_server_services.js b/x-pack/legacy/plugins/file_upload/server/kibana_server_services.js new file mode 100644 index 00000000000000..08eebc0e983c02 --- /dev/null +++ b/x-pack/legacy/plugins/file_upload/server/kibana_server_services.js @@ -0,0 +1,14 @@ +/* + * 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. + */ + +let dataClient; +let adminClient; + +export const setElasticsearchClientServices = elasticsearch => { + ({ dataClient, adminClient } = elasticsearch); +}; +export const getAdminClient = () => adminClient; +export const getDataClient = () => dataClient; diff --git a/x-pack/legacy/plugins/file_upload/server/plugin.js b/x-pack/legacy/plugins/file_upload/server/plugin.js index 23fb8bda897f0f..2570d3c4d0088e 100644 --- a/x-pack/legacy/plugins/file_upload/server/plugin.js +++ b/x-pack/legacy/plugins/file_upload/server/plugin.js @@ -5,18 +5,18 @@ */ import { initRoutes } from './routes/file_upload'; +import { setElasticsearchClientServices } from './kibana_server_services'; import { registerFileUploadUsageCollector } from './telemetry'; export class FileUploadPlugin { setup(core, plugins, __LEGACY) { - const elasticsearchPlugin = __LEGACY.plugins.elasticsearch; const getSavedObjectsRepository = __LEGACY.savedObjects.getSavedObjectsRepository; const router = core.http.createRouter(); - initRoutes(router, elasticsearchPlugin, getSavedObjectsRepository); + setElasticsearchClientServices(core.elasticsearch); + initRoutes(router, getSavedObjectsRepository); registerFileUploadUsageCollector(plugins.usageCollection, { - elasticsearchPlugin, getSavedObjectsRepository, }); } diff --git a/x-pack/legacy/plugins/file_upload/server/routes/file_upload.js b/x-pack/legacy/plugins/file_upload/server/routes/file_upload.js index 1c27c2d7d68e9d..3c3a4c19af6bf2 100644 --- a/x-pack/legacy/plugins/file_upload/server/routes/file_upload.js +++ b/x-pack/legacy/plugins/file_upload/server/routes/file_upload.js @@ -75,7 +75,7 @@ export const idConditionalValidation = (body, boolHasId) => ) .validate(body); -const finishValidationAndProcessReq = (elasticsearchPlugin, getSavedObjectsRepository) => { +const finishValidationAndProcessReq = getSavedObjectsRepository => { return async (con, req, { ok, badRequest }) => { const { query: { id }, @@ -86,7 +86,7 @@ const finishValidationAndProcessReq = (elasticsearchPlugin, getSavedObjectsRepos let resp; try { const validIdReqData = idConditionalValidation(body, boolHasId); - const callWithRequest = callWithRequestFactory(elasticsearchPlugin, req); + const callWithRequest = callWithRequestFactory(req); const { importData: importDataFunc } = importDataProvider(callWithRequest); const { index, settings, mappings, ingestPipeline, data } = validIdReqData; @@ -103,7 +103,7 @@ const finishValidationAndProcessReq = (elasticsearchPlugin, getSavedObjectsRepos resp = ok({ body: processedReq }); // If no id's been established then this is a new index, update telemetry if (!boolHasId) { - await updateTelemetry({ elasticsearchPlugin, getSavedObjectsRepository }); + await updateTelemetry({ getSavedObjectsRepository }); } } else { resp = badRequest(`Error processing request 1: ${processedReq.error.message}`, ['body']); @@ -115,7 +115,7 @@ const finishValidationAndProcessReq = (elasticsearchPlugin, getSavedObjectsRepos }; }; -export const initRoutes = (router, esPlugin, getSavedObjectsRepository) => { +export const initRoutes = (router, getSavedObjectsRepository) => { router.post( { path: `${IMPORT_ROUTE}{id?}`, @@ -125,6 +125,6 @@ export const initRoutes = (router, esPlugin, getSavedObjectsRepository) => { }, options, }, - finishValidationAndProcessReq(esPlugin, getSavedObjectsRepository) + finishValidationAndProcessReq(getSavedObjectsRepository) ); }; diff --git a/x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts b/x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts index a2b359ae11638a..f4ff815b8e02f5 100644 --- a/x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts +++ b/x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts @@ -12,16 +12,14 @@ const TELEMETRY_TYPE = 'fileUploadTelemetry'; export function registerFileUploadUsageCollector( usageCollection: UsageCollectionSetup, deps: { - elasticsearchPlugin: any; getSavedObjectsRepository: any; } ): void { - const { elasticsearchPlugin, getSavedObjectsRepository } = deps; + const { getSavedObjectsRepository } = deps; const fileUploadUsageCollector = usageCollection.makeUsageCollector({ type: TELEMETRY_TYPE, isReady: () => true, - fetch: async () => - (await getTelemetry(elasticsearchPlugin, getSavedObjectsRepository)) || initTelemetry(), + fetch: async () => (await getTelemetry(getSavedObjectsRepository)) || initTelemetry(), }); usageCollection.registerCollector(fileUploadUsageCollector); diff --git a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts b/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts index 5ffa735f4c83a8..cf78ec30f88516 100644 --- a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts +++ b/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts @@ -17,11 +17,8 @@ export interface TelemetrySavedObject { attributes: Telemetry; } -export function getInternalRepository( - elasticsearchPlugin: any, - getSavedObjectsRepository: any -): any { - const callWithInternalUser = callWithInternalUserFactory(elasticsearchPlugin); +export function getInternalRepository(getSavedObjectsRepository: any): any { + const callWithInternalUser = callWithInternalUserFactory(); return getSavedObjectsRepository(callWithInternalUser); } @@ -32,12 +29,10 @@ export function initTelemetry(): Telemetry { } export async function getTelemetry( - elasticsearchPlugin: any, getSavedObjectsRepository: any, internalRepo?: object ): Promise { - const internalRepository = - internalRepo || getInternalRepository(elasticsearchPlugin, getSavedObjectsRepository); + const internalRepository = internalRepo || getInternalRepository(getSavedObjectsRepository); let telemetrySavedObject; try { @@ -50,21 +45,14 @@ export async function getTelemetry( } export async function updateTelemetry({ - elasticsearchPlugin, getSavedObjectsRepository, internalRepo, }: { - elasticsearchPlugin: any; getSavedObjectsRepository: any; internalRepo?: any; }) { - const internalRepository = - internalRepo || getInternalRepository(elasticsearchPlugin, getSavedObjectsRepository); - let telemetry = await getTelemetry( - elasticsearchPlugin, - getSavedObjectsRepository, - internalRepository - ); + const internalRepository = internalRepo || getInternalRepository(getSavedObjectsRepository); + let telemetry = await getTelemetry(getSavedObjectsRepository, internalRepository); // Create if doesn't exist if (!telemetry || _.isEmpty(telemetry)) { const newTelemetrySavedObject = await internalRepository.create( From b462cda6024d74ee6b73f500e01b89d5585a7af4 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Thu, 20 Feb 2020 07:33:28 -0700 Subject: [PATCH 3/5] Remove getSavedObjectsRepository, use NP internalRepository --- x-pack/legacy/plugins/file_upload/index.js | 15 ++++------- .../call_with_internal_user_factory.d.ts | 7 ----- .../client/call_with_internal_user_factory.js | 19 ------------- .../call_with_internal_user_factory.test.ts | 22 --------------- .../server/kibana_server_services.js | 10 ++++--- .../plugins/file_upload/server/plugin.js | 20 ++++++++------ .../file_upload/server/routes/file_upload.js | 8 +++--- .../telemetry/file_upload_usage_collector.ts | 10 ++----- .../file_upload/server/telemetry/telemetry.ts | 27 +++++-------------- 9 files changed, 37 insertions(+), 101 deletions(-) delete mode 100644 x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.d.ts delete mode 100644 x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.js delete mode 100644 x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.test.ts diff --git a/x-pack/legacy/plugins/file_upload/index.js b/x-pack/legacy/plugins/file_upload/index.js index 18cb8e3a0c2f64..17e13a7f1174c9 100644 --- a/x-pack/legacy/plugins/file_upload/index.js +++ b/x-pack/legacy/plugins/file_upload/index.js @@ -22,19 +22,14 @@ export const fileUpload = kibana => { init(server) { const coreSetup = server.newPlatform.setup.core; + const coreStart = server.newPlatform.start.core; const { usageCollection } = server.newPlatform.setup.plugins; - const pluginsSetup = { + const pluginsStart = { usageCollection, }; - - // legacy dependencies - const __LEGACY = { - savedObjects: { - getSavedObjectsRepository: server.savedObjects.getSavedObjectsRepository, - }, - }; - - new FileUploadPlugin().setup(coreSetup, pluginsSetup, __LEGACY); + const fileUploadPlugin = new FileUploadPlugin(); + fileUploadPlugin.setup(coreSetup); + fileUploadPlugin.start(coreStart, pluginsStart); }, }); }; diff --git a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.d.ts b/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.d.ts deleted file mode 100644 index 3282be64e96e80..00000000000000 --- a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.d.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 function callWithInternalUserFactory(): any; diff --git a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.js b/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.js deleted file mode 100644 index e9606b39d9656e..00000000000000 --- a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.js +++ /dev/null @@ -1,19 +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. - */ - -import { once } from 'lodash'; -import { getAdminClient } from '../kibana_server_services'; - -const _callWithInternalUser = once(() => { - const { callAsInternalUser } = getAdminClient(); - return callAsInternalUser; -}); - -export const callWithInternalUserFactory = () => { - return (...args) => { - return _callWithInternalUser()(...args); - }; -}; diff --git a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.test.ts b/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.test.ts deleted file mode 100644 index 04c5013ed8e67c..00000000000000 --- a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.test.ts +++ /dev/null @@ -1,22 +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. - */ - -import { callWithInternalUserFactory } from './call_with_internal_user_factory'; - -describe('call_with_internal_user_factory', () => { - describe('callWithInternalUserFactory', () => { - it('should use internal user "admin"', () => { - const callWithInternalUser: any = jest.fn(); - const elasticsearchPlugin: any = { - getCluster: jest.fn(() => ({ callWithInternalUser })), - }; - const callWithInternalUserInstance = callWithInternalUserFactory(elasticsearchPlugin); - callWithInternalUserInstance(); - - expect(elasticsearchPlugin.getCluster).toHaveBeenCalledWith('admin'); - }); - }); -}); diff --git a/x-pack/legacy/plugins/file_upload/server/kibana_server_services.js b/x-pack/legacy/plugins/file_upload/server/kibana_server_services.js index 08eebc0e983c02..104e49015ba807 100644 --- a/x-pack/legacy/plugins/file_upload/server/kibana_server_services.js +++ b/x-pack/legacy/plugins/file_upload/server/kibana_server_services.js @@ -5,10 +5,14 @@ */ let dataClient; -let adminClient; export const setElasticsearchClientServices = elasticsearch => { - ({ dataClient, adminClient } = elasticsearch); + ({ dataClient } = elasticsearch); }; -export const getAdminClient = () => adminClient; export const getDataClient = () => dataClient; + +let internalRepository; +export const setInternalRepository = createInternalRepository => { + internalRepository = createInternalRepository(); +}; +export const getInternalRepository = () => internalRepository; diff --git a/x-pack/legacy/plugins/file_upload/server/plugin.js b/x-pack/legacy/plugins/file_upload/server/plugin.js index 2570d3c4d0088e..c448676f813eac 100644 --- a/x-pack/legacy/plugins/file_upload/server/plugin.js +++ b/x-pack/legacy/plugins/file_upload/server/plugin.js @@ -5,19 +5,23 @@ */ import { initRoutes } from './routes/file_upload'; -import { setElasticsearchClientServices } from './kibana_server_services'; +import { setElasticsearchClientServices, setInternalRepository } from './kibana_server_services'; import { registerFileUploadUsageCollector } from './telemetry'; export class FileUploadPlugin { - setup(core, plugins, __LEGACY) { - const getSavedObjectsRepository = __LEGACY.savedObjects.getSavedObjectsRepository; - const router = core.http.createRouter(); + constructor() { + this.router = null; + } + setup(core) { setElasticsearchClientServices(core.elasticsearch); - initRoutes(router, getSavedObjectsRepository); + this.router = core.http.createRouter(); + } + + start(core, plugins) { + initRoutes(this.router, core.savedObjects.getSavedObjectsRepository); + setInternalRepository(core.savedObjects.createInternalRepository); - registerFileUploadUsageCollector(plugins.usageCollection, { - getSavedObjectsRepository, - }); + registerFileUploadUsageCollector(plugins.usageCollection); } } diff --git a/x-pack/legacy/plugins/file_upload/server/routes/file_upload.js b/x-pack/legacy/plugins/file_upload/server/routes/file_upload.js index 3c3a4c19af6bf2..acbc907729d958 100644 --- a/x-pack/legacy/plugins/file_upload/server/routes/file_upload.js +++ b/x-pack/legacy/plugins/file_upload/server/routes/file_upload.js @@ -75,7 +75,7 @@ export const idConditionalValidation = (body, boolHasId) => ) .validate(body); -const finishValidationAndProcessReq = getSavedObjectsRepository => { +const finishValidationAndProcessReq = () => { return async (con, req, { ok, badRequest }) => { const { query: { id }, @@ -103,7 +103,7 @@ const finishValidationAndProcessReq = getSavedObjectsRepository => { resp = ok({ body: processedReq }); // If no id's been established then this is a new index, update telemetry if (!boolHasId) { - await updateTelemetry({ getSavedObjectsRepository }); + await updateTelemetry(); } } else { resp = badRequest(`Error processing request 1: ${processedReq.error.message}`, ['body']); @@ -115,7 +115,7 @@ const finishValidationAndProcessReq = getSavedObjectsRepository => { }; }; -export const initRoutes = (router, getSavedObjectsRepository) => { +export const initRoutes = router => { router.post( { path: `${IMPORT_ROUTE}{id?}`, @@ -125,6 +125,6 @@ export const initRoutes = (router, getSavedObjectsRepository) => { }, options, }, - finishValidationAndProcessReq(getSavedObjectsRepository) + finishValidationAndProcessReq() ); }; diff --git a/x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts b/x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts index f4ff815b8e02f5..2c2b1183fd5bf3 100644 --- a/x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts +++ b/x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts @@ -9,17 +9,11 @@ import { getTelemetry, initTelemetry } from './telemetry'; const TELEMETRY_TYPE = 'fileUploadTelemetry'; -export function registerFileUploadUsageCollector( - usageCollection: UsageCollectionSetup, - deps: { - getSavedObjectsRepository: any; - } -): void { - const { getSavedObjectsRepository } = deps; +export function registerFileUploadUsageCollector(usageCollection: UsageCollectionSetup): void { const fileUploadUsageCollector = usageCollection.makeUsageCollector({ type: TELEMETRY_TYPE, isReady: () => true, - fetch: async () => (await getTelemetry(getSavedObjectsRepository)) || initTelemetry(), + fetch: async () => (await getTelemetry()) || initTelemetry(), }); usageCollection.registerCollector(fileUploadUsageCollector); diff --git a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts b/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts index cf78ec30f88516..2978dec7aa68da 100644 --- a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts +++ b/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts @@ -5,7 +5,8 @@ */ import _ from 'lodash'; -import { callWithInternalUserFactory } from '../client/call_with_internal_user_factory'; +// @ts-ignore +import { getInternalRepository } from '../kibana_server_services'; export const TELEMETRY_DOC_ID = 'file-upload-telemetry'; @@ -17,22 +18,14 @@ export interface TelemetrySavedObject { attributes: Telemetry; } -export function getInternalRepository(getSavedObjectsRepository: any): any { - const callWithInternalUser = callWithInternalUserFactory(); - return getSavedObjectsRepository(callWithInternalUser); -} - export function initTelemetry(): Telemetry { return { filesUploadedTotalCount: 0, }; } -export async function getTelemetry( - getSavedObjectsRepository: any, - internalRepo?: object -): Promise { - const internalRepository = internalRepo || getInternalRepository(getSavedObjectsRepository); +export async function getTelemetry(internalRepo?: object): Promise { + const internalRepository = internalRepo || getInternalRepository(); let telemetrySavedObject; try { @@ -44,15 +37,9 @@ export async function getTelemetry( return telemetrySavedObject ? telemetrySavedObject.attributes : null; } -export async function updateTelemetry({ - getSavedObjectsRepository, - internalRepo, -}: { - getSavedObjectsRepository: any; - internalRepo?: any; -}) { - const internalRepository = internalRepo || getInternalRepository(getSavedObjectsRepository); - let telemetry = await getTelemetry(getSavedObjectsRepository, internalRepository); +export async function updateTelemetry(internalRepo?: any) { + const internalRepository = internalRepo || getInternalRepository(); + let telemetry = await getTelemetry(internalRepository); // Create if doesn't exist if (!telemetry || _.isEmpty(telemetry)) { const newTelemetrySavedObject = await internalRepository.create( From 372f5ff375a757840fc8572ade0fc094bc441f75 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Thu, 20 Feb 2020 08:56:57 -0700 Subject: [PATCH 4/5] Update tests and clean up --- x-pack/legacy/plugins/file_upload/index.js | 3 ++- .../file_upload/server/telemetry/telemetry.test.ts | 8 ++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/x-pack/legacy/plugins/file_upload/index.js b/x-pack/legacy/plugins/file_upload/index.js index 17e13a7f1174c9..23e1e1d98aa7fb 100644 --- a/x-pack/legacy/plugins/file_upload/index.js +++ b/x-pack/legacy/plugins/file_upload/index.js @@ -8,9 +8,10 @@ import { mappings } from './mappings'; export const fileUpload = kibana => { return new kibana.Plugin({ - require: ['elasticsearch', 'xpack_main'], + require: ['elasticsearch'], name: 'file_upload', id: 'file_upload', + // TODO: uiExports and savedObjectSchemas to be removed on migration uiExports: { mappings, }, diff --git a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts b/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts index 1c785d8e7b61c6..deb38989bab1dc 100644 --- a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts +++ b/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts @@ -25,7 +25,7 @@ describe('file upload plugin telemetry', () => { describe('getTelemetry', () => { it('should get existing telemetry', async () => { const internalRepo = mockInit(); - await getTelemetry(elasticsearchPlugin, getSavedObjectsRepository, internalRepo); + await getTelemetry(internalRepo); expect(internalRepo.update.mock.calls.length).toBe(0); expect(internalRepo.get.mock.calls.length).toBe(1); expect(internalRepo.create.mock.calls.length).toBe(0); @@ -40,11 +40,7 @@ describe('file upload plugin telemetry', () => { }, }); - await updateTelemetry({ - elasticsearchPlugin, - getSavedObjectsRepository, - internalRepo, - }); + await updateTelemetry(internalRepo); expect(internalRepo.update.mock.calls.length).toBe(1); expect(internalRepo.get.mock.calls.length).toBe(1); expect(internalRepo.create.mock.calls.length).toBe(0); From d0caae4fa134c5a24d2ec4dea29f3299b9442ba4 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Fri, 21 Feb 2020 13:14:21 -0700 Subject: [PATCH 5/5] Remove unused test vars --- .../plugins/file_upload/server/telemetry/telemetry.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts b/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts index deb38989bab1dc..fadad307c0710c 100644 --- a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts +++ b/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts @@ -6,8 +6,6 @@ import { getTelemetry, updateTelemetry } from './telemetry'; -const elasticsearchPlugin: any = null; -const getSavedObjectsRepository: any = null; const internalRepository = () => ({ get: jest.fn(() => null), create: jest.fn(() => ({ attributes: 'test' })),