Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backend] add ability to validate draft and ingest it back through worker (#6577) #8659

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@
"Display name": "Name anzeigen",
"DLL service": "DLL-Dienst",
"Do you want to delete this support package?": "Möchten Sie dieses Support-Paket löschen?",
"Draft change": "Entwurfsänderung",
"Draft ids": "Entwurfs-Ids",
"Draft name": "Name des Entwurfs",
"Draft operation": "Entwurf einer Operation",
"DST": "DST",
"DST byte count": "DST-Byte-Anzahl",
"DST packets": "DST-Pakete",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@
"Display name": "Display name",
"DLL service": "DLL service",
"Do you want to delete this support package?": "Do you want to delete this support package?",
"Draft change": "Draft change",
"Draft ids": "Draft ids",
"Draft name": "Draft name",
"Draft operation": "Draft operation",
"DST": "DST",
"DST byte count": "DST byte count",
"DST packets": "DST packets",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@
"Display name": "Mostrar nombre",
"DLL service": "Servicio DLL",
"Do you want to delete this support package?": "¿Desea eliminar este paquete de soporte?",
"Draft change": "Proyecto de cambio",
"Draft ids": "Id. de borrador",
"Draft name": "Nombre del proyecto",
"Draft operation": "Operación borrador",
"DST": "DST",
"DST byte count": "DST byte count",
"DST packets": "Paquetes DST",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@
"Display name": "Nom d'affichage",
"DLL service": "Service DLL",
"Do you want to delete this support package?": "Voulez-vous supprimer ce paquet de support ?",
"Draft change": "Changement en brouillon",
"Draft ids": "Identifiants de draft",
"Draft name": "Nom du brouillon",
"Draft operation": "Opération de brouillon",
"DST": "DST",
"DST byte count": "Nombre d'octets DST",
"DST packets": "Paquets DST",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@
"Display name": "表示名",
"DLL service": "DLLサービス",
"Do you want to delete this support package?": "このサポートパッケージを削除しますか?",
"Draft change": "ドラフト変更",
"Draft ids": "ドラフトID",
"Draft name": "ドラフト名",
"Draft operation": "ドラフト操作",
"DST": "DST",
"DST byte count": "DST バイト数",
"DST packets": "DSTパケット",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@
"Display name": "표시 이름",
"DLL service": "DLL 서비스",
"Do you want to delete this support package?": "이 지원 패키지를 삭제하시겠습니까?",
"Draft change": "초안 변경",
"Draft ids": "초안 ID",
"Draft name": "초안 이름",
"Draft operation": "초안 작업",
"DST": "DST",
"DST byte count": "DST 바이트 수",
"DST packets": "DST 패킷",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@
"Display name": "显示名称",
"DLL service": "DLL 服务",
"Do you want to delete this support package?": "您想删除此支持包吗?",
"Draft change": "修改草案",
"Draft ids": "草案 ID",
"Draft name": "草案名称",
"Draft operation": "草案操作",
"DST": "DST",
"DST byte count": "DST 字节数",
"DST packets": "DST 数据包",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,7 @@
"INTERNAL_ENRICHMENT": "Anreicherung",
"INTERNAL_EXPORT_FILE": "Dateien exportieren",
"INTERNAL_IMPORT_FILE": "Dateien importieren",
"INTERNAL_INGESTION": "Dateneingabe",
"Interval": "Intervall",
"Interval between injections (in minute)": "Intervall zwischen den Injektionen (in Minuten)",
"Intrusion set": "Intrusion set",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,7 @@
"INTERNAL_ENRICHMENT": "Enrichment",
"INTERNAL_EXPORT_FILE": "Files export",
"INTERNAL_IMPORT_FILE": "Files import",
"INTERNAL_INGESTION": "Data ingestion",
"Interval": "Interval",
"Interval between injections (in minute)": "Interval between injections (in minute)",
"Intrusion set": "Intrusion set",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,7 @@
"INTERNAL_ENRICHMENT": "Enriquecimiento",
"INTERNAL_EXPORT_FILE": "Exportación de ficheros",
"INTERNAL_IMPORT_FILE": "Importación de ficheros",
"INTERNAL_INGESTION": "Ingesta de datos",
"Interval": "Intervalo",
"Interval between injections (in minute)": "Intervalo entre inyecciones (en minutos)",
"Intrusion set": "Set de intrusión",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,7 @@
"INTERNAL_ENRICHMENT": "Enrichissement",
"INTERNAL_EXPORT_FILE": "Export de fichiers",
"INTERNAL_IMPORT_FILE": "Import de fichiers",
"INTERNAL_INGESTION": "L'ingestion de données",
"Interval": "Intervalle",
"Interval between injections (in minute)": "Intervalle entre les injections (en minute)",
"Intrusion set": "Mode opératoire",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,7 @@
"INTERNAL_ENRICHMENT": "データエンリッチメント",
"INTERNAL_EXPORT_FILE": "ファイルエクスポート",
"INTERNAL_IMPORT_FILE": "ファイルインポート",
"INTERNAL_INGESTION": "データの取り込み",
"Interval": "インターバル",
"Interval between injections (in minute)": "注入間隔(分)",
"Intrusion set": "侵入セット",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,7 @@
"INTERNAL_ENRICHMENT": "풍부화",
"INTERNAL_EXPORT_FILE": "파일 내보내기",
"INTERNAL_IMPORT_FILE": "파일 가져오기",
"INTERNAL_INGESTION": "데이터 수집",
"Interval": "간격",
"Interval between injections (in minute)": "주입 간격 (분 단위)",
"Intrusion set": "침입 세트",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,7 @@
"INTERNAL_ENRICHMENT": "丰富",
"INTERNAL_EXPORT_FILE": "导出文件",
"INTERNAL_IMPORT_FILE": "导入文件",
"INTERNAL_INGESTION": "数据摄取",
"Interval": "时间间隔",
"Interval between injections (in minute)": "注射间隔时间(分钟)",
"Intrusion set": "入侵集合",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8715,6 +8715,7 @@ type Mutation {
supportPackageForceZip(input: SupportPackageForceZipInput!): SupportPackage
supportPackageDelete(id: ID!): ID
draftWorkspaceAdd(input: DraftWorkspaceAddInput!): DraftWorkspace
draftWorkspaceValidate(id: ID!): Work
draftWorkspaceDelete(id: ID!): ID
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import useAuth from './useAuth';
const ignoredAttributes = [
'id',
'draft_ids',
'draft_change',
'parent_types',
'base_type',
'internal_id',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { importCsvConnector, importCsvConnectorRuntime } from './importCsv/importCsv-domain';
import type { AuthContext, AuthUser } from '../types/user';
import { ENABLED_IMPORT_CSV_BUILT_IN_CONNECTOR } from './importCsv/importCsv-configuration';
import { DRAFT_VALIDATION_CONNECTOR, draftValidationConnectorRuntime } from '../modules/draftWorkspace/draftWorkspace-connector';
import { isFeatureEnabled } from '../config/conf';

export const builtInConnectorsRuntime = async (context: AuthContext, user: AuthUser) => {
const builtInConnectors = [];
if (ENABLED_IMPORT_CSV_BUILT_IN_CONNECTOR) {
const csvConnector = await importCsvConnectorRuntime(context, user);
builtInConnectors.push(csvConnector);
}
if (isFeatureEnabled('DRAFT_WORKSPACE')) {
builtInConnectors.push(await draftValidationConnectorRuntime());
}
return builtInConnectors;
};

export const builtInConnectors = () => {
return [importCsvConnector()];
return [importCsvConnector(), DRAFT_VALIDATION_CONNECTOR];
};

export const builtInConnector = (id: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const importCsvConnector = () => {

export const importCsvConnectorRuntime = async (context: AuthContext, user: AuthUser) => {
const connector = importCsvConnector();
const configurations = await connector.connector_schema_runtime_fn(context, user);
const configurations = connector.connector_schema_runtime_fn ? await connector.connector_schema_runtime_fn(context, user) : [];
const configurationsFiltered: BasicStoreEntityCsvMapper[] = [];
await Promise.all(configurations.map(async (c) => {
const mapperErrors = await getCsvMapperErrorMessage(context, user, c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ export interface Connector {
connector_type: string;
name: string;
built_in: boolean;
connector_schema_runtime_fn: <T extends BasicStoreEntityCsvMapper> (context: AuthContext, user: AuthUser) => Promise<T[]>;
connector_schema_runtime_fn?: <T extends BasicStoreEntityCsvMapper> (context: AuthContext, user: AuthUser) => Promise<T[]>;
}
24 changes: 23 additions & 1 deletion opencti-platform/opencti-graphql/src/database/draft-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import { getDraftContext } from '../utils/draftContext';
import { READ_INDEX_DRAFT_OBJECTS } from './utils';

export const buildDraftFilter = (context, user) => {
export const DRAFT_OPERATION_CREATE = 'create';
export const DRAFT_OPERATION_UPDATE = 'update';
export const DRAFT_OPERATION_DELETE = 'delete';
export const DRAFT_OPERATION_DELETE_LINKED = 'delete_linked';

export const buildDraftFilter = (context, user, opts = {}) => {
const { includeDeletedInDraft = false } = opts;
const draftContext = getDraftContext(context, user);
const draftMust = [];
if (draftContext) {
Expand All @@ -30,10 +36,26 @@
},
};
draftMust.push(draftBool);

if (!includeDeletedInDraft) {
const excludeDeletedDraft = {
bool: {
must_not: [
{ terms: { 'draft_change.draft_operation.keyword': [DRAFT_OPERATION_DELETE, DRAFT_OPERATION_DELETE_LINKED] } },
]
}
};
draftMust.push(excludeDeletedDraft);
}
}
return draftMust;
};

export const isDraftSupportedEntity = (element) => {
return !isInternalObject(element.entity_type) && !isInternalRelationship(element.entity_type);
};

// TODO: once update metadata is better refined, add it to draft_change
export const getDraftChanges = (initialInstance) => {
return initialInstance.draft_change ?? { draft_operation: DRAFT_OPERATION_UPDATE };
};

Check warning on line 61 in opencti-platform/opencti-graphql/src/database/draft-utils.js

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/database/draft-utils.js#L60-L61

Added lines #L60 - L61 were not covered by tests
Loading