-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backend] added DeleteOperation module
- Loading branch information
1 parent
626d6b7
commit 8529985
Showing
17 changed files
with
384 additions
and
11 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 119 additions & 4 deletions
123
opencti-platform/opencti-graphql/src/generated/graphql.ts
Large diffs are not rendered by default.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
opencti-platform/opencti-graphql/src/modules/deleteOperation/deleteOperation-converter.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,23 @@ | ||
import { buildStixObject, cleanObject } from '../../database/stix-converter'; | ||
import { STIX_EXT_OCTI } from '../../types/stix-extensions'; | ||
import type { StixDeleteOperation, StoreEntityDeleteOperation } from './deleteOperation-types'; | ||
|
||
const convertDeleteOperationToStix = (instance: StoreEntityDeleteOperation): StixDeleteOperation => { | ||
const stixObject = buildStixObject(instance); | ||
return { | ||
...stixObject, | ||
timestamp: instance.timestamp, | ||
user_id: instance.user_id, | ||
main_entity_type: instance.main_entity_type, | ||
main_entity_id: instance.main_entity_id, | ||
main_entity_name: instance.main_entity_name, | ||
extensions: { | ||
[STIX_EXT_OCTI]: cleanObject({ | ||
...stixObject.extensions[STIX_EXT_OCTI], | ||
extension_type: 'new-sdo', | ||
}) | ||
} | ||
}; | ||
}; | ||
|
||
export default convertDeleteOperationToStix; |
27 changes: 27 additions & 0 deletions
27
opencti-platform/opencti-graphql/src/modules/deleteOperation/deleteOperation-domain.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,27 @@ | ||
import type { AuthContext, AuthUser } from '../../types/user'; | ||
import { listEntitiesPaginated, storeLoadById } from '../../database/middleware-loader'; | ||
import type { QueryDeleteOperationsArgs } from '../../generated/graphql'; | ||
import { type BasicStoreEntityDeleteOperation, ENTITY_TYPE_DELETE_OPERATION } from './deleteOperation-types'; | ||
|
||
export interface DeletedElement { | ||
id: string | ||
source_index: string | ||
} | ||
|
||
export const findById = (context: AuthContext, user: AuthUser, id: string) => { | ||
return storeLoadById<BasicStoreEntityDeleteOperation>(context, user, id, ENTITY_TYPE_DELETE_OPERATION); | ||
}; | ||
|
||
export const findAll = (context: AuthContext, user: AuthUser, args: QueryDeleteOperationsArgs) => { | ||
return listEntitiesPaginated<BasicStoreEntityDeleteOperation>(context, user, [ENTITY_TYPE_DELETE_OPERATION], args); | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export const restoreDelete = (context: AuthContext, user: AuthUser, id: string) => { | ||
throw new Error('Restore delete not implemented'); | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export const completeDelete = (context: AuthContext, user: AuthUser, id: string) => { | ||
throw new Error('Complete delete not implemented'); | ||
}; |
8 changes: 8 additions & 0 deletions
8
opencti-platform/opencti-graphql/src/modules/deleteOperation/deleteOperation-graphql.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,8 @@ | ||
import { registerGraphqlSchema } from '../../graphql/schema'; | ||
import deleteOperationTypeDefs from './deleteOperation.graphql'; | ||
import deleteOperationResolvers from './deleteOperation-resolvers'; | ||
|
||
registerGraphqlSchema({ | ||
schema: deleteOperationTypeDefs, | ||
resolver: deleteOperationResolvers, | ||
}); |
19 changes: 19 additions & 0 deletions
19
opencti-platform/opencti-graphql/src/modules/deleteOperation/deleteOperation-resolvers.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,19 @@ | ||
import type { Resolvers } from '../../generated/graphql'; | ||
import { completeDelete, findAll, findById, restoreDelete } from './deleteOperation-domain'; | ||
|
||
const deleteOperationResolvers: Resolvers = { | ||
Query: { | ||
deleteOperation: (_, { id }, context) => findById(context, context.user, id), | ||
deleteOperations: (_, args, context) => findAll(context, context.user, args), | ||
}, | ||
Mutation: { | ||
deleteOperationRestore: (_, { id }, context) => { | ||
return restoreDelete(context, context.user, id); | ||
}, | ||
deleteOperationConfirm: (_, { id }, context) => { | ||
return completeDelete(context, context.user, id); | ||
}, | ||
} | ||
}; | ||
|
||
export default deleteOperationResolvers; |
29 changes: 29 additions & 0 deletions
29
opencti-platform/opencti-graphql/src/modules/deleteOperation/deleteOperation-types.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,29 @@ | ||
import type { StixObject, StixOpenctiExtensionSDO } from '../../types/stix-common'; | ||
import { STIX_EXT_OCTI } from '../../types/stix-extensions'; | ||
import type { BasicStoreEntity, StoreEntity } from '../../types/store'; | ||
import type { DeletedElement } from './deleteOperation-domain'; | ||
|
||
export const ENTITY_TYPE_DELETE_OPERATION = 'DeleteOperation'; | ||
|
||
export interface BasicStoreEntityDeleteOperation extends BasicStoreEntity { | ||
timestamp: Date | ||
user_id: string | ||
main_entity_type: string | ||
main_entity_id: string | ||
main_entity_name: string | ||
deleted_elements: Array<DeletedElement> | ||
} | ||
|
||
export interface StoreEntityDeleteOperation extends BasicStoreEntityDeleteOperation, StoreEntity { | ||
} | ||
|
||
export interface StixDeleteOperation extends StixObject { | ||
timestamp: Date | ||
user_id: string | ||
main_entity_type: string | ||
main_entity_id: string | ||
main_entity_name: string | ||
extensions: { | ||
[STIX_EXT_OCTI]: StixOpenctiExtensionSDO | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
opencti-platform/opencti-graphql/src/modules/deleteOperation/deleteOperation.graphql
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,55 @@ | ||
# Type | ||
type DeletedElement | ||
{ | ||
id: String! | ||
source_index: String! | ||
} | ||
|
||
type DeleteOperation implements InternalObject & BasicObject { | ||
id: ID! | ||
entity_type: String! | ||
standard_id: String! | ||
parent_types: [String!]! | ||
# DeleteOperation | ||
timestamp: DateTime! | ||
user_id: String! | ||
main_entity_type: String! | ||
main_entity_id: String! | ||
main_entity_name: String! | ||
deleted_elements: [DeletedElement!]! | ||
} | ||
|
||
# Ordering | ||
enum DeleteOperationOrdering { | ||
timestamp | ||
} | ||
|
||
# Relay connections | ||
type DeleteOperationConnection { | ||
pageInfo: PageInfo! | ||
edges: [DeleteOperationEdge!]! | ||
} | ||
|
||
type DeleteOperationEdge { | ||
cursor: String! | ||
node: DeleteOperation! | ||
} | ||
|
||
# Queries | ||
type Query { | ||
deleteOperation(id: String!): DeleteOperation | ||
deleteOperations( | ||
first: Int | ||
after: ID | ||
orderBy: DeleteOperationOrdering | ||
orderMode: OrderingMode | ||
filters: FilterGroup | ||
search: String | ||
): DeleteOperationConnection | ||
} | ||
|
||
# Mutations | ||
type Mutation { | ||
deleteOperationRestore(id: ID!): ID @auth(for: [KNOWLEDGE_KNUPDATE_KNDELETE]) | ||
deleteOperationConfirm(id: ID!): ID @auth(for: [KNOWLEDGE_KNUPDATE_KNDELETE]) | ||
} |
34 changes: 34 additions & 0 deletions
34
opencti-platform/opencti-graphql/src/modules/deleteOperation/deleteOperation.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,34 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { ABSTRACT_INTERNAL_OBJECT } from '../../schema/general'; | ||
import { type ModuleDefinition, registerDefinition } from '../../schema/module'; | ||
import { ENTITY_TYPE_DELETE_OPERATION, type StixDeleteOperation, type StoreEntityDeleteOperation } from './deleteOperation-types'; | ||
import convertDeleteOperationToStix from './deleteOperation-converter'; | ||
|
||
const DELETE_OPERATION_DEFINITION: ModuleDefinition<StoreEntityDeleteOperation, StixDeleteOperation> = { | ||
type: { | ||
id: 'deleteOperation', | ||
name: ENTITY_TYPE_DELETE_OPERATION, | ||
category: ABSTRACT_INTERNAL_OBJECT, | ||
aliased: false | ||
}, | ||
identifier: { | ||
definition: { | ||
[ENTITY_TYPE_DELETE_OPERATION]: () => uuidv4() | ||
}, | ||
}, | ||
attributes: [ | ||
{ name: 'timestamp', label: 'Timestamp', type: 'date', mandatoryType: 'internal', editDefault: false, multiple: false, upsert: false, isFilterable: true }, | ||
{ name: 'user_id', label: 'User_id', type: 'string', format: 'short', mandatoryType: 'internal', editDefault: false, multiple: false, upsert: false, isFilterable: true }, | ||
{ name: 'main_entity_type', label: 'Deleted entity type', type: 'string', format: 'short', mandatoryType: 'internal', editDefault: false, multiple: false, upsert: false, isFilterable: true }, | ||
{ name: 'main_entity_id', label: 'Deleted entity id', type: 'string', format: 'short', mandatoryType: 'internal', editDefault: false, multiple: false, upsert: false, isFilterable: true }, | ||
{ name: 'main_entity_name', label: 'Deleted entity name', type: 'string', format: 'short', mandatoryType: 'internal', editDefault: false, multiple: false, upsert: false, isFilterable: true }, | ||
{ name: 'deleted_elements', label: 'Deleted elements', type: 'object', format: 'flat', mandatoryType: 'no', editDefault: false, multiple: true, upsert: false, isFilterable: false }, | ||
], | ||
relations: [], | ||
representative: (stix: StixDeleteOperation) => { | ||
return stix.main_entity_name; | ||
}, | ||
converter: convertDeleteOperationToStix | ||
}; | ||
|
||
registerDefinition(DELETE_OPERATION_DEFINITION); |
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