kibana/x-pack/plugins/actions/server/action_type_registry.test.ts

374 lines
14 KiB
TypeScript
Raw Normal View History

Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { taskManagerMock } from '../../task_manager/server/mocks';
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
import { ActionTypeRegistry, ActionTypeRegistryOpts } from './action_type_registry';
import { ActionType, ExecutorType } from './types';
import { ActionExecutor, ExecutorError, ILicenseState, TaskRunnerFactory } from './lib';
import { actionsConfigMock } from './actions_config.mock';
import { licenseStateMock } from './lib/license_state.mock';
import { ActionsConfigurationUtilities } from './actions_config';
import { licensingMock } from '../../licensing/server/mocks';
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
const mockTaskManager = taskManagerMock.createSetup();
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
let mockedLicenseState: jest.Mocked<ILicenseState>;
let mockedActionsConfig: jest.Mocked<ActionsConfigurationUtilities>;
let actionTypeRegistryParams: ActionTypeRegistryOpts;
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
beforeEach(() => {
jest.resetAllMocks();
mockedLicenseState = licenseStateMock.create();
mockedActionsConfig = actionsConfigMock.create();
actionTypeRegistryParams = {
licensing: licensingMock.createSetup(),
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
taskManager: mockTaskManager,
taskRunnerFactory: new TaskRunnerFactory(
new ActionExecutor({ isESOUsingEphemeralEncryptionKey: false })
),
actionsConfigUtils: mockedActionsConfig,
licenseState: mockedLicenseState,
preconfiguredActions: [
{
actionTypeId: 'foo',
config: {},
id: 'my-slack1',
name: 'Slack #xyz',
secrets: {},
isPreconfigured: true,
},
],
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
};
});
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
const executor: ExecutorType<{}, {}, {}, void> = async (options) => {
return { status: 'ok', actionId: options.actionId };
};
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
describe('register()', () => {
test('able to register action types', () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
minimumLicenseRequired: 'gold',
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
executor,
});
expect(actionTypeRegistry.has('my-action-type')).toEqual(true);
expect(mockTaskManager.registerTaskDefinitions).toHaveBeenCalledTimes(1);
expect(mockTaskManager.registerTaskDefinitions.mock.calls[0]).toMatchInlineSnapshot(`
Array [
Object {
"actions:my-action-type": Object {
"createTaskRunner": [Function],
"getRetry": [Function],
"maxAttempts": 1,
"title": "My action type",
},
},
]
`);
expect(actionTypeRegistryParams.licensing.featureUsage.register).toHaveBeenCalledWith(
'Connector: My action type',
'gold'
);
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
});
test('shallow clones the given action type', () => {
const myType: ActionType = {
id: 'my-action-type',
name: 'My action type',
minimumLicenseRequired: 'basic',
executor,
};
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register(myType);
myType.name = 'Changed';
expect(actionTypeRegistry.get('my-action-type').name).toEqual('My action type');
});
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
test('throws error if action type already registered', () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
minimumLicenseRequired: 'basic',
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
executor,
});
expect(() =>
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
minimumLicenseRequired: 'basic',
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
executor,
})
).toThrowErrorMatchingInlineSnapshot(
`"Action type \\"my-action-type\\" is already registered."`
);
});
test('provides a getRetry function that handles ExecutorError', () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
minimumLicenseRequired: 'basic',
executor,
});
expect(mockTaskManager.registerTaskDefinitions).toHaveBeenCalledTimes(1);
const registerTaskDefinitionsCall = mockTaskManager.registerTaskDefinitions.mock.calls[0][0];
const getRetry = registerTaskDefinitionsCall['actions:my-action-type'].getRetry!;
const retryTime = new Date();
expect(getRetry(0, new Error())).toEqual(false);
expect(getRetry(0, new ExecutorError('my message', {}, true))).toEqual(true);
expect(getRetry(0, new ExecutorError('my message', {}, false))).toEqual(false);
expect(getRetry(0, new ExecutorError('my message', {}, undefined))).toEqual(false);
expect(getRetry(0, new ExecutorError('my message', {}, retryTime))).toEqual(retryTime);
});
test('registers gold+ action types to the licensing feature usage API', () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
minimumLicenseRequired: 'gold',
executor,
});
expect(actionTypeRegistryParams.licensing.featureUsage.register).toHaveBeenCalledWith(
'Connector: My action type',
'gold'
);
});
test(`doesn't register basic action types to the licensing feature usage API`, () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
minimumLicenseRequired: 'basic',
executor,
});
expect(actionTypeRegistryParams.licensing.featureUsage.register).not.toHaveBeenCalled();
});
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
});
describe('get()', () => {
test('returns action type', () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
minimumLicenseRequired: 'basic',
executor,
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
});
const actionType = actionTypeRegistry.get('my-action-type');
expect(actionType).toMatchInlineSnapshot(`
Object {
"executor": [Function],
"id": "my-action-type",
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
"minimumLicenseRequired": "basic",
"name": "My action type",
}
`);
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
});
test(`throws an error when action type doesn't exist`, () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
expect(() => actionTypeRegistry.get('my-action-type')).toThrowErrorMatchingInlineSnapshot(
`"Action type \\"my-action-type\\" is not registered."`
);
});
});
describe('list()', () => {
test('returns list of action types', () => {
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
mockedLicenseState.isLicenseValidForActionType.mockReturnValue({ isValid: true });
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
minimumLicenseRequired: 'basic',
executor,
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
});
const actionTypes = actionTypeRegistry.list();
expect(actionTypes).toEqual([
{
id: 'my-action-type',
name: 'My action type',
enabled: true,
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
enabledInConfig: true,
enabledInLicense: true,
minimumLicenseRequired: 'basic',
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
},
]);
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
expect(mockedActionsConfig.isActionTypeEnabled).toHaveBeenCalled();
expect(mockedLicenseState.isLicenseValidForActionType).toHaveBeenCalled();
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
});
});
describe('has()', () => {
test('returns false for unregistered action types', () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
expect(actionTypeRegistry.has('my-action-type')).toEqual(false);
});
test('returns true after registering an action type', () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
minimumLicenseRequired: 'basic',
Introduce basic alerting and actions plugin (#37042) * Create actions plugin (#35679) * Basic alerting plugin with actions * Remove relative imports * Code cleanup * Split service into 3 parts, change connector structure * Ability to disable plugin, ability to get actions * Add slack connector * Add email connector * Ability to validate params and connector options * Remove connectorOptionsSecrets for now * Fix plugin config validation * Add tests for slack connector * Default connectors register on plugin init, console renamed to log, slack to message_slack * Add remaining API endpoints for action CRUD * Add list connectors API * Change actions CRUD APIs to be closer with saved objects structure * WIP * Fix broken tests * Add encrypted attribute support * Add params and connectorOptions for email * WIP * Remove action's ability to have custom ids * Remove ts-ignore * Fix broken test * Remove default connectors from this branch * Fix API integration tests to use fixture connector * Rename connector terminology to action type * Rename actionTypeOptions to actionTypeConfig * Code cleanup * Fix broken tests * Rename alerting plugin to actions * Some code cleanup and add API unit tests * Change signature of action type service execute function * Add some plugin api integration tests * Fix type check failure * Code cleanup * Create an actions client instead of an action service * Apply Bill's PR feedback * Fix broken test * Find function to have destructured params * Add tests to ensure encrypted attributes are not returned * Fix broken test * Add tests for validation * Ensure actions can be updated without re-passing the config * Remove dead code * Test cleanup * Fix eslint issue * Apply Peter's PR feedback * Code cleanup and fix broken tests * Apply Brandon's PR feedback * Add namespace support * Fix broken test * Pass services to action executors (#37194) * Pass services to action executors * Fix tests * Apply PR feedback * Apply PR feedback pt2 * Cleanup actions plugin (#37250) * Cleanup actions, move code from alerting plugin PR * Rename service terminology to registry * Use static encryption key for encrypted attributes plugin inside of tests * Empty data after create test is done running * Fix type checks * Fix inconsistent naming * add server log action for alerting (#37530) adds the first "builtin" alertType for performing a `server.log()` * Create alerting plugin (#37043) * WIP * Rename fire function and remove @ts-ignore in all places * Change naming in alerting service * Remove alert instance class for now, support interval configuration * Cleanup TS * Split alerting between registry and client * Use saved object alongside task manager instance * Add remaining alerting APIs * Change create structure * Rename some variables, change actionGroups structure * Use handlebars for templating strings at fire time * Fix params given to alert type execute function * Use alert instance class * Alert instances support meta attributes * Move alert instances deserialization * Change interval to be ms * Rename actions es archive * Fix tests to use encrypted esArchive for action record * Add create alert test to demo end to end flow * Fix type check issue * Alerts to use references to action objects * Only update task manager tasks after saved objects are fully updated * Use scope in task manager * Fix type check * Use task manager to execute actions * Convert ids into references and back * Apply PR feedback * Fix broken test * Fix some bugs * Fix test errors * Alert interval to be previous runAt + interval instead of now + interval * Add range support * Remove extra line * Cleanup * Add alert_instance.test.ts * Add alert_type_registry.test.ts * Move tests around * Create generic task manager mock * Add note about saved objects client mock * Create alert_type_registry.mock.ts * Add alerts_client.test.ts * Add create_alert_instance_factory.test.ts * Add create_fire_handler.test.ts * WIP * Fix get_create_task_runner_function.test.ts and make test pass * Make get_create_task_runner_function.test.ts 100% coverage * Add unit tests for routes * Move files around * Created transform_action_params.ts * Add get_next_run_at.ts * Add comment explaining why we copy nextRunAt * Re-use state within alert instance * Finalize code coverage in unit tests * Create base api integration tests * Add a test that ensures end to end functionality of an alert * Fix ui capabilities test * Fix broken plugin api integration test * Fix jest tests with new saved objects client * Fix broken integration tests * Change api integration test fixture to make more sense, add functions for future tests * Move alerts integration testing into own file, prep to add more tests * Add tests to ensure failed task instances get retried * Add get_create_task_runner_function.test.ts for actions, create encrypted saved objects mock * Add action validation tests * Ensure action type validation occurs on update * Test 400 on unregistered alert types * Ensure alertTypeId can't be updated * Add validation test for alert create / update * Fix broken checks / tests * Skip failing test for now * Cleanup jest tests * Ensure action objects can be updated while keeping encrypted attributes readable * Remove partial update sopport, remove ability to change actionTypeId, require config * Ensure actionTypeConfig is validated on create and update * Add alertTypeParams validation support * Fix failing tests * Ensure alert cleanup errors don't replace the original error * Pass callCluster as a service to alerts and actions * Only pass log to alerts client * Pass savedObjectsClient as a service to alerting and actions * Fix failing tests * Remove range support, provide when current and previous task got scheduled * Ensure Joi validation happens before every execute * Remove skipped tests, to be done in future PR * Apply self feedback pt1 * Apply self feedback pt2 * Fix broken tests * Apply PR feedback * PR feedback pt1 * Apply security team PR feedback * PR feedback pt1 * PR feedback pt2 * PR feedback pt3 * Fix broken tests * Fix callCluster to have signature * Revert f11a6aeb06c65e5ab54bf3cc36694845c812b6a7 * PR feedback pt4 * Remove __jest__ folders * PR feedback pt5 * Fix Joi from leaking secrets * Fire instance actions in parallel instead of series * Fix failing jest tests * Accept core api changes * Fix saved objects client mock * PR feedback pt1 * Fix eslint issues * Throw error when alert instance already fired (#39251) * Throw error when alert instance already fired * shouldFire doesn't need its own boolean value * Actions & alerting getting started user guides (#39093) * Initial user guides * Cleanup * Typos, example changes * Switch to tables, use ordered list for usage * Start docs around alert instances and templating * Documentation changes * Some adjustments * Apply PR feedback * Apply suggestions from code review Co-Authored-By: gchaps <33642766+gchaps@users.noreply.github.com> * PR feedback pt2 * Provide better examples for alert types * Apply PR feedback * Update README locations
2019-06-21 01:37:17 +02:00
executor,
});
expect(actionTypeRegistry.has('my-action-type'));
});
});
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
describe('isActionTypeEnabled', () => {
let actionTypeRegistry: ActionTypeRegistry;
const fooActionType: ActionType = {
id: 'foo',
name: 'Foo',
minimumLicenseRequired: 'basic',
executor: async (options) => {
return { status: 'ok', actionId: options.actionId };
},
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
};
beforeEach(() => {
actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register(fooActionType);
});
test('should call isActionTypeEnabled of the actions config', async () => {
mockedLicenseState.isLicenseValidForActionType.mockReturnValue({ isValid: true });
actionTypeRegistry.isActionTypeEnabled('foo');
expect(mockedActionsConfig.isActionTypeEnabled).toHaveBeenCalledWith('foo');
});
test('should call isActionExecutable of the actions config', async () => {
mockedLicenseState.isLicenseValidForActionType.mockReturnValue({ isValid: true });
actionTypeRegistry.isActionExecutable('my-slack1', 'foo');
expect(mockedActionsConfig.isActionTypeEnabled).toHaveBeenCalledWith('foo');
});
test('should return true when isActionTypeEnabled is false and isLicenseValidForActionType is true and it has preconfigured connectors', async () => {
mockedActionsConfig.isActionTypeEnabled.mockReturnValue(false);
mockedLicenseState.isLicenseValidForActionType.mockReturnValue({ isValid: true });
expect(actionTypeRegistry.isActionExecutable('my-slack1', 'foo')).toEqual(true);
});
test('should call isLicenseValidForActionType of the license state with notifyUsage false by default', async () => {
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
mockedLicenseState.isLicenseValidForActionType.mockReturnValue({ isValid: true });
actionTypeRegistry.isActionTypeEnabled('foo');
expect(mockedLicenseState.isLicenseValidForActionType).toHaveBeenCalledWith(fooActionType, {
notifyUsage: false,
});
});
test('should call isLicenseValidForActionType of the license state with notifyUsage true when specified', async () => {
mockedLicenseState.isLicenseValidForActionType.mockReturnValue({ isValid: true });
actionTypeRegistry.isActionTypeEnabled('foo', { notifyUsage: true });
expect(mockedLicenseState.isLicenseValidForActionType).toHaveBeenCalledWith(fooActionType, {
notifyUsage: true,
});
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
});
test('should return false when isActionTypeEnabled is false and isLicenseValidForActionType is true', async () => {
mockedActionsConfig.isActionTypeEnabled.mockReturnValue(false);
mockedLicenseState.isLicenseValidForActionType.mockReturnValue({ isValid: true });
expect(actionTypeRegistry.isActionTypeEnabled('foo')).toEqual(false);
});
test('should return false when isActionTypeEnabled is true and isLicenseValidForActionType is false', async () => {
mockedActionsConfig.isActionTypeEnabled.mockReturnValue(true);
mockedLicenseState.isLicenseValidForActionType.mockReturnValue({
isValid: false,
reason: 'invalid',
});
expect(actionTypeRegistry.isActionTypeEnabled('foo')).toEqual(false);
});
});
describe('ensureActionTypeEnabled', () => {
let actionTypeRegistry: ActionTypeRegistry;
const fooActionType: ActionType = {
id: 'foo',
name: 'Foo',
minimumLicenseRequired: 'basic',
executor: async (options) => {
return { status: 'ok', actionId: options.actionId };
},
License checks for actions plugin (#59070) * Define minimum license required for each action type (#58668) * Add minimum required license * Require at least gold license as a minimum license required on third party action types * Use strings for license references * Ensure license type is valid * Fix some tests * Add servicenow to gold * Add tests * Set license requirements on other built in action types * Use jest.Mocked<ActionType> instead * Change servicenow to platinum Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Make actions config mock and license state mock use factory pattern and jest mocks (#59370) * Add license checks to action HTTP APIs (#59153) * Initial work * Handle errors in update action API * Add unit tests for APIs * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Add license checks within alerting / actions framework (#59699) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Fix confusing assertion * Add comment explaining double mock * Log warning when alert action isn't scheduled * Disable action types in UI when license doesn't support it (#59819) * Initial work * Handle errors in update action API * Add unit tests for APIs * Verify action type before scheduling action task * Make actions plugin.execute throw error if action type is disabled * Bug fixes * Make action executor throw when action type isn't enabled * Add test suite for basic license * Fix ESLint errors * Stop action task from re-running when license check fails * Fix failing tests * Attempt 1 to fix CI * ESLint fixes * Return enabledInConfig and enabledInLicense from actions get types API * Disable cards that have invalid license in create connector flyout * Create sendResponse function on ActionTypeDisabledError * Make disabled action types by config return 403 * Remove switch case * Fix ESLint * Disable when creating alert action * Return minimumLicenseRequired in /types API * Disable row in connectors when action type is disabled * Fix failing jest test * Some refactoring * Card in edit alert flyout * Sort action types by name * Add tooltips to create connector action type selector * Add tooltips to alert flyout action type selector * Add get more actions link in alert flyout * Add callout when creating a connector * Typos * remove float right and use flexgroup * replace pixels with eui variables * turn on sass lint for triggers_actions_ui dir * trying to add padding around cards * Add callout in edit alert screen when some actions are disabled * improve card selection for Add Connector flyout * Fix cards for create connector * Add tests * ESLint issue * Cleanup * Cleanup pt2 * Fix type check errors * moving to 3-columns cards for connector selection * Change re-enable to enable terminology * Revert "Change re-enable to enable terminology" This reverts commit b497dfd6b6bc88db862ad97826e8d03b094c8ed0. * Add re-enable comment * Remove unecessary fragment * Add type to actionTypeNodes * Fix EuiLink to not have opacity of 0.7 when not hovered * design cleanup in progress * updating classNames * using EuiIconTip * Remove label on icon tip * Fix failing jest test Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com> * Add index to .index action type test * PR feedback * Add isErrorThatHandlesItsOwnResponse Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Andrea Del Rio <delrio.andre@gmail.com>
2020-03-20 15:49:37 +01:00
};
beforeEach(() => {
actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register(fooActionType);
});
test('should call ensureActionTypeEnabled of the action config', async () => {
actionTypeRegistry.ensureActionTypeEnabled('foo');
expect(mockedActionsConfig.ensureActionTypeEnabled).toHaveBeenCalledWith('foo');
});
test('should call ensureLicenseForActionType on the license state', async () => {
actionTypeRegistry.ensureActionTypeEnabled('foo');
expect(mockedLicenseState.ensureLicenseForActionType).toHaveBeenCalledWith(fooActionType);
});
test('should throw when ensureActionTypeEnabled throws', async () => {
mockedActionsConfig.ensureActionTypeEnabled.mockImplementation(() => {
throw new Error('Fail');
});
expect(() =>
actionTypeRegistry.ensureActionTypeEnabled('foo')
).toThrowErrorMatchingInlineSnapshot(`"Fail"`);
});
test('should throw when ensureLicenseForActionType throws', async () => {
mockedLicenseState.ensureLicenseForActionType.mockImplementation(() => {
throw new Error('Fail');
});
expect(() =>
actionTypeRegistry.ensureActionTypeEnabled('foo')
).toThrowErrorMatchingInlineSnapshot(`"Fail"`);
});
});
describe('isActionExecutable()', () => {
let actionTypeRegistry: ActionTypeRegistry;
const fooActionType: ActionType = {
id: 'foo',
name: 'Foo',
minimumLicenseRequired: 'basic',
executor: async (options) => {
return { status: 'ok', actionId: options.actionId };
},
};
beforeEach(() => {
actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register(fooActionType);
});
test('should call isLicenseValidForActionType of the license state with notifyUsage false by default', async () => {
mockedLicenseState.isLicenseValidForActionType.mockReturnValue({ isValid: true });
actionTypeRegistry.isActionExecutable('123', 'foo');
expect(mockedLicenseState.isLicenseValidForActionType).toHaveBeenCalledWith(fooActionType, {
notifyUsage: false,
});
});
test('should call isLicenseValidForActionType of the license state with notifyUsage true when specified', async () => {
mockedLicenseState.isLicenseValidForActionType.mockReturnValue({ isValid: true });
actionTypeRegistry.isActionExecutable('123', 'foo', { notifyUsage: true });
expect(mockedLicenseState.isLicenseValidForActionType).toHaveBeenCalledWith(fooActionType, {
notifyUsage: true,
});
});
});