-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SIEM][CASE] Refactor Connectors - Jira Connector (#63450)
- Loading branch information
Showing
84 changed files
with
5,330 additions
and
3,235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
x-pack/plugins/actions/server/builtin_action_types/case/api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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 { | ||
ExternalServiceApi, | ||
ExternalServiceParams, | ||
PushToServiceResponse, | ||
GetIncidentApiHandlerArgs, | ||
HandshakeApiHandlerArgs, | ||
PushToServiceApiHandlerArgs, | ||
} from './types'; | ||
import { prepareFieldsForTransformation, transformFields, transformComments } from './utils'; | ||
|
||
const handshakeHandler = async ({ | ||
externalService, | ||
mapping, | ||
params, | ||
}: HandshakeApiHandlerArgs) => {}; | ||
const getIncidentHandler = async ({ | ||
externalService, | ||
mapping, | ||
params, | ||
}: GetIncidentApiHandlerArgs) => {}; | ||
|
||
const pushToServiceHandler = async ({ | ||
externalService, | ||
mapping, | ||
params, | ||
}: PushToServiceApiHandlerArgs): Promise<PushToServiceResponse> => { | ||
const { externalId, comments } = params; | ||
const updateIncident = externalId ? true : false; | ||
const defaultPipes = updateIncident ? ['informationUpdated'] : ['informationCreated']; | ||
let currentIncident: ExternalServiceParams | undefined; | ||
let res: PushToServiceResponse; | ||
|
||
if (externalId) { | ||
currentIncident = await externalService.getIncident(externalId); | ||
} | ||
|
||
const fields = prepareFieldsForTransformation({ | ||
params, | ||
mapping, | ||
defaultPipes, | ||
}); | ||
|
||
const incident = transformFields({ | ||
params, | ||
fields, | ||
currentIncident, | ||
}); | ||
|
||
if (updateIncident) { | ||
res = await externalService.updateIncident({ incidentId: externalId, incident }); | ||
} else { | ||
res = await externalService.createIncident({ incident }); | ||
} | ||
|
||
if ( | ||
comments && | ||
Array.isArray(comments) && | ||
comments.length > 0 && | ||
mapping.get('comments')?.actionType !== 'nothing' | ||
) { | ||
const commentsTransformed = transformComments(comments, ['informationAdded']); | ||
|
||
res.comments = []; | ||
for (const currentComment of commentsTransformed) { | ||
const comment = await externalService.createComment({ | ||
incidentId: res.id, | ||
comment: currentComment, | ||
field: mapping.get('comments')?.target ?? 'comments', | ||
}); | ||
res.comments = [ | ||
...(res.comments ?? []), | ||
{ | ||
commentId: comment.commentId, | ||
pushedDate: comment.pushedDate, | ||
}, | ||
]; | ||
} | ||
} | ||
|
||
return res; | ||
}; | ||
|
||
export const api: ExternalServiceApi = { | ||
handshake: handshakeHandler, | ||
pushToService: pushToServiceHandler, | ||
getIncident: getIncidentHandler, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
x-pack/plugins/actions/server/builtin_action_types/case/schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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 { schema } from '@kbn/config-schema'; | ||
|
||
export const MappingActionType = schema.oneOf([ | ||
schema.literal('nothing'), | ||
schema.literal('overwrite'), | ||
schema.literal('append'), | ||
]); | ||
|
||
export const MapRecordSchema = schema.object({ | ||
source: schema.string(), | ||
target: schema.string(), | ||
actionType: MappingActionType, | ||
}); | ||
|
||
export const CaseConfigurationSchema = schema.object({ | ||
mapping: schema.arrayOf(MapRecordSchema), | ||
}); | ||
|
||
export const ExternalIncidentServiceConfiguration = { | ||
apiUrl: schema.string(), | ||
casesConfiguration: CaseConfigurationSchema, | ||
}; | ||
|
||
export const ExternalIncidentServiceConfigurationSchema = schema.object( | ||
ExternalIncidentServiceConfiguration | ||
); | ||
|
||
export const ExternalIncidentServiceSecretConfiguration = { | ||
password: schema.string(), | ||
username: schema.string(), | ||
}; | ||
|
||
export const ExternalIncidentServiceSecretConfigurationSchema = schema.object( | ||
ExternalIncidentServiceSecretConfiguration | ||
); | ||
|
||
export const UserSchema = schema.object({ | ||
fullName: schema.nullable(schema.string()), | ||
username: schema.nullable(schema.string()), | ||
}); | ||
|
||
const EntityInformation = { | ||
createdAt: schema.string(), | ||
createdBy: UserSchema, | ||
updatedAt: schema.nullable(schema.string()), | ||
updatedBy: schema.nullable(UserSchema), | ||
}; | ||
|
||
export const EntityInformationSchema = schema.object(EntityInformation); | ||
|
||
export const CommentSchema = schema.object({ | ||
commentId: schema.string(), | ||
comment: schema.string(), | ||
...EntityInformation, | ||
}); | ||
|
||
export const ExecutorSubActionSchema = schema.oneOf([ | ||
schema.literal('getIncident'), | ||
schema.literal('pushToService'), | ||
schema.literal('handshake'), | ||
]); | ||
|
||
export const ExecutorSubActionPushParamsSchema = schema.object({ | ||
caseId: schema.string(), | ||
title: schema.string(), | ||
description: schema.nullable(schema.string()), | ||
comments: schema.nullable(schema.arrayOf(CommentSchema)), | ||
externalId: schema.nullable(schema.string()), | ||
...EntityInformation, | ||
}); | ||
|
||
export const ExecutorSubActionGetIncidentParamsSchema = schema.object({ | ||
externalId: schema.string(), | ||
}); | ||
|
||
// Reserved for future implementation | ||
export const ExecutorSubActionHandshakeParamsSchema = schema.object({}); | ||
|
||
export const ExecutorParamsSchema = schema.oneOf([ | ||
schema.object({ | ||
subAction: schema.literal('getIncident'), | ||
subActionParams: ExecutorSubActionGetIncidentParamsSchema, | ||
}), | ||
schema.object({ | ||
subAction: schema.literal('handshake'), | ||
subActionParams: ExecutorSubActionHandshakeParamsSchema, | ||
}), | ||
schema.object({ | ||
subAction: schema.literal('pushToService'), | ||
subActionParams: ExecutorSubActionPushParamsSchema, | ||
}), | ||
]); |
Oops, something went wrong.