-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Alerting] Export rules and connectors #98802
Merged
ymao1
merged 17 commits into
elastic:master
from
ymao1:alerting/export-rules-and-connectors
May 5, 2021
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bd1ea5c
Adding importableAndExportable but hidden saved object types to saved…
ymao1 ae7b219
Adding helper function for transforming rule for export. Added audit …
ymao1 6188455
Adding helper function for transforming rule for export. Added audit …
ymao1 0f0d65e
Merge branch 'master' of https://github.com/elastic/kibana into alert…
ymao1 9b84a07
Adding unit test for transforming rules for export
ymao1 c66de1f
Exporting connectors
ymao1 2621aff
Merge branch 'master' of https://github.com/elastic/kibana into alert…
ymao1 df73b5f
Removing auditing during export
ymao1 b5e04cd
Adding import/export to docs
ymao1 aa132b9
Merge branch 'master' of https://github.com/elastic/kibana into alert…
ymao1 47ebbf5
PR fixes
ymao1 58dfb8a
Using action type validation onExport
ymao1 c4d4bf4
Merge branch 'master' into alerting/export-rules-and-connectors
kibanamachine 41e7e7a
Fixing logic for connectors with optional secrets
ymao1 6a0d61c
Merge branch 'master' of https://github.com/elastic/kibana into alert…
ymao1 6d3d7ee
Merge branch 'alerting/export-rules-and-connectors' of https://github…
ymao1 3be3824
Fixing logic for connectors with optional secrets
ymao1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
253 changes: 253 additions & 0 deletions
253
x-pack/plugins/actions/server/saved_objects/transform_connectors_for_export.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,253 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { transformConnectorsForExport } from './transform_connectors_for_export'; | ||
import { ActionTypeRegistry, ActionTypeRegistryOpts } from '../action_type_registry'; | ||
import { loggingSystemMock } from '../../../../../src/core/server/mocks'; | ||
import { actionsConfigMock } from '../actions_config.mock'; | ||
import { licensingMock } from '../../../licensing/server/mocks'; | ||
import { licenseStateMock } from '../lib/license_state.mock'; | ||
import { taskManagerMock } from '../../../task_manager/server/mocks'; | ||
import { ActionExecutor, TaskRunnerFactory } from '../lib'; | ||
import { registerBuiltInActionTypes } from '../builtin_action_types'; | ||
|
||
describe('transform connector for export', () => { | ||
const actionTypeRegistryParams: ActionTypeRegistryOpts = { | ||
licensing: licensingMock.createSetup(), | ||
taskManager: taskManagerMock.createSetup(), | ||
taskRunnerFactory: new TaskRunnerFactory(new ActionExecutor({ isESOCanEncrypt: true })), | ||
actionsConfigUtils: actionsConfigMock.create(), | ||
licenseState: licenseStateMock.create(), | ||
preconfiguredActions: [], | ||
}; | ||
const actionTypeRegistry: ActionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams); | ||
|
||
registerBuiltInActionTypes({ | ||
logger: loggingSystemMock.create().get(), | ||
actionTypeRegistry, | ||
actionsConfigUtils: actionsConfigMock.create(), | ||
}); | ||
|
||
const connectorsWithNoSecrets = [ | ||
{ | ||
id: '1', | ||
type: 'action', | ||
attributes: { | ||
actionTypeId: '.email', | ||
name: 'email connector without auth', | ||
isMissingSecrets: false, | ||
config: { | ||
hasAuth: false, | ||
from: 'me@me.com', | ||
host: 'host', | ||
port: 22, | ||
service: null, | ||
secure: null, | ||
}, | ||
secrets: 'asbqw4tqbef', | ||
}, | ||
references: [], | ||
}, | ||
{ | ||
id: '2', | ||
type: 'action', | ||
attributes: { | ||
actionTypeId: '.index', | ||
name: 'index connector', | ||
isMissingSecrets: false, | ||
config: { | ||
index: 'test-index', | ||
refresh: false, | ||
executionTimeField: null, | ||
}, | ||
secrets: 'asbqw4tqbef', | ||
}, | ||
references: [], | ||
}, | ||
{ | ||
id: '3', | ||
type: 'action', | ||
attributes: { | ||
actionTypeId: '.server-log', | ||
name: 'server log connector', | ||
isMissingSecrets: false, | ||
config: {}, | ||
secrets: 'asbqw4tqbef', | ||
}, | ||
references: [], | ||
}, | ||
{ | ||
id: '4', | ||
type: 'action', | ||
attributes: { | ||
actionTypeId: '.webhook', | ||
name: 'webhook connector without auth', | ||
isMissingSecrets: false, | ||
config: { | ||
method: 'post', | ||
hasAuth: false, | ||
url: 'https://webhook', | ||
headers: {}, | ||
}, | ||
secrets: 'asbqw4tqbef', | ||
}, | ||
references: [], | ||
}, | ||
]; | ||
const connectorsWithSecrets = [ | ||
{ | ||
id: '1', | ||
type: 'action', | ||
attributes: { | ||
actionTypeId: '.email', | ||
name: 'email connector with auth', | ||
isMissingSecrets: false, | ||
config: { | ||
hasAuth: true, | ||
from: 'me@me.com', | ||
host: 'host', | ||
port: 22, | ||
service: null, | ||
secure: null, | ||
}, | ||
secrets: 'asbqw4tqbef', | ||
}, | ||
references: [], | ||
}, | ||
{ | ||
id: '2', | ||
type: 'action', | ||
attributes: { | ||
actionTypeId: '.resilient', | ||
name: 'resilient connector', | ||
isMissingSecrets: false, | ||
config: { | ||
apiUrl: 'https://resilient', | ||
orgId: 'origId', | ||
}, | ||
secrets: 'asbqw4tqbef', | ||
}, | ||
references: [], | ||
}, | ||
{ | ||
id: '3', | ||
type: 'action', | ||
attributes: { | ||
actionTypeId: '.servicenow', | ||
name: 'servicenow itsm connector', | ||
isMissingSecrets: false, | ||
config: { | ||
apiUrl: 'https://servicenow', | ||
}, | ||
secrets: 'asbqw4tqbef', | ||
}, | ||
references: [], | ||
}, | ||
{ | ||
id: '4', | ||
type: 'action', | ||
attributes: { | ||
actionTypeId: '.pagerduty', | ||
name: 'pagerduty connector', | ||
isMissingSecrets: false, | ||
config: { | ||
apiUrl: 'https://pagerduty', | ||
}, | ||
secrets: 'asbqw4tqbef', | ||
}, | ||
references: [], | ||
}, | ||
{ | ||
id: '5', | ||
type: 'action', | ||
attributes: { | ||
actionTypeId: '.jira', | ||
name: 'jira connector', | ||
isMissingSecrets: false, | ||
config: { | ||
apiUrl: 'https://jira', | ||
projectKey: 'foo', | ||
}, | ||
secrets: 'asbqw4tqbef', | ||
}, | ||
references: [], | ||
}, | ||
{ | ||
id: '6', | ||
type: 'action', | ||
attributes: { | ||
actionTypeId: '.teams', | ||
name: 'teams connector', | ||
isMissingSecrets: false, | ||
config: {}, | ||
secrets: 'asbqw4tqbef', | ||
}, | ||
references: [], | ||
}, | ||
{ | ||
id: '7', | ||
type: 'action', | ||
attributes: { | ||
actionTypeId: '.slack', | ||
name: 'slack connector', | ||
isMissingSecrets: false, | ||
config: {}, | ||
secrets: 'asbqw4tqbef', | ||
}, | ||
references: [], | ||
}, | ||
{ | ||
id: '8', | ||
type: 'action', | ||
attributes: { | ||
actionTypeId: '.servicenow-sir', | ||
name: 'servicenow sir connector', | ||
isMissingSecrets: false, | ||
config: { | ||
apiUrl: 'https://servicenow-sir', | ||
}, | ||
secrets: 'asbqw4tqbef', | ||
}, | ||
references: [], | ||
}, | ||
{ | ||
id: '8', | ||
type: 'action', | ||
attributes: { | ||
actionTypeId: '.webhook', | ||
name: 'webhook connector with auth', | ||
isMissingSecrets: false, | ||
config: { | ||
method: 'post', | ||
hasAuth: true, | ||
url: 'https://webhook', | ||
headers: {}, | ||
}, | ||
secrets: 'asbqw4tqbef', | ||
}, | ||
references: [], | ||
}, | ||
]; | ||
|
||
it('should not change connectors without secrets', () => { | ||
expect(transformConnectorsForExport(connectorsWithNoSecrets, actionTypeRegistry)).toEqual( | ||
connectorsWithNoSecrets | ||
); | ||
}); | ||
|
||
it('should remove secrets for connectors with secrets', () => { | ||
expect(transformConnectorsForExport(connectorsWithSecrets, actionTypeRegistry)).toEqual( | ||
connectorsWithSecrets.map((connector) => ({ | ||
...connector, | ||
attributes: { | ||
...connector.attributes, | ||
isMissingSecrets: true, | ||
}, | ||
})) | ||
); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
x-pack/plugins/actions/server/saved_objects/transform_connectors_for_export.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { SavedObject } from 'kibana/server'; | ||
import { ActionTypeRegistry } from '../action_type_registry'; | ||
import { validateSecrets } from '../lib'; | ||
import { RawAction, ActionType } from '../types'; | ||
|
||
export function transformConnectorsForExport( | ||
connectors: SavedObject[], | ||
actionTypeRegistry: ActionTypeRegistry | ||
): Array<SavedObject<RawAction>> { | ||
return connectors.map((c) => { | ||
const connector = c as SavedObject<RawAction>; | ||
return transformConnectorForExport( | ||
connector, | ||
actionTypeRegistry.get(connector.attributes.actionTypeId) | ||
); | ||
}); | ||
} | ||
|
||
function transformConnectorForExport( | ||
connector: SavedObject<RawAction>, | ||
actionType: ActionType | ||
): SavedObject<RawAction> { | ||
let isMissingSecrets = false; | ||
try { | ||
// If connector requires secrets, this will throw an error | ||
validateSecrets(actionType, {}); | ||
|
||
// If connector has optional (or no) secrets, set isMissingSecrets value to value of hasAuth | ||
// If connector doesn't have hasAuth value, default to isMissingSecrets: false | ||
isMissingSecrets = (connector?.attributes?.config?.hasAuth as boolean) ?? false; | ||
} catch (err) { | ||
isMissingSecrets = true; | ||
} | ||
|
||
// Skip connectors | ||
return { | ||
...connector, | ||
attributes: { | ||
...connector.attributes, | ||
isMissingSecrets, | ||
}, | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Referring to the
getTitle
function on top, as comments are not allowed on non-diff lines...)Ideally, we shouldn't need the object's type to be displayed in its associated title, as it introduces redundancy in some parts of the SOM UI.
Now, the main SOM table is only using an (EUI) icon to display the type associated with each object. Is there an icon associated with
rules
andconnectors
in the EUI library? If so, you could add them via themanagement.icon
property of the types.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pgayvallet Discussed with @mdefazio and we currently don't have dedicated icons for
rules
orconnectors
. If we're using the default icon, should we leaveRules:
andConnectors:
in the title?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so. This is low impact and can be changed later anyway, so I think it's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for being flexible. Our concern is associating icons with Rules and Connectors that may also be used elsewhere for different concepts. The viz type icons were created specifically for those types and aren't used for other things (or shouldn't be).
If we want an icon, we will just need to go the route of creating on specifically for this. However, this type column may quickly turn into a lot of different icons and likely need the title to be shown alongside them anyway.
So let's circle back to it in the future and determine if we want to only show the title.