Skip to content

Commit

Permalink
[Fleet] Fix circular ref by moving code & tests into Fleet (#94171) (#…
Browse files Browse the repository at this point in the history
…94483)

## Problem
There's a circular dependency #91111 between the `fleet` and `security_solution` plugins 

* `security_solution` depends on `fleet`, but 
* `fleet` has (_had_ with this PR) an `import` from  `security_solution` (migrations for the 7.11 and 7.12 package policy objects)

## Proposed solution
### (A) This PR
Move the two imported functions from `security` into `fleet`.

### (B) Follow up issue
Putting integration-specific code into `fleet` doesn't scale (technically or cognitively). Discuss if this use case (specifying saved object migrations, etc) applies to other plugins. e.g. can `apm` do this? `nginx`? If so, should we find a way to move this out of `fleet`?


### Checklist

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios

closes #91111
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: John Schulz <john.schulz@elastic.co>
  • Loading branch information
kibanamachine and John Schulz authored Mar 11, 2021
1 parent df329b0 commit e0094d3
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 27 deletions.
18 changes: 10 additions & 8 deletions x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@ import {
} from '../constants';

import {
migratePackagePolicyToV7110,
migratePackagePolicyToV7120,
// @ts-expect-error
} from './security_solution';
import {
migrateAgentToV7100,
migrateAgentActionToV7100,
migrateAgentEventToV7100,
migrateAgentPolicyToV7100,
migrateAgentToV7100,
migrateEnrollmentApiKeysToV7100,
migratePackagePolicyToV7100,
migrateSettingsToV7100,
migrateAgentActionToV7100,
} from './migrations/to_v7_10_0';
import { migrateAgentToV7120, migrateAgentPolicyToV7120 } from './migrations/to_v7_12_0';

import { migratePackagePolicyToV7110 } from './migrations/to_v7_11_0';

import {
migrateAgentPolicyToV7120,
migrateAgentToV7120,
migratePackagePolicyToV7120,
} from './migrations/to_v7_12_0';

/*
* Saved object types and mappings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { migratePackagePolicyToV7110 } from './to_v7_11_0';
export { migratePackagePolicyToV7120 } from './to_v7_12_0';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

import { SavedObjectMigrationContext, SavedObjectUnsanitizedDoc } from 'kibana/server';
import { PackagePolicy } from '../../../../../fleet/common';

import type { PackagePolicy } from '../../../../common';

import { migratePackagePolicyToV7110 } from './to_v7_11_0';

describe('7.11.0 Endpoint Package Policy migration', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import { SavedObjectMigrationFn, SavedObjectUnsanitizedDoc } from 'kibana/server';
import { cloneDeep } from 'lodash';
import { PackagePolicy } from '../../../../../fleet/common';

import type { PackagePolicy } from '../../../../common';

export const migratePackagePolicyToV7110: SavedObjectMigrationFn<PackagePolicy, PackagePolicy> = (
packagePolicyDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
*/

import { SavedObjectMigrationContext, SavedObjectUnsanitizedDoc } from 'kibana/server';
import { PackagePolicy } from '../../../../../fleet/common';
import { PolicyData, ProtectionModes } from '../../types';

import type { PackagePolicy } from '../../../../common';

import { migratePackagePolicyToV7120 } from './to_v7_12_0';

describe('7.12.0 Endpoint Package Policy migration', () => {
const migration = migratePackagePolicyToV7120;
it('adds ransomware option and notification customization', () => {
const doc: SavedObjectUnsanitizedDoc<PolicyData> = {
const doc = {
id: 'mock-saved-object-id',
attributes: {
name: 'Some Policy Name',
Expand Down Expand Up @@ -41,7 +42,6 @@ describe('7.12.0 Endpoint Package Policy migration', () => {
policy: {
value: {
windows: {
// @ts-expect-error
popup: {
malware: {
message: '',
Expand All @@ -58,9 +58,7 @@ describe('7.12.0 Endpoint Package Policy migration', () => {
type: ' nested',
};

expect(
migration(doc, {} as SavedObjectMigrationContext) as SavedObjectUnsanitizedDoc<PolicyData>
).toEqual({
expect(migration(doc, {} as SavedObjectMigrationContext)).toEqual({
attributes: {
name: 'Some Policy Name',
package: {
Expand Down Expand Up @@ -88,7 +86,7 @@ describe('7.12.0 Endpoint Package Policy migration', () => {
value: {
windows: {
ransomware: {
mode: ProtectionModes.off,
mode: 'off',
},
popup: {
malware: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import { SavedObjectMigrationFn, SavedObjectUnsanitizedDoc } from 'kibana/server';
import { cloneDeep } from 'lodash';
import { PackagePolicy } from '../../../../../fleet/common';
import { ProtectionModes } from '../../types';

import type { PackagePolicy } from '../../../../common';

export const migratePackagePolicyToV7120: SavedObjectMigrationFn<PackagePolicy, PackagePolicy> = (
packagePolicyDoc
Expand All @@ -19,7 +19,7 @@ export const migratePackagePolicyToV7120: SavedObjectMigrationFn<PackagePolicy,
if (packagePolicyDoc.attributes.package?.name === 'endpoint') {
const input = updatedPackagePolicyDoc.attributes.inputs[0];
const ransomware = {
mode: ProtectionModes.off,
mode: 'off',
};
const ransomwarePopup = {
message: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@
* 2.0.
*/

export {
migratePackagePolicyToV7110,
migratePackagePolicyToV7120,
} from '../../../security_solution/common';
export { migratePackagePolicyToV7110 } from './security_solution/to_v7_11_0';
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type { SavedObjectMigrationFn } from 'kibana/server';

import type { Agent, AgentPolicy } from '../../types';

export { migratePackagePolicyToV7120 } from './security_solution/to_v7_12_0';

export const migrateAgentToV7120: SavedObjectMigrationFn<Agent & { shared_id?: string }, Agent> = (
agentDoc
) => {
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/security_solution/common/shared_exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ export { exactCheck } from './exact_check';
export { getPaths, foldLeftRight, removeExternalLinkText } from './test_utils';
export { validate, validateEither } from './validate';
export { formatErrors } from './format_errors';
export { migratePackagePolicyToV7110 } from './endpoint/policy/migrations/to_v7_11_0';
export { migratePackagePolicyToV7120 } from './endpoint/policy/migrations/to_v7_12_0';
export { addIdToItem, removeIdFromItem } from './add_remove_id_to_item';

0 comments on commit e0094d3

Please sign in to comment.