Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Mar 12, 2020
1 parent b68e0ab commit 5e3dfaa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
8 changes: 8 additions & 0 deletions x-pack/plugins/ingest_manager/server/services/agent_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AgentConfig> {
return this._update(soClient, id, {}, options?.user);
}

public async assignDatasources(
soClient: SavedObjectsClientContract,
id: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/ingest_manager/server/services/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class DatasourceService {
datasource: NewDatasource,
options?: { id?: string; user?: AuthenticatedUser }
): Promise<Datasource> {
const newSo = await soClient.create<Datasource>(
const newSo = await soClient.create<Omit<Datasource, 'id'>>(
SAVED_OBJECT_TYPE,
{
...datasource,
revision: 1,
} as Datasource,
},
options
);

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 5e3dfaa

Please sign in to comment.