From ba90e13e1383403b72aecbf67f7b69737bdaedab Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Mon, 18 May 2020 17:33:21 +0100 Subject: [PATCH] adds a getClient api to Encrypted Saved Objects --- .../server/lib/action_executor.test.ts | 20 ++++++------- .../actions/server/lib/action_executor.ts | 12 ++++---- .../server/lib/task_runner_factory.test.ts | 22 +++++++-------- .../actions/server/lib/task_runner_factory.ts | 8 +++--- x-pack/plugins/actions/server/plugin.ts | 6 ++-- .../alerting/server/alerts_client.test.ts | 4 +-- .../plugins/alerting/server/alerts_client.ts | 24 ++++++++-------- .../server/alerts_client_factory.test.ts | 4 +-- .../alerting/server/alerts_client_factory.ts | 10 +++---- x-pack/plugins/alerting/server/plugin.test.ts | 2 ++ x-pack/plugins/alerting/server/plugin.ts | 6 ++-- .../server/task_runner/task_runner.test.ts | 28 +++++++++---------- .../server/task_runner/task_runner.ts | 2 +- .../task_runner/task_runner_factory.test.ts | 2 +- .../server/task_runner/task_runner_factory.ts | 4 +-- .../encrypted_saved_objects/server/index.ts | 1 + .../encrypted_saved_objects/server/mocks.ts | 10 ++++++- .../server/plugin.test.ts | 24 ++++++---------- .../encrypted_saved_objects/server/plugin.ts | 13 ++------- .../server/saved_objects/index.ts | 8 +++--- .../server/services/agents/acks.test.ts | 8 ++++-- .../server/services/app_context.ts | 6 ++-- .../fixtures/plugins/aad/server/plugin.ts | 8 ++++-- .../api_consumer_plugin/server/index.ts | 8 ++---- 24 files changed, 123 insertions(+), 117 deletions(-) diff --git a/x-pack/plugins/actions/server/lib/action_executor.test.ts b/x-pack/plugins/actions/server/lib/action_executor.test.ts index 4594fc1ddf6d9a..f1e5a10e5bbd2b 100644 --- a/x-pack/plugins/actions/server/lib/action_executor.test.ts +++ b/x-pack/plugins/actions/server/lib/action_executor.test.ts @@ -18,7 +18,7 @@ import { actionsMock } from '../mocks'; const actionExecutor = new ActionExecutor({ isESOUsingEphemeralEncryptionKey: false }); const services = actionsMock.createServices(); const savedObjectsClient = services.savedObjectsClient; -const encryptedSavedObjectsPlugin = encryptedSavedObjectsMock.createStart(); +const encryptedSavedObjectsClient = encryptedSavedObjectsMock.createClient(); const actionTypeRegistry = actionTypeRegistryMock.create(); const executeParams = { @@ -35,7 +35,7 @@ actionExecutor.initialize({ spaces: spacesMock, getServices: () => services, actionTypeRegistry, - encryptedSavedObjectsPlugin, + encryptedSavedObjectsClient, eventLogger: eventLoggerMock.create(), preconfiguredActions: [], }); @@ -67,11 +67,11 @@ test('successfully executes', async () => { references: [], }; savedObjectsClient.get.mockResolvedValueOnce(actionSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce(actionSavedObject); + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce(actionSavedObject); actionTypeRegistry.get.mockReturnValueOnce(actionType); await actionExecutor.execute(executeParams); - expect(encryptedSavedObjectsPlugin.getDecryptedAsInternalUser).toHaveBeenCalledWith( + expect(encryptedSavedObjectsClient.getDecryptedAsInternalUser).toHaveBeenCalledWith( 'action', '1', { namespace: 'some-namespace' } @@ -108,7 +108,7 @@ test('provides empty config when config and / or secrets is empty', async () => references: [], }; savedObjectsClient.get.mockResolvedValueOnce(actionSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce(actionSavedObject); + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce(actionSavedObject); actionTypeRegistry.get.mockReturnValueOnce(actionType); await actionExecutor.execute(executeParams); @@ -138,7 +138,7 @@ test('throws an error when config is invalid', async () => { references: [], }; savedObjectsClient.get.mockResolvedValueOnce(actionSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce(actionSavedObject); + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce(actionSavedObject); actionTypeRegistry.get.mockReturnValueOnce(actionType); const result = await actionExecutor.execute(executeParams); @@ -171,7 +171,7 @@ test('throws an error when params is invalid', async () => { references: [], }; savedObjectsClient.get.mockResolvedValueOnce(actionSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce(actionSavedObject); + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce(actionSavedObject); actionTypeRegistry.get.mockReturnValueOnce(actionType); const result = await actionExecutor.execute(executeParams); @@ -206,7 +206,7 @@ test('throws an error if actionType is not enabled', async () => { references: [], }; savedObjectsClient.get.mockResolvedValueOnce(actionSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce(actionSavedObject); + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce(actionSavedObject); actionTypeRegistry.get.mockReturnValueOnce(actionType); actionTypeRegistry.ensureActionTypeEnabled.mockImplementationOnce(() => { throw new Error('not enabled for test'); @@ -240,7 +240,7 @@ test('should not throws an error if actionType is preconfigured', async () => { references: [], }; savedObjectsClient.get.mockResolvedValueOnce(actionSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce(actionSavedObject); + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce(actionSavedObject); actionTypeRegistry.get.mockReturnValueOnce(actionType); actionTypeRegistry.ensureActionTypeEnabled.mockImplementationOnce(() => { throw new Error('not enabled for test'); @@ -269,7 +269,7 @@ test('throws an error when passing isESOUsingEphemeralEncryptionKey with value o spaces: spacesMock, getServices: () => services, actionTypeRegistry, - encryptedSavedObjectsPlugin, + encryptedSavedObjectsClient, eventLogger: eventLoggerMock.create(), preconfiguredActions: [], }); diff --git a/x-pack/plugins/actions/server/lib/action_executor.ts b/x-pack/plugins/actions/server/lib/action_executor.ts index 3e9262c05efac4..aad93a04248ebb 100644 --- a/x-pack/plugins/actions/server/lib/action_executor.ts +++ b/x-pack/plugins/actions/server/lib/action_executor.ts @@ -14,7 +14,7 @@ import { PreConfiguredAction, Services, } from '../types'; -import { EncryptedSavedObjectsPluginStart } from '../../../encrypted_saved_objects/server'; +import { EncryptedSavedObjectsClient } from '../../../encrypted_saved_objects/server'; import { SpacesServiceSetup } from '../../../spaces/server'; import { EVENT_LOG_ACTIONS } from '../plugin'; import { IEvent, IEventLogger, SAVED_OBJECT_REL_PRIMARY } from '../../../event_log/server'; @@ -23,7 +23,7 @@ export interface ActionExecutorContext { logger: Logger; spaces?: SpacesServiceSetup; getServices: GetServicesFunction; - encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart; + encryptedSavedObjectsClient: EncryptedSavedObjectsClient; actionTypeRegistry: ActionTypeRegistryContract; eventLogger: IEventLogger; preconfiguredActions: PreConfiguredAction[]; @@ -72,7 +72,7 @@ export class ActionExecutor { const { spaces, getServices, - encryptedSavedObjectsPlugin, + encryptedSavedObjectsClient, actionTypeRegistry, eventLogger, preconfiguredActions, @@ -84,7 +84,7 @@ export class ActionExecutor { const { actionTypeId, name, config, secrets } = await getActionInfo( services, - encryptedSavedObjectsPlugin, + encryptedSavedObjectsClient, preconfiguredActions, actionId, namespace.namespace @@ -196,7 +196,7 @@ interface ActionInfo { async function getActionInfo( services: Services, - encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart, + encryptedSavedObjectsClient: EncryptedSavedObjectsClient, preconfiguredActions: PreConfiguredAction[], actionId: string, namespace: string | undefined @@ -222,7 +222,7 @@ async function getActionInfo( const { attributes: { secrets }, - } = await encryptedSavedObjectsPlugin.getDecryptedAsInternalUser('action', actionId, { + } = await encryptedSavedObjectsClient.getDecryptedAsInternalUser('action', actionId, { namespace: namespace === 'default' ? undefined : namespace, }); diff --git a/x-pack/plugins/actions/server/lib/task_runner_factory.test.ts b/x-pack/plugins/actions/server/lib/task_runner_factory.test.ts index f070f714ee508d..42ccf5a33ebaa4 100644 --- a/x-pack/plugins/actions/server/lib/task_runner_factory.test.ts +++ b/x-pack/plugins/actions/server/lib/task_runner_factory.test.ts @@ -18,7 +18,7 @@ import { ActionTypeDisabledError } from './errors'; const spaceIdToNamespace = jest.fn(); const actionTypeRegistry = actionTypeRegistryMock.create(); -const mockedEncryptedSavedObjectsPlugin = encryptedSavedObjectsMock.createStart(); +const mockedEncryptedSavedObjectsClient = encryptedSavedObjectsMock.createClient(); const mockedActionExecutor = actionExecutorMock.create(); let fakeTimer: sinon.SinonFakeTimers; @@ -59,7 +59,7 @@ const actionExecutorInitializerParams = { logger: loggingServiceMock.create().get(), getServices: jest.fn().mockReturnValue(services), actionTypeRegistry, - encryptedSavedObjectsPlugin: mockedEncryptedSavedObjectsPlugin, + encryptedSavedObjectsClient: mockedEncryptedSavedObjectsClient, eventLogger: eventLoggerMock.create(), preconfiguredActions: [], }; @@ -67,7 +67,7 @@ const taskRunnerFactoryInitializerParams = { spaceIdToNamespace, actionTypeRegistry, logger: loggingServiceMock.create().get(), - encryptedSavedObjectsPlugin: mockedEncryptedSavedObjectsPlugin, + encryptedSavedObjectsClient: mockedEncryptedSavedObjectsClient, getBasePath: jest.fn().mockReturnValue(undefined), getScopedSavedObjectsClient: jest.fn().mockReturnValue(services.savedObjectsClient), }; @@ -106,7 +106,7 @@ test('executes the task by calling the executor with proper parameters', async ( mockedActionExecutor.execute.mockResolvedValueOnce({ status: 'ok', actionId: '2' }); spaceIdToNamespace.mockReturnValueOnce('namespace-test'); - mockedEncryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + mockedEncryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '3', type: 'action_task_params', attributes: { @@ -122,7 +122,7 @@ test('executes the task by calling the executor with proper parameters', async ( expect(runnerResult).toBeUndefined(); expect(spaceIdToNamespace).toHaveBeenCalledWith('test'); expect( - mockedEncryptedSavedObjectsPlugin.getDecryptedAsInternalUser + mockedEncryptedSavedObjectsClient.getDecryptedAsInternalUser ).toHaveBeenCalledWith('action_task_params', '3', { namespace: 'namespace-test' }); expect(mockedActionExecutor.execute).toHaveBeenCalledWith({ actionId: '2', @@ -154,7 +154,7 @@ test('cleans up action_task_params object', async () => { mockedActionExecutor.execute.mockResolvedValueOnce({ status: 'ok', actionId: '2' }); spaceIdToNamespace.mockReturnValueOnce('namespace-test'); - mockedEncryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + mockedEncryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '3', type: 'action_task_params', attributes: { @@ -177,7 +177,7 @@ test('runs successfully when cleanup fails and logs the error', async () => { mockedActionExecutor.execute.mockResolvedValueOnce({ status: 'ok', actionId: '2' }); spaceIdToNamespace.mockReturnValueOnce('namespace-test'); - mockedEncryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + mockedEncryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '3', type: 'action_task_params', attributes: { @@ -202,7 +202,7 @@ test('throws an error with suggested retry logic when return status is error', a taskInstance: mockedTaskInstance, }); - mockedEncryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + mockedEncryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '3', type: 'action_task_params', attributes: { @@ -237,7 +237,7 @@ test('uses API key when provided', async () => { mockedActionExecutor.execute.mockResolvedValueOnce({ status: 'ok', actionId: '2' }); spaceIdToNamespace.mockReturnValueOnce('namespace-test'); - mockedEncryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + mockedEncryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '3', type: 'action_task_params', attributes: { @@ -280,7 +280,7 @@ test(`doesn't use API key when not provided`, async () => { mockedActionExecutor.execute.mockResolvedValueOnce({ status: 'ok', actionId: '2' }); spaceIdToNamespace.mockReturnValueOnce('namespace-test'); - mockedEncryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + mockedEncryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '3', type: 'action_task_params', attributes: { @@ -317,7 +317,7 @@ test(`throws an error when license doesn't support the action type`, async () => taskInstance: mockedTaskInstance, }); - mockedEncryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + mockedEncryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '3', type: 'action_task_params', attributes: { diff --git a/x-pack/plugins/actions/server/lib/task_runner_factory.ts b/x-pack/plugins/actions/server/lib/task_runner_factory.ts index 08c5b90edbcb78..a962497f906a9a 100644 --- a/x-pack/plugins/actions/server/lib/task_runner_factory.ts +++ b/x-pack/plugins/actions/server/lib/task_runner_factory.ts @@ -8,7 +8,7 @@ import { ActionExecutorContract } from './action_executor'; import { ExecutorError } from './executor_error'; import { Logger, CoreStart, KibanaRequest } from '../../../../../src/core/server'; import { RunContext } from '../../../task_manager/server'; -import { EncryptedSavedObjectsPluginStart } from '../../../encrypted_saved_objects/server'; +import { EncryptedSavedObjectsClient } from '../../../encrypted_saved_objects/server'; import { ActionTypeDisabledError } from './errors'; import { ActionTaskParams, @@ -21,7 +21,7 @@ import { export interface TaskRunnerContext { logger: Logger; actionTypeRegistry: ActionTypeRegistryContract; - encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart; + encryptedSavedObjectsClient: EncryptedSavedObjectsClient; spaceIdToNamespace: SpaceIdToNamespaceFunction; getBasePath: GetBasePathFunction; getScopedSavedObjectsClient: CoreStart['savedObjects']['getScopedClient']; @@ -52,7 +52,7 @@ export class TaskRunnerFactory { const { actionExecutor } = this; const { logger, - encryptedSavedObjectsPlugin, + encryptedSavedObjectsClient, spaceIdToNamespace, getBasePath, getScopedSavedObjectsClient, @@ -65,7 +65,7 @@ export class TaskRunnerFactory { const { attributes: { actionId, params, apiKey }, - } = await encryptedSavedObjectsPlugin.getDecryptedAsInternalUser( + } = await encryptedSavedObjectsClient.getDecryptedAsInternalUser( 'action_task_params', actionTaskParamsId, { namespace } diff --git a/x-pack/plugins/actions/server/plugin.ts b/x-pack/plugins/actions/server/plugin.ts index bc7440c8bee4de..75e15815d0787f 100644 --- a/x-pack/plugins/actions/server/plugin.ts +++ b/x-pack/plugins/actions/server/plugin.ts @@ -232,12 +232,14 @@ export class ActionsPlugin implements Plugin, Plugi preconfiguredActions, } = this; + const encryptedSavedObjectsClient = plugins.encryptedSavedObjects.getClient(); + actionExecutor!.initialize({ logger, eventLogger: this.eventLogger!, spaces: this.spaces, getServices: this.getServicesFactory(core.savedObjects, core.elasticsearch), - encryptedSavedObjectsPlugin: plugins.encryptedSavedObjects, + encryptedSavedObjectsClient, actionTypeRegistry: actionTypeRegistry!, preconfiguredActions, }); @@ -245,7 +247,7 @@ export class ActionsPlugin implements Plugin, Plugi taskRunnerFactory!.initialize({ logger, actionTypeRegistry: actionTypeRegistry!, - encryptedSavedObjectsPlugin: plugins.encryptedSavedObjects, + encryptedSavedObjectsClient, getBasePath: this.getBasePath, spaceIdToNamespace: this.spaceIdToNamespace, getScopedSavedObjectsClient: core.savedObjects.getScopedClient, diff --git a/x-pack/plugins/alerting/server/alerts_client.test.ts b/x-pack/plugins/alerting/server/alerts_client.test.ts index 6601ccc4f5a73b..93b98f6a0fe037 100644 --- a/x-pack/plugins/alerting/server/alerts_client.test.ts +++ b/x-pack/plugins/alerting/server/alerts_client.test.ts @@ -17,7 +17,7 @@ import { encryptedSavedObjectsMock } from '../../../plugins/encrypted_saved_obje const taskManager = taskManagerMock.start(); const alertTypeRegistry = alertTypeRegistryMock.create(); const savedObjectsClient = savedObjectsClientMock.create(); -const encryptedSavedObjects = encryptedSavedObjectsMock.createStart(); +const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); const alertsClientParams = { taskManager, @@ -29,7 +29,7 @@ const alertsClientParams = { createAPIKey: jest.fn(), invalidateAPIKey: jest.fn(), logger: loggingServiceMock.create().get(), - encryptedSavedObjectsPlugin: encryptedSavedObjects, + encryptedSavedObjectsClient: encryptedSavedObjects, preconfiguredActions: [], }; diff --git a/x-pack/plugins/alerting/server/alerts_client.ts b/x-pack/plugins/alerting/server/alerts_client.ts index ff501055ba9fe9..01687f33f631d4 100644 --- a/x-pack/plugins/alerting/server/alerts_client.ts +++ b/x-pack/plugins/alerting/server/alerts_client.ts @@ -32,7 +32,7 @@ import { GrantAPIKeyResult as SecurityPluginGrantAPIKeyResult, InvalidateAPIKeyResult as SecurityPluginInvalidateAPIKeyResult, } from '../../../plugins/security/server'; -import { EncryptedSavedObjectsPluginStart } from '../../../plugins/encrypted_saved_objects/server'; +import { EncryptedSavedObjectsClient } from '../../../plugins/encrypted_saved_objects/server'; import { TaskManagerStartContract } from '../../../plugins/task_manager/server'; import { taskInstanceToAlertTaskInstance } from './task_runner/alert_task_instance'; import { deleteTaskIfItExists } from './lib/delete_task_if_it_exists'; @@ -50,7 +50,7 @@ interface ConstructorOptions { taskManager: TaskManagerStartContract; savedObjectsClient: SavedObjectsClientContract; alertTypeRegistry: AlertTypeRegistry; - encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart; + encryptedSavedObjectsClient: EncryptedSavedObjectsClient; spaceId?: string; namespace?: string; getUserName: () => Promise; @@ -128,7 +128,7 @@ export class AlertsClient { params: InvalidateAPIKeyParams ) => Promise; private preconfiguredActions: PreConfiguredAction[]; - encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart; + encryptedSavedObjectsClient: EncryptedSavedObjectsClient; constructor({ alertTypeRegistry, @@ -140,7 +140,7 @@ export class AlertsClient { getUserName, createAPIKey, invalidateAPIKey, - encryptedSavedObjectsPlugin, + encryptedSavedObjectsClient, preconfiguredActions, }: ConstructorOptions) { this.logger = logger; @@ -152,7 +152,7 @@ export class AlertsClient { this.savedObjectsClient = savedObjectsClient; this.createAPIKey = createAPIKey; this.invalidateAPIKey = invalidateAPIKey; - this.encryptedSavedObjectsPlugin = encryptedSavedObjectsPlugin; + this.encryptedSavedObjectsClient = encryptedSavedObjectsClient; this.preconfiguredActions = preconfiguredActions; } @@ -252,7 +252,7 @@ export class AlertsClient { let apiKeyToInvalidate: string | null = null; try { - const decryptedAlert = await this.encryptedSavedObjectsPlugin.getDecryptedAsInternalUser< + const decryptedAlert = await this.encryptedSavedObjectsClient.getDecryptedAsInternalUser< RawAlert >('alert', id, { namespace: this.namespace }); apiKeyToInvalidate = decryptedAlert.attributes.apiKey; @@ -281,7 +281,7 @@ export class AlertsClient { let alertSavedObject: SavedObject; try { - alertSavedObject = await this.encryptedSavedObjectsPlugin.getDecryptedAsInternalUser< + alertSavedObject = await this.encryptedSavedObjectsClient.getDecryptedAsInternalUser< RawAlert >('alert', id, { namespace: this.namespace }); } catch (e) { @@ -377,7 +377,7 @@ export class AlertsClient { let version: string | undefined; try { - const decryptedAlert = await this.encryptedSavedObjectsPlugin.getDecryptedAsInternalUser< + const decryptedAlert = await this.encryptedSavedObjectsClient.getDecryptedAsInternalUser< RawAlert >('alert', id, { namespace: this.namespace }); apiKeyToInvalidate = decryptedAlert.attributes.apiKey; @@ -435,7 +435,7 @@ export class AlertsClient { let version: string | undefined; try { - const decryptedAlert = await this.encryptedSavedObjectsPlugin.getDecryptedAsInternalUser< + const decryptedAlert = await this.encryptedSavedObjectsClient.getDecryptedAsInternalUser< RawAlert >('alert', id, { namespace: this.namespace }); apiKeyToInvalidate = decryptedAlert.attributes.apiKey; @@ -479,7 +479,7 @@ export class AlertsClient { let version: string | undefined; try { - const decryptedAlert = await this.encryptedSavedObjectsPlugin.getDecryptedAsInternalUser< + const decryptedAlert = await this.encryptedSavedObjectsClient.getDecryptedAsInternalUser< RawAlert >('alert', id, { namespace: this.namespace }); apiKeyToInvalidate = decryptedAlert.attributes.apiKey; @@ -543,7 +543,7 @@ export class AlertsClient { alertId: string; alertInstanceId: string; }) { - const { attributes, version } = await this.savedObjectsClient.get('alert', alertId); + const { attributes, version } = await this.savedObjectsClient.get('alert', alertId); const mutedInstanceIds = attributes.mutedInstanceIds || []; if (!attributes.muteAll && !mutedInstanceIds.includes(alertInstanceId)) { mutedInstanceIds.push(alertInstanceId); @@ -566,7 +566,7 @@ export class AlertsClient { alertId: string; alertInstanceId: string; }) { - const { attributes, version } = await this.savedObjectsClient.get('alert', alertId); + const { attributes, version } = await this.savedObjectsClient.get('alert', alertId); const mutedInstanceIds = attributes.mutedInstanceIds || []; if (!attributes.muteAll && mutedInstanceIds.includes(alertInstanceId)) { await this.savedObjectsClient.update( diff --git a/x-pack/plugins/alerting/server/alerts_client_factory.test.ts b/x-pack/plugins/alerting/server/alerts_client_factory.test.ts index e5aa0a674eccf4..cc792d11c890dd 100644 --- a/x-pack/plugins/alerting/server/alerts_client_factory.test.ts +++ b/x-pack/plugins/alerting/server/alerts_client_factory.test.ts @@ -24,7 +24,7 @@ const alertsClientFactoryParams: jest.Mocked = { alertTypeRegistry: alertTypeRegistryMock.create(), getSpaceId: jest.fn(), spaceIdToNamespace: jest.fn(), - encryptedSavedObjectsPlugin: encryptedSavedObjectsMock.createStart(), + encryptedSavedObjectsClient: encryptedSavedObjectsMock.createClient(), preconfiguredActions: [], }; const fakeRequest = ({ @@ -64,7 +64,7 @@ test('creates an alerts client with proper constructor arguments', async () => { getUserName: expect.any(Function), createAPIKey: expect.any(Function), invalidateAPIKey: expect.any(Function), - encryptedSavedObjectsPlugin: alertsClientFactoryParams.encryptedSavedObjectsPlugin, + encryptedSavedObjectsClient: alertsClientFactoryParams.encryptedSavedObjectsClient, preconfiguredActions: [], }); }); diff --git a/x-pack/plugins/alerting/server/alerts_client_factory.ts b/x-pack/plugins/alerting/server/alerts_client_factory.ts index 734417e72733e3..913b4e2e81fe14 100644 --- a/x-pack/plugins/alerting/server/alerts_client_factory.ts +++ b/x-pack/plugins/alerting/server/alerts_client_factory.ts @@ -9,7 +9,7 @@ import { AlertsClient } from './alerts_client'; import { AlertTypeRegistry, SpaceIdToNamespaceFunction } from './types'; import { KibanaRequest, Logger, SavedObjectsClientContract } from '../../../../src/core/server'; import { InvalidateAPIKeyParams, SecurityPluginSetup } from '../../../plugins/security/server'; -import { EncryptedSavedObjectsPluginStart } from '../../../plugins/encrypted_saved_objects/server'; +import { EncryptedSavedObjectsClient } from '../../../plugins/encrypted_saved_objects/server'; import { TaskManagerStartContract } from '../../../plugins/task_manager/server'; export interface AlertsClientFactoryOpts { @@ -19,7 +19,7 @@ export interface AlertsClientFactoryOpts { securityPluginSetup?: SecurityPluginSetup; getSpaceId: (request: KibanaRequest) => string | undefined; spaceIdToNamespace: SpaceIdToNamespaceFunction; - encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart; + encryptedSavedObjectsClient: EncryptedSavedObjectsClient; preconfiguredActions: PreConfiguredAction[]; } @@ -31,7 +31,7 @@ export class AlertsClientFactory { private securityPluginSetup?: SecurityPluginSetup; private getSpaceId!: (request: KibanaRequest) => string | undefined; private spaceIdToNamespace!: SpaceIdToNamespaceFunction; - private encryptedSavedObjectsPlugin!: EncryptedSavedObjectsPluginStart; + private encryptedSavedObjectsClient!: EncryptedSavedObjectsClient; private preconfiguredActions!: PreConfiguredAction[]; public initialize(options: AlertsClientFactoryOpts) { @@ -45,7 +45,7 @@ export class AlertsClientFactory { this.alertTypeRegistry = options.alertTypeRegistry; this.securityPluginSetup = options.securityPluginSetup; this.spaceIdToNamespace = options.spaceIdToNamespace; - this.encryptedSavedObjectsPlugin = options.encryptedSavedObjectsPlugin; + this.encryptedSavedObjectsClient = options.encryptedSavedObjectsClient; this.preconfiguredActions = options.preconfiguredActions; } @@ -62,7 +62,7 @@ export class AlertsClientFactory { alertTypeRegistry: this.alertTypeRegistry, savedObjectsClient, namespace: this.spaceIdToNamespace(spaceId), - encryptedSavedObjectsPlugin: this.encryptedSavedObjectsPlugin, + encryptedSavedObjectsClient: this.encryptedSavedObjectsClient, async getUserName() { if (!securityPluginSetup) { return null; diff --git a/x-pack/plugins/alerting/server/plugin.test.ts b/x-pack/plugins/alerting/server/plugin.test.ts index 267e68930a5d7a..0411899290ab2d 100644 --- a/x-pack/plugins/alerting/server/plugin.test.ts +++ b/x-pack/plugins/alerting/server/plugin.test.ts @@ -81,6 +81,7 @@ describe('Alerting Plugin', () => { execute: jest.fn(), getActionsClientWithRequest: jest.fn(), }, + encryptedSavedObjects: encryptedSavedObjectsMock.createStart(), } as unknown) as AlertingPluginsStart ); @@ -125,6 +126,7 @@ describe('Alerting Plugin', () => { getActionsClientWithRequest: jest.fn(), }, spaces: () => null, + encryptedSavedObjects: encryptedSavedObjectsMock.createStart(), } as unknown) as AlertingPluginsStart ); diff --git a/x-pack/plugins/alerting/server/plugin.ts b/x-pack/plugins/alerting/server/plugin.ts index 7bd515616a3c11..08353656359905 100644 --- a/x-pack/plugins/alerting/server/plugin.ts +++ b/x-pack/plugins/alerting/server/plugin.ts @@ -201,12 +201,14 @@ export class AlertingPlugin { security, } = this; + const encryptedSavedObjectsClient = plugins.encryptedSavedObjects.getClient(); + alertsClientFactory.initialize({ alertTypeRegistry: alertTypeRegistry!, logger, taskManager: plugins.taskManager, securityPluginSetup: security, - encryptedSavedObjectsPlugin: plugins.encryptedSavedObjects, + encryptedSavedObjectsClient, spaceIdToNamespace: this.spaceIdToNamespace, getSpaceId(request: KibanaRequest) { return spaces?.getSpaceId(request); @@ -219,7 +221,7 @@ export class AlertingPlugin { getServices: this.getServicesFactory(core.savedObjects, core.elasticsearch), spaceIdToNamespace: this.spaceIdToNamespace, actionsPlugin: plugins.actions, - encryptedSavedObjectsPlugin: plugins.encryptedSavedObjects, + encryptedSavedObjectsClient, getBasePath: this.getBasePath, eventLogger: this.eventLogger!, }); diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts b/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts index e5ec8f587b9d7f..98824b8cf4e1a4 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts @@ -54,7 +54,7 @@ describe('Task Runner', () => { afterAll(() => fakeTimer.restore()); - const encryptedSavedObjectsPlugin = encryptedSavedObjectsMock.createStart(); + const encryptedSavedObjectsClient = encryptedSavedObjectsMock.createClient(); const services = alertsMock.createAlertServices(); const savedObjectsClient = services.savedObjectsClient; @@ -64,7 +64,7 @@ describe('Task Runner', () => { } = { getServices: jest.fn().mockReturnValue(services), actionsPlugin: actionsMock.createStart(), - encryptedSavedObjectsPlugin, + encryptedSavedObjectsClient, logger: loggingServiceMock.create().get(), spaceIdToNamespace: jest.fn().mockReturnValue(undefined), getBasePath: jest.fn().mockReturnValue(undefined), @@ -123,7 +123,7 @@ describe('Task Runner', () => { taskRunnerFactoryInitializerParams ); savedObjectsClient.get.mockResolvedValueOnce(mockedAlertTypeSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '1', type: 'alert', attributes: { @@ -197,7 +197,7 @@ describe('Task Runner', () => { taskRunnerFactoryInitializerParams ); savedObjectsClient.get.mockResolvedValueOnce(mockedAlertTypeSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '1', type: 'alert', attributes: { @@ -316,7 +316,7 @@ describe('Task Runner', () => { taskRunnerFactoryInitializerParams ); savedObjectsClient.get.mockResolvedValueOnce(mockedAlertTypeSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '1', type: 'alert', attributes: { @@ -403,7 +403,7 @@ describe('Task Runner', () => { taskRunnerFactoryInitializerParams ); savedObjectsClient.get.mockResolvedValueOnce(mockedAlertTypeSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '1', type: 'alert', attributes: { @@ -434,7 +434,7 @@ describe('Task Runner', () => { ...mockedAlertTypeSavedObject, references: [], }); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '1', type: 'alert', attributes: { @@ -462,7 +462,7 @@ describe('Task Runner', () => { taskRunnerFactoryInitializerParams ); savedObjectsClient.get.mockResolvedValueOnce(mockedAlertTypeSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '1', type: 'alert', attributes: { @@ -498,7 +498,7 @@ describe('Task Runner', () => { taskRunnerFactoryInitializerParams ); savedObjectsClient.get.mockResolvedValueOnce(mockedAlertTypeSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '1', type: 'alert', attributes: {}, @@ -537,7 +537,7 @@ describe('Task Runner', () => { ); savedObjectsClient.get.mockResolvedValueOnce(mockedAlertTypeSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '1', type: 'alert', attributes: { @@ -588,7 +588,7 @@ describe('Task Runner', () => { }); test('recovers gracefully when the Alert Task Runner throws an exception when fetching the encrypted attributes', async () => { - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockImplementation(() => { + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockImplementation(() => { throw new Error('OMG'); }); @@ -624,7 +624,7 @@ describe('Task Runner', () => { ); savedObjectsClient.get.mockResolvedValueOnce(mockedAlertTypeSavedObject); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '1', type: 'alert', attributes: { @@ -656,7 +656,7 @@ describe('Task Runner', () => { taskRunnerFactoryInitializerParams ); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '1', type: 'alert', attributes: { @@ -688,7 +688,7 @@ describe('Task Runner', () => { taskRunnerFactoryInitializerParams ); - encryptedSavedObjectsPlugin.getDecryptedAsInternalUser.mockResolvedValueOnce({ + encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({ id: '1', type: 'alert', attributes: { diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner.ts b/x-pack/plugins/alerting/server/task_runner/task_runner.ts index bf005301adc07c..a36152fa17544f 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner.ts @@ -62,7 +62,7 @@ export class TaskRunner { // scoped with the API key to fetch the remaining data. const { attributes: { apiKey }, - } = await this.context.encryptedSavedObjectsPlugin.getDecryptedAsInternalUser( + } = await this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser( 'alert', alertId, { namespace } diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts b/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts index 96d89bebcc66f3..c1318bac48dfbc 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts @@ -56,7 +56,7 @@ describe('Task Runner Factory', () => { const taskRunnerFactoryInitializerParams: jest.Mocked = { getServices: jest.fn().mockReturnValue(services), actionsPlugin: actionsMock.createStart(), - encryptedSavedObjectsPlugin, + encryptedSavedObjectsClient: encryptedSavedObjectsPlugin.getClient(), logger: loggingServiceMock.create().get(), spaceIdToNamespace: jest.fn().mockReturnValue(undefined), getBasePath: jest.fn().mockReturnValue(undefined), diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner_factory.ts b/x-pack/plugins/alerting/server/task_runner/task_runner_factory.ts index b58db8c74f7bba..c50e288d2e5203 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner_factory.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner_factory.ts @@ -5,7 +5,7 @@ */ import { Logger } from '../../../../../src/core/server'; import { RunContext } from '../../../../plugins/task_manager/server'; -import { EncryptedSavedObjectsPluginStart } from '../../../../plugins/encrypted_saved_objects/server'; +import { EncryptedSavedObjectsClient } from '../../../../plugins/encrypted_saved_objects/server'; import { PluginStartContract as ActionsPluginStartContract } from '../../../../plugins/actions/server'; import { AlertType, @@ -21,7 +21,7 @@ export interface TaskRunnerContext { getServices: GetServicesFunction; actionsPlugin: ActionsPluginStartContract; eventLogger: IEventLogger; - encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart; + encryptedSavedObjectsClient: EncryptedSavedObjectsClient; spaceIdToNamespace: SpaceIdToNamespaceFunction; getBasePath: GetBasePathFunction; } diff --git a/x-pack/plugins/encrypted_saved_objects/server/index.ts b/x-pack/plugins/encrypted_saved_objects/server/index.ts index 3b4b91de355c74..c8f7acf952c222 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/index.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/index.ts @@ -10,6 +10,7 @@ import { Plugin } from './plugin'; export { EncryptedSavedObjectTypeRegistration, EncryptionError } from './crypto'; export { EncryptedSavedObjectsPluginSetup, EncryptedSavedObjectsPluginStart } from './plugin'; +export { EncryptedSavedObjectsClient } from './saved_objects'; export const config = { schema: ConfigSchema }; export const plugin = (initializerContext: PluginInitializerContext) => diff --git a/x-pack/plugins/encrypted_saved_objects/server/mocks.ts b/x-pack/plugins/encrypted_saved_objects/server/mocks.ts index f797b49e633703..efa975e81ea936 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/mocks.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/mocks.ts @@ -5,6 +5,7 @@ */ import { EncryptedSavedObjectsPluginSetup, EncryptedSavedObjectsPluginStart } from './plugin'; +import { EncryptedSavedObjectsClient } from './saved_objects'; function createEncryptedSavedObjectsSetupMock() { return { @@ -18,11 +19,18 @@ function createEncryptedSavedObjectsSetupMock() { function createEncryptedSavedObjectsStartMock() { return { isEncryptionError: jest.fn(), - getDecryptedAsInternalUser: jest.fn(), + getClient: jest.fn(() => createEncryptedSavedObjectsClienttMock()), } as jest.Mocked; } +function createEncryptedSavedObjectsClienttMock() { + return { + getDecryptedAsInternalUser: jest.fn(), + } as jest.Mocked; +} + export const encryptedSavedObjectsMock = { createSetup: createEncryptedSavedObjectsSetupMock, createStart: createEncryptedSavedObjectsStartMock, + createClient: createEncryptedSavedObjectsClienttMock, }; diff --git a/x-pack/plugins/encrypted_saved_objects/server/plugin.test.ts b/x-pack/plugins/encrypted_saved_objects/server/plugin.test.ts index fdf00609097985..e8568e9964c2f0 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/plugin.test.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/plugin.test.ts @@ -20,34 +20,28 @@ describe('EncryptedSavedObjects Plugin', () => { "registerLegacyAPI": [Function], }, "registerType": [Function], - "startWithHiddenTypes": [Function], "usingEphemeralEncryptionKey": true, } `); }); + }); - it('exposes a start contract with included hidden types', async () => { + describe('start()', () => { + it('exposes proper contract', async () => { const plugin = new Plugin(coreMock.createPluginInitializerContext()); - const startApiWithHiddenTypes = ( - await plugin.setup(coreMock.createSetup(), { security: securityMock.createSetup() }) - ).startWithHiddenTypes(['hiddenType']); - expect(startApiWithHiddenTypes).toMatchInlineSnapshot(` + await plugin.setup(coreMock.createSetup(), { security: securityMock.createSetup() }); + + const startContract = plugin.start(); + await expect(startContract).toMatchInlineSnapshot(` Object { - "getDecryptedAsInternalUser": [Function], + "getClient": [Function], "isEncryptionError": [Function], } `); - }); - }); - describe('start()', () => { - it('exposes proper contract', async () => { - const plugin = new Plugin(coreMock.createPluginInitializerContext()); - await plugin.setup(coreMock.createSetup(), { security: securityMock.createSetup() }); - await expect(plugin.start()).toMatchInlineSnapshot(` + expect(startContract.getClient()).toMatchInlineSnapshot(` Object { "getDecryptedAsInternalUser": [Function], - "isEncryptionError": [Function], } `); }); diff --git a/x-pack/plugins/encrypted_saved_objects/server/plugin.ts b/x-pack/plugins/encrypted_saved_objects/server/plugin.ts index 865d678cc035e6..948cb94512f2c0 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/plugin.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/plugin.ts @@ -24,11 +24,11 @@ export interface EncryptedSavedObjectsPluginSetup { registerType: (typeRegistration: EncryptedSavedObjectTypeRegistration) => void; __legacyCompat: { registerLegacyAPI: (legacyAPI: LegacyAPI) => void }; usingEphemeralEncryptionKey: boolean; - startWithHiddenTypes: (includedHiddenTypes: string[]) => EncryptedSavedObjectsPluginStart; } -export interface EncryptedSavedObjectsPluginStart extends ReturnType { +export interface EncryptedSavedObjectsPluginStart { isEncryptionError: (error: Error) => boolean; + getClient: SavedObjectsSetup; } /** @@ -88,21 +88,14 @@ export class Plugin { service.registerType(typeRegistration), __legacyCompat: { registerLegacyAPI: (legacyAPI: LegacyAPI) => (this.legacyAPI = legacyAPI) }, usingEphemeralEncryptionKey, - startWithHiddenTypes: (includedHiddenTypes: string[]) => - this.createStartApi(includedHiddenTypes), }; } public start() { this.logger.debug('Starting plugin'); - return this.createStartApi(); - } - - private createStartApi(includedHiddenTypes?: string[]) { - const { getDecryptedAsInternalUser } = this.savedObjectsSetup(includedHiddenTypes); return { isEncryptionError: (error: Error) => error instanceof EncryptionError, - getDecryptedAsInternalUser, + getClient: (includedHiddenTypes?: string[]) => this.savedObjectsSetup(includedHiddenTypes), }; } diff --git a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/index.ts b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/index.ts index dadeaf92e145c8..67bbaab75425ab 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/index.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/index.ts @@ -23,15 +23,15 @@ interface SetupSavedObjectsParams { getStartServices: StartServicesAccessor; } -export type SavedObjectsSetup = ( - includedHiddenTypes?: string[] -) => { +export type SavedObjectsSetup = (includedHiddenTypes?: string[]) => EncryptedSavedObjectsClient; + +export interface EncryptedSavedObjectsClient { getDecryptedAsInternalUser: ( type: string, id: string, options?: SavedObjectsBaseOptions ) => Promise>; -}; +} export function setupSavedObjects({ service, diff --git a/x-pack/plugins/ingest_manager/server/services/agents/acks.test.ts b/x-pack/plugins/ingest_manager/server/services/agents/acks.test.ts index ae0dedce178a81..0d22529fdb0312 100644 --- a/x-pack/plugins/ingest_manager/server/services/agents/acks.test.ts +++ b/x-pack/plugins/ingest_manager/server/services/agents/acks.test.ts @@ -22,11 +22,15 @@ import { IngestManagerAppContext } from '../../plugin'; describe('test agent acks services', () => { it('should succeed on valid and matched actions', async () => { const mockSavedObjectsClient = savedObjectsClientMock.create(); - const mockStartEncryptedSOClient = encryptedSavedObjectsMock.createStart(); + const mockStartEncryptedSOPlugin = encryptedSavedObjectsMock.createStart(); appContextService.start(({ - encryptedSavedObjects: mockStartEncryptedSOClient, + encryptedSavedObjects: mockStartEncryptedSOPlugin, } as unknown) as IngestManagerAppContext); + const [ + { value: mockStartEncryptedSOClient }, + ] = mockStartEncryptedSOPlugin.getClient.mock.results; + mockStartEncryptedSOClient.getDecryptedAsInternalUser.mockReturnValue( Promise.resolve({ id: 'action1', diff --git a/x-pack/plugins/ingest_manager/server/services/app_context.ts b/x-pack/plugins/ingest_manager/server/services/app_context.ts index 91b09d651bf5cd..9e6220b6958f17 100644 --- a/x-pack/plugins/ingest_manager/server/services/app_context.ts +++ b/x-pack/plugins/ingest_manager/server/services/app_context.ts @@ -6,14 +6,14 @@ import { BehaviorSubject, Observable } from 'rxjs'; import { first } from 'rxjs/operators'; import { SavedObjectsServiceStart, HttpServiceSetup, Logger } from 'src/core/server'; -import { EncryptedSavedObjectsPluginStart } from '../../../encrypted_saved_objects/server'; +import { EncryptedSavedObjectsClient } from '../../../encrypted_saved_objects/server'; import { SecurityPluginSetup } from '../../../security/server'; import { IngestManagerConfigType } from '../../common'; import { IngestManagerAppContext } from '../plugin'; import { CloudSetup } from '../../../cloud/server'; class AppContextService { - private encryptedSavedObjects: EncryptedSavedObjectsPluginStart | undefined; + private encryptedSavedObjects: EncryptedSavedObjectsClient | undefined; private security: SecurityPluginSetup | undefined; private config$?: Observable; private configSubject$?: BehaviorSubject; @@ -25,7 +25,7 @@ class AppContextService { private httpSetup?: HttpServiceSetup; public async start(appContext: IngestManagerAppContext) { - this.encryptedSavedObjects = appContext.encryptedSavedObjects; + this.encryptedSavedObjects = appContext.encryptedSavedObjects?.getClient(); this.security = appContext.security; this.savedObjects = appContext.savedObjects; this.isProductionMode = appContext.isProductionMode; diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/aad/server/plugin.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/aad/server/plugin.ts index 0e9c71d8c20c81..4908b3338a10ab 100644 --- a/x-pack/test/alerting_api_integration/common/fixtures/plugins/aad/server/plugin.ts +++ b/x-pack/test/alerting_api_integration/common/fixtures/plugins/aad/server/plugin.ts @@ -48,9 +48,11 @@ export class FixturePlugin implements Plugin = try { return response.ok({ - body: await encryptedSavedObjects.getDecryptedAsInternalUser( - request.params.type, - request.params.id, - { namespace } - ), + body: await encryptedSavedObjects + .getClient() + .getDecryptedAsInternalUser(request.params.type, request.params.id, { namespace }), }); } catch (err) { if (encryptedSavedObjects.isEncryptionError(err)) {