Skip to content

Commit

Permalink
[Actions] Exposes the typing for Actions Type Params (elastic#87465)
Browse files Browse the repository at this point in the history
This PR exposes the types for the Params & ActionTypeIds of all Action Types
  • Loading branch information
gmmorris committed Jan 6, 2021
1 parent 16aae3b commit 24c103c
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 19 deletions.
3 changes: 2 additions & 1 deletion x-pack/plugins/actions/server/builtin_action_types/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ interface GetActionTypeParams {
}

// action type definition
export const ActionTypeId = '.email';
export function getActionType(params: GetActionTypeParams): EmailActionType {
const { logger, publicBaseUrl, configurationUtilities } = params;
return {
id: '.email',
id: ActionTypeId,
minimumLicenseRequired: 'gold',
name: i18n.translate('xpack.actions.builtin.emailTitle', {
defaultMessage: 'Email',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ const ParamsSchema = schema.object({
documents: schema.arrayOf(schema.recordOf(schema.string(), schema.any())),
});

export const ES_INDEX_ACTION_TYPE_ID = '.index';
export const ActionTypeId = '.index';
// action type definition
export function getActionType({ logger }: { logger: Logger }): ESIndexActionType {
return {
id: ES_INDEX_ACTION_TYPE_ID,
id: ActionTypeId,
minimumLicenseRequired: 'basic',
name: i18n.translate('xpack.actions.builtin.esIndexTitle', {
defaultMessage: 'Index',
Expand Down
28 changes: 28 additions & 0 deletions x-pack/plugins/actions/server/builtin_action_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,34 @@ import { getActionType as getServiceNowActionType } from './servicenow';
import { getActionType as getJiraActionType } from './jira';
import { getActionType as getResilientActionType } from './resilient';
import { getActionType as getTeamsActionType } from './teams';
export { ActionParamsType as EmailActionParams, ActionTypeId as EmailActionTypeId } from './email';
export {
ActionParamsType as IndexActionParams,
ActionTypeId as IndexActionTypeId,
} from './es_index';
export {
ActionParamsType as PagerDutyActionParams,
ActionTypeId as PagerDutyActionTypeId,
} from './pagerduty';
export {
ActionParamsType as ServerLogActionParams,
ActionTypeId as ServerLogActionTypeId,
} from './server_log';
export { ActionParamsType as SlackActionParams, ActionTypeId as SlackActionTypeId } from './slack';
export {
ActionParamsType as WebhookActionParams,
ActionTypeId as WebhookActionTypeId,
} from './webhook';
export {
ActionParamsType as ServiceNowActionParams,
ActionTypeId as ServiceNowActionTypeId,
} from './servicenow';
export { ActionParamsType as JiraActionParams, ActionTypeId as JiraActionTypeId } from './jira';
export {
ActionParamsType as ResilientActionParams,
ActionTypeId as ResilientActionTypeId,
} from './resilient';
export { ActionParamsType as TeamsActionParams, ActionTypeId as TeamsActionTypeId } from './teams';

export function registerBuiltInActionTypes({
actionsConfigUtils: configurationUtilities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { curry } from 'lodash';
import { schema } from '@kbn/config-schema';
import { schema, TypeOf } from '@kbn/config-schema';

import { validate } from './validators';
import {
Expand All @@ -32,6 +32,7 @@ import {
import * as i18n from './translations';
import { Logger } from '../../../../../../src/core/server';

export type ActionParamsType = TypeOf<typeof ExecutorParamsSchema>;
interface GetActionTypeParams {
logger: Logger;
configurationUtilities: ActionsConfigurationUtilities;
Expand All @@ -47,6 +48,7 @@ const supportedSubActions: string[] = [
'issue',
];

export const ActionTypeId = '.jira';
// action type definition
export function getActionType(
params: GetActionTypeParams
Expand All @@ -58,7 +60,7 @@ export function getActionType(
> {
const { logger, configurationUtilities } = params;
return {
id: '.jira',
id: ActionTypeId,
minimumLicenseRequired: 'gold',
name: i18n.NAME,
validate: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function validateParams(paramsObject: unknown): string | void {
}
}

export const ActionTypeId = '.pagerduty';
// action type definition
export function getActionType({
logger,
Expand All @@ -126,7 +127,7 @@ export function getActionType({
configurationUtilities: ActionsConfigurationUtilities;
}): PagerDutyActionType {
return {
id: '.pagerduty',
id: ActionTypeId,
minimumLicenseRequired: 'gold',
name: i18n.translate('xpack.actions.builtin.pagerdutyTitle', {
defaultMessage: 'PagerDuty',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { curry } from 'lodash';
import { schema } from '@kbn/config-schema';
import { schema, TypeOf } from '@kbn/config-schema';

import { validate } from './validators';
import {
Expand All @@ -30,13 +30,16 @@ import {
import * as i18n from './translations';
import { Logger } from '../../../../../../src/core/server';

export type ActionParamsType = TypeOf<typeof ExecutorParamsSchema>;

interface GetActionTypeParams {
logger: Logger;
configurationUtilities: ActionsConfigurationUtilities;
}

const supportedSubActions: string[] = ['getFields', 'pushToService', 'incidentTypes', 'severity'];

export const ActionTypeId = '.resilient';
// action type definition
export function getActionType(
params: GetActionTypeParams
Expand All @@ -48,7 +51,7 @@ export function getActionType(
> {
const { logger, configurationUtilities } = params;
return {
id: '.resilient',
id: ActionTypeId,
minimumLicenseRequired: 'platinum',
name: i18n.NAME,
validate: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ const ParamsSchema = schema.object({
),
});

export const SERVER_LOG_ACTION_TYPE_ID = '.server-log';
export const ActionTypeId = '.server-log';
// action type definition
export function getActionType({ logger }: { logger: Logger }): ServerLogActionType {
return {
id: SERVER_LOG_ACTION_TYPE_ID,
id: ActionTypeId,
minimumLicenseRequired: 'basic',
name: i18n.translate('xpack.actions.builtin.serverLogTitle', {
defaultMessage: 'Server log',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { curry } from 'lodash';
import { schema } from '@kbn/config-schema';
import { schema, TypeOf } from '@kbn/config-schema';

import { validate } from './validators';
import {
Expand All @@ -29,11 +29,14 @@ import {
ServiceNowExecutorResultData,
} from './types';

export type ActionParamsType = TypeOf<typeof ExecutorParamsSchema>;

interface GetActionTypeParams {
logger: Logger;
configurationUtilities: ActionsConfigurationUtilities;
}

export const ActionTypeId = '.servicenow';
// action type definition
export function getActionType(
params: GetActionTypeParams
Expand All @@ -45,7 +48,7 @@ export function getActionType(
> {
const { logger, configurationUtilities } = params;
return {
id: '.servicenow',
id: ActionTypeId,
minimumLicenseRequired: 'platinum',
name: i18n.NAME,
validate: {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/actions/server/builtin_action_types/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const ParamsSchema = schema.object({

// action type definition

export const ActionTypeId = '.slack';
// customizing executor is only used for tests
export function getActionType({
logger,
Expand All @@ -63,7 +64,7 @@ export function getActionType({
executor?: ExecutorType<{}, ActionTypeSecretsType, ActionParamsType, unknown>;
}): SlackActionType {
return {
id: '.slack',
id: ActionTypeId,
minimumLicenseRequired: 'gold',
name: i18n.translate('xpack.actions.builtin.slackTitle', {
defaultMessage: 'Slack',
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/actions/server/builtin_action_types/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const ParamsSchema = schema.object({
message: schema.string({ minLength: 1 }),
});

export const ActionTypeId = '.teams';
// action type definition
export function getActionType({
logger,
Expand All @@ -51,7 +52,7 @@ export function getActionType({
configurationUtilities: ActionsConfigurationUtilities;
}): TeamsActionType {
return {
id: '.teams',
id: ActionTypeId,
minimumLicenseRequired: 'gold',
name: i18n.translate('xpack.actions.builtin.teamsTitle', {
defaultMessage: 'Microsoft Teams',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const ParamsSchema = schema.object({
body: schema.maybe(schema.string()),
});

export const ActionTypeId = '.webhook';
// action type definition
export function getActionType({
logger,
Expand All @@ -80,7 +81,7 @@ export function getActionType({
configurationUtilities: ActionsConfigurationUtilities;
}): WebhookActionType {
return {
id: '.webhook',
id: ActionTypeId,
minimumLicenseRequired: 'gold',
name: i18n.translate('xpack.actions.builtin.webhookTitle', {
defaultMessage: 'Webhook',
Expand Down
24 changes: 24 additions & 0 deletions x-pack/plugins/actions/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ export {
ActionType,
PreConfiguredAction,
} from './types';

export type {
EmailActionTypeId,
EmailActionParams,
IndexActionTypeId,
IndexActionParams,
PagerDutyActionTypeId,
PagerDutyActionParams,
ServerLogActionTypeId,
ServerLogActionParams,
SlackActionTypeId,
SlackActionParams,
WebhookActionTypeId,
WebhookActionParams,
ServiceNowActionTypeId,
ServiceNowActionParams,
JiraActionTypeId,
JiraActionParams,
ResilientActionTypeId,
ResilientActionParams,
TeamsActionTypeId,
TeamsActionParams,
} from './builtin_action_types';

export { PluginSetupContract, PluginStartContract } from './plugin';

export { asSavedObjectExecutionSource, asHttpRequestExecutionSource } from './lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
*/
import { ActionType } from '../types';
import { LICENSE_TYPE } from '../../../licensing/common/types';
import { SERVER_LOG_ACTION_TYPE_ID } from '../builtin_action_types/server_log';
import { ES_INDEX_ACTION_TYPE_ID } from '../builtin_action_types/es_index';
import { ServerLogActionTypeId, IndexActionTypeId } from '../builtin_action_types';
import { CASE_ACTION_TYPE_ID } from '../../../case/server';
import { ActionTypeConfig, ActionTypeSecrets, ActionTypeParams } from '../types';

const ACTIONS_SCOPED_WITHIN_STACK = new Set([
SERVER_LOG_ACTION_TYPE_ID,
ES_INDEX_ACTION_TYPE_ID,
ServerLogActionTypeId,
IndexActionTypeId,
CASE_ACTION_TYPE_ID,
]);

Expand Down

0 comments on commit 24c103c

Please sign in to comment.