[Ingest Manager] Do not bumb config revision during config creation (#72270)

This commit is contained in:
Nicolas Chaulet 2020-07-20 08:53:09 -04:00 committed by GitHub
parent 9504c9453b
commit bf89b3cdd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 7 deletions

View file

@ -135,6 +135,7 @@ export const createAgentConfigHandler: RequestHandler<
newSysPackageConfig.namespace = agentConfig.namespace;
await packageConfigService.create(soClient, callCluster, newSysPackageConfig, {
user,
bumpConfigRevision: false,
});
}

View file

@ -41,7 +41,8 @@ class AgentConfigService {
soClient: SavedObjectsClientContract,
id: string,
agentConfig: Partial<AgentConfigSOAttributes>,
user?: AuthenticatedUser
user?: AuthenticatedUser,
options: { bumpRevision: boolean } = { bumpRevision: true }
): Promise<AgentConfig> {
const oldAgentConfig = await this.get(soClient, id, false);
@ -60,7 +61,7 @@ class AgentConfigService {
await soClient.update<AgentConfigSOAttributes>(SAVED_OBJECT_TYPE, id, {
...agentConfig,
revision: oldAgentConfig.revision + 1,
...(options.bumpRevision ? { revision: oldAgentConfig.revision + 1 } : {}),
updated_at: new Date().toISOString(),
updated_by: user ? user.username : 'system',
});
@ -265,7 +266,7 @@ class AgentConfigService {
soClient: SavedObjectsClientContract,
id: string,
packageConfigIds: string[],
options?: { user?: AuthenticatedUser }
options: { user?: AuthenticatedUser; bumpRevision: boolean } = { bumpRevision: true }
): Promise<AgentConfig> {
const oldAgentConfig = await this.get(soClient, id, false);
@ -281,7 +282,8 @@ class AgentConfigService {
[...((oldAgentConfig.package_configs || []) as string[])].concat(packageConfigIds)
),
},
options?.user
options?.user,
{ bumpRevision: options.bumpRevision }
);
}

View file

@ -42,7 +42,7 @@ class PackageConfigService {
soClient: SavedObjectsClientContract,
callCluster: CallESAsCurrentUser,
packageConfig: NewPackageConfig,
options?: { id?: string; user?: AuthenticatedUser }
options?: { id?: string; user?: AuthenticatedUser; bumpConfigRevision?: boolean }
): Promise<PackageConfig> {
// Check that its agent config does not have a package config with the same name
const parentAgentConfig = await agentConfigService.get(soClient, packageConfig.config_id);
@ -104,6 +104,7 @@ class PackageConfigService {
// Assign it to the given agent config
await agentConfigService.assignPackageConfigs(soClient, packageConfig.config_id, [newSo.id], {
user: options?.user,
bumpRevision: options?.bumpConfigRevision ?? true,
});
return {
@ -117,7 +118,7 @@ class PackageConfigService {
soClient: SavedObjectsClientContract,
packageConfigs: NewPackageConfig[],
configId: string,
options?: { user?: AuthenticatedUser }
options?: { user?: AuthenticatedUser; bumpConfigRevision?: boolean }
): Promise<PackageConfig[]> {
const isoDate = new Date().toISOString();
const { saved_objects: newSos } = await soClient.bulkCreate<PackageConfigSOAttributes>(
@ -142,6 +143,7 @@ class PackageConfigService {
newSos.map((newSo) => newSo.id),
{
user: options?.user,
bumpRevision: options?.bumpConfigRevision ?? true,
}
);

View file

@ -218,5 +218,7 @@ async function addPackageToConfig(
config.namespace
);
await packageConfigService.create(soClient, callCluster, newPackageConfig);
await packageConfigService.create(soClient, callCluster, newPackageConfig, {
bumpConfigRevision: false,
});
}