Skip to content

Commit

Permalink
Removes version bump logic and adds migration of version to revision …
Browse files Browse the repository at this point in the history
…for security rules
  • Loading branch information
spong committed Mar 10, 2023
1 parent d2366cf commit 689648b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import { SavedObjectUnsanitizedDoc } from '@kbn/core-saved-objects-server';
import { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server';
import { v4 as uuidv4 } from 'uuid';
import { createEsoMigration, pipeMigrations } from '../utils';
import { createEsoMigration, isDetectionEngineAADRuleType, pipeMigrations } from '../utils';
import { RawRule } from '../../../types';

function addRevision(doc: SavedObjectUnsanitizedDoc<RawRule>): SavedObjectUnsanitizedDoc<RawRule> {
return {
...doc,
attributes: {
...doc.attributes,
revision: 0,
revision: isDetectionEngineAADRuleType(doc) ? (doc.attributes.params.version as number) : 0,
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2660,6 +2660,14 @@ describe('successful migrations', () => {
const migratedAlert880 = migration880(rule, migrationContext);
expect(migratedAlert880.attributes.revision).toEqual(0);
});

test('migrates security rule version to revision', () => {
const migration880 = getMigrations(encryptedSavedObjectsSetup, {}, isPreconfigured)['8.8.0'];

const rule = getMockData({ alertTypeId: ruleTypeMappings.eql, params: { version: 2 } });
const migratedAlert880 = migration880(rule, migrationContext);
expect(migratedAlert880.attributes.revision).toEqual(2);
});
});

describe('Metrics Inventory Threshold rule', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ export const updateRules = async ({
references: ruleUpdate.references ?? [],
namespace: ruleUpdate.namespace,
note: ruleUpdate.note,
// Always use the version from the request if specified. If it isn't specified, leave immutable rules alone and
// increment the version of mutable rules by 1.
version:
ruleUpdate.version ?? existingRule.params.immutable
? existingRule.params.version
: existingRule.params.version + 1,
version: ruleUpdate.version ?? existingRule.params.version,
exceptionsList: ruleUpdate.exceptions_list ?? [],
...typeSpecificParams,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ export default ({ getService }: FtrProviderContext) => {
.expect(200);

const outputRule = getSimpleMlRuleOutput();
outputRule.version = 2;
// TODO: Followup to #147398
// NOTE: Once we remove `version` increment, revision will not be updated as `machine_learning_job_id` value doesn't actually change
outputRule.revision = 1;
const bodyToCompare = removeServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(outputRule);
});
Expand Down

0 comments on commit 689648b

Please sign in to comment.