From 5e3dfaa3e36712807d760cebcbff8c8c83a6167a Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Thu, 12 Mar 2020 12:10:53 -0700 Subject: [PATCH] PR feedback --- .../ingest_manager/server/services/agent_config.ts | 8 ++++++++ .../ingest_manager/server/services/agent_config_update.ts | 6 +++--- .../ingest_manager/server/services/agents/update.ts | 4 ++-- .../plugins/ingest_manager/server/services/datasource.ts | 6 +++--- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/ingest_manager/server/services/agent_config.ts b/x-pack/plugins/ingest_manager/server/services/agent_config.ts index 5b99e0eee586d..cafef4c49c798 100644 --- a/x-pack/plugins/ingest_manager/server/services/agent_config.ts +++ b/x-pack/plugins/ingest_manager/server/services/agent_config.ts @@ -175,6 +175,14 @@ class AgentConfigService { return this._update(soClient, id, agentConfig, options?.user); } + public async bumpRevision( + soClient: SavedObjectsClientContract, + id: string, + options?: { user?: AuthenticatedUser } + ): Promise { + return this._update(soClient, id, {}, options?.user); + } + public async assignDatasources( soClient: SavedObjectsClientContract, id: string, diff --git a/x-pack/plugins/ingest_manager/server/services/agent_config_update.ts b/x-pack/plugins/ingest_manager/server/services/agent_config_update.ts index c0a40ffbe034a..38894ff321a0b 100644 --- a/x-pack/plugins/ingest_manager/server/services/agent_config_update.ts +++ b/x-pack/plugins/ingest_manager/server/services/agent_config_update.ts @@ -6,7 +6,7 @@ import { SavedObjectsClientContract } from 'kibana/server'; import { generateEnrollmentAPIKey, deleteEnrollmentApiKeyForConfigId } from './api_keys'; -import { updateAgentsForPolicyId, unenrollForPolicyId } from './agents'; +import { updateAgentsForConfigId, unenrollForConfigId } from './agents'; export async function agentConfigUpdateEventHandler( soClient: SavedObjectsClientContract, @@ -20,11 +20,11 @@ export async function agentConfigUpdateEventHandler( } if (action === 'updated') { - await updateAgentsForPolicyId(soClient, configId); + await updateAgentsForConfigId(soClient, configId); } if (action === 'deleted') { - await unenrollForPolicyId(soClient, configId); + await unenrollForConfigId(soClient, configId); await deleteEnrollmentApiKeyForConfigId(soClient, configId); } } diff --git a/x-pack/plugins/ingest_manager/server/services/agents/update.ts b/x-pack/plugins/ingest_manager/server/services/agents/update.ts index 152a51ae519bf..8452c05d53a1f 100644 --- a/x-pack/plugins/ingest_manager/server/services/agents/update.ts +++ b/x-pack/plugins/ingest_manager/server/services/agents/update.ts @@ -9,7 +9,7 @@ import { listAgents } from './crud'; import { AGENT_SAVED_OBJECT_TYPE } from '../../constants'; import { unenrollAgents } from './unenroll'; -export async function updateAgentsForPolicyId( +export async function updateAgentsForConfigId( soClient: SavedObjectsClientContract, configId: string ) { @@ -37,7 +37,7 @@ export async function updateAgentsForPolicyId( } } -export async function unenrollForPolicyId(soClient: SavedObjectsClientContract, configId: string) { +export async function unenrollForConfigId(soClient: SavedObjectsClientContract, configId: string) { let hasMore = true; let page = 1; while (hasMore) { diff --git a/x-pack/plugins/ingest_manager/server/services/datasource.ts b/x-pack/plugins/ingest_manager/server/services/datasource.ts index c5ed66b45d4b2..615b29087ba1e 100644 --- a/x-pack/plugins/ingest_manager/server/services/datasource.ts +++ b/x-pack/plugins/ingest_manager/server/services/datasource.ts @@ -18,12 +18,12 @@ class DatasourceService { datasource: NewDatasource, options?: { id?: string; user?: AuthenticatedUser } ): Promise { - const newSo = await soClient.create( + const newSo = await soClient.create>( SAVED_OBJECT_TYPE, { ...datasource, revision: 1, - } as Datasource, + }, options ); @@ -124,7 +124,7 @@ class DatasourceService { }); // Bump revision of associated agent config - await agentConfigService.update(soClient, datasource.config_id, {}, { user: options?.user }); + await agentConfigService.bumpRevision(soClient, datasource.config_id, { user: options?.user }); return (await this.get(soClient, id)) as Datasource; }