import http from 'http' ; import https from 'https' ; import { Plugin , CoreSetup , IRouter } from 'kibana/server' ; import { EncryptedSavedObjectsPluginStart } from '../../../../../../../plugins/encrypted_saved_objects/server' ; import { PluginSetupContract as FeaturesPluginSetup } from '../../../../../../../plugins/features/server' ; import { PluginSetupContract as ActionsPluginSetupContract } from '../../../../../../../plugins/actions/server/plugin' ; import { ActionType } from '../../../../../../../plugins/actions/server' ; import { initPlugin as initPagerduty } from './pagerduty_simulation' ; import { initPlugin as initSwimlane } from './swimlane_simulation' ; import { initPlugin as initServiceNow } from './servicenow_simulation' ; import { initPlugin as initJira } from './jira_simulation' ; import { initPlugin as initResilient } from './resilient_simulation' ; import { initPlugin as initSlack } from './slack_simulation' ; import { initPlugin as initWebhook } from './webhook_simulation' ; import { initPlugin as initMSExchange } from './ms_exchage_server_simulation' ; export const NAME = 'actions-FTS-external-service-simulators' ; export enum ExternalServiceSimulator { PAGERDUTY = 'pagerduty' , SWIMLANE = 'swimlane' , SERVICENOW = 'servicenow' , SLACK = 'slack' , JIRA = 'jira' , RESILIENT = 'resilient' , WEBHOOK = 'webhook' , MS_EXCHANGE = 'exchange' } export function getExternalServiceSimulatorPath ( service ) { return `/api/_${ NAME }/${ service }` ; } export function getAllExternalServiceSimulatorPaths ( ) { const allPaths = Object . values ( ExternalServiceSimulator ) . map ( ( service ) => getExternalServiceSimulatorPath ( service ) ) ; allPaths . push ( `/api/_${ NAME }/${ ExternalServiceSimulator . JIRA }/rest/api/2/issue` ) ; allPaths . push ( `/api/_${ NAME }/${ ExternalServiceSimulator . JIRA }/rest/api/2/createmeta` ) ; allPaths . push ( `/api/_${ NAME }/${ ExternalServiceSimulator . RESILIENT }/rest/orgs/201/incidents` ) ; allPaths . push ( `/api/_${ NAME }/${ ExternalServiceSimulator . MS_EXCHANGE }/users/test@/sendMail` ) ; allPaths . push ( `/api/_${ NAME }/${ ExternalServiceSimulator . MS_EXCHANGE }/1234567/oauth2/v2.0/token` ) ; return allPaths ; } export async function getWebhookServer ( ) { const { httpServer } = await initWebhook ( ) ; return httpServer ; } export async function getHttpsWebhookServer ( ) { const { httpsServer } = await initWebhook ( ) ; return httpsServer ; } export async function getSlackServer ( ) { return await initSlack ( ) ; } export async function getSwimlaneServer ( ) { return await initSwimlane ( ) ; } export async function getServiceNowServer ( ) { return await initServiceNow ( ) ; } interface FixtureSetupDeps { actions : ActionsPluginSetupContract ; features : FeaturesPluginSetup ; } interface FixtureStartDeps { encryptedSavedObjects : EncryptedSavedObjectsPluginStart ; } export class FixturePlugin implements Plugin < void , void , FixtureSetupDeps , FixtureStartDeps > { public setup ( core , { features , actions } ) { const notEnabledActionType = { id : 'test.not-enabled' , name : 'Test: Not Enabled' , minimumLicenseRequired : 'gold' , async executor ( ) { return { status : 'ok' , actionId : '' } ; } , } ; actions . registerType ( notEnabledActionType ) ; features . registerKibanaFeature ( { id : 'actionsSimulators' , name : 'actionsSimulators' , app : [ 'actions' , 'kibana' ] , category : { id : 'foo' , label : 'foo' } , privileges : { all : { app : [ 'actions' , 'kibana' ] , savedObject : { all : [ ] , read : [ ] , } , ui : [ ] , api : [ ] , } , read : { app : [ 'actions' , 'kibana' ] , savedObject : { all : [ ] , read : [ ] , } , ui : [ ] , api : [ ] , } , } , } ) ; const router = core . http . createRouter ( ) ; initPagerduty ( router , getExternalServiceSimulatorPath ( ExternalServiceSimulator . PAGERDUTY ) ) ; initJira ( router , getExternalServiceSimulatorPath ( ExternalServiceSimulator . JIRA ) ) ; initResilient ( router , getExternalServiceSimulatorPath ( ExternalServiceSimulator . RESILIENT ) ) ; initMSExchange ( router , getExternalServiceSimulatorPath ( ExternalServiceSimulator . MS_EXCHANGE ) ) ; } public start ( ) { } public stop ( ) { } }