Skip to content

Commit 23afbf3

Browse files
committed
[backend] Apply PRs suggestions after review
1 parent 85c139e commit 23afbf3

File tree

5 files changed

+62
-112
lines changed

5 files changed

+62
-112
lines changed

opencti-platform/opencti-dev/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ services:
122122
- 15672:15672
123123

124124
## Telemetry + tracing dependencies
125-
## docker compose --profile telemetry up -d (launch everything + telemetry)
125+
## podman compose --profile telemetry up -d (launch everything + telemetry)
126126
opencti-dev-telemetry-pyroscope:
127127
container_name: opencti-pyroscope
128128
image: grafana/pyroscope

opencti-platform/opencti-graphql/src/database/attachment-processor-props.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

opencti-platform/opencti-graphql/src/database/engine.ts

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ import { DRAFT_OPERATION_CREATE, DRAFT_OPERATION_DELETE, DRAFT_OPERATION_DELETE_
175175
import { RELATION_SAMPLE } from '../modules/malwareAnalysis/malwareAnalysis-types';
176176
import { asyncMap } from '../utils/data-processing';
177177
import { doYield } from '../utils/eventloop-utils';
178-
import type { Mutable } from '../utils/type-utils';
179178
import { RELATION_COVERED } from '../modules/securityCoverage/securityCoverage-types';
180179
import type { AuthContext, AuthUser } from '../types/user';
181180
import type {
@@ -310,7 +309,39 @@ export const elConfigureAttachmentProcessor = async (): Promise<boolean> => {
310309
attachment: {
311310
field: 'file_data',
312311
remove_binary: true,
313-
properties: ATTACHMENT_PROCESSOR_EXTRACTED_PROPS_ELASTICSEARCH as Mutable<typeof ATTACHMENT_PROCESSOR_EXTRACTED_PROPS_ELASTICSEARCH>,
312+
// List of fields extracted by the attachment ingest processor.
313+
// The full list is available in the Elasticsearch docs:
314+
// (https://www.elastic.co/guide/en/elasticsearch/reference/8.19/attachment.html#attachment-fields).
315+
properties: [
316+
'content',
317+
'title',
318+
'author',
319+
'keywords',
320+
'date',
321+
'content_type',
322+
'content_length',
323+
'language',
324+
'modified',
325+
'format',
326+
// identifier, NOT EXTRACTED
327+
// contributor, NOT EXTRACTED
328+
// coverage, NOT EXTRACTED
329+
'modifier',
330+
'creator_tool',
331+
// publisher, NOT EXTRACTED
332+
// relation, NOT EXTRACTED
333+
// rights, NOT EXTRACTED
334+
// source, NOT EXTRACTED
335+
// type, NOT EXTRACTED
336+
'description',
337+
'print_date',
338+
'metadata_date',
339+
// latitude, NOT EXTRACTED
340+
// longitude, NOT EXTRACTED
341+
// altitude, NOT EXTRACTED
342+
// rating, NOT EXTRACTED
343+
'comments',
344+
],
314345
},
315346
},
316347
],
@@ -327,7 +358,21 @@ export const elConfigureAttachmentProcessor = async (): Promise<boolean> => {
327358
{
328359
attachment: {
329360
field: 'file_data',
330-
properties: ATTACHMENT_PROCESSOR_EXTRACTED_PROPS_OPENSEARCH as Mutable<typeof ATTACHMENT_PROCESSOR_EXTRACTED_PROPS_OPENSEARCH>,
361+
// List of fields extracted by the attachment ingest processor, for OpenSearch.
362+
// The full list is available in the OS docs:
363+
// (https://docs.opensearch.org/latest/install-and-configure/additional-plugins/ingest-attachment-plugin/#extracted-information),
364+
// and code shows the check rejects unknown fields with an exception:
365+
// https://github.com/opensearch-project/OpenSearch/blob/315481148edaa43410e2e9f1801ec903fd62ec20/plugins/ingest-attachment/src/main/java/org/opensearch/ingest/attachment/AttachmentProcessor.java#L277
366+
properties: [
367+
'content',
368+
'title',
369+
'author',
370+
'keywords',
371+
'date',
372+
'content_type',
373+
'content_length',
374+
'language',
375+
],
331376
},
332377
},
333378
{
@@ -2746,11 +2791,11 @@ const buildSubQueryForFilterGroup = (
27462791

27472792
const currentSubQuery = localMustFilters.length > 0
27482793
? {
2749-
bool: {
2750-
should: localMustFilters,
2751-
minimum_should_match: mode === 'or' ? 1 : localMustFilters.length,
2752-
},
2753-
}
2794+
bool: {
2795+
should: localMustFilters,
2796+
minimum_should_match: mode === 'or' ? 1 : localMustFilters.length,
2797+
},
2798+
}
27542799
: null;
27552800
return { subQuery: currentSubQuery, postFiltersTags: localPostFilterTags, resultSaltCount: localSaltCount };
27562801
};
@@ -3123,12 +3168,12 @@ const tagFiltersForPostFiltering = (
31233168
) => {
31243169
const taggedFilters: (Filter & { postFilteringTag: string })[] = filters
31253170
? extractFiltersFromGroup(filters, [INSTANCE_REGARDING_OF, INSTANCE_DYNAMIC_REGARDING_OF])
3126-
.filter((filter) => isEmptyField(filter.operator) || filter.operator === 'eq')
3127-
.map((filter, i) => {
3128-
const taggedFilter = filter as Filter & { postFilteringTag: string };
3129-
taggedFilter.postFilteringTag = `${i}`;
3130-
return taggedFilter;
3131-
})
3171+
.filter((filter) => isEmptyField(filter.operator) || filter.operator === 'eq')
3172+
.map((filter, i) => {
3173+
const taggedFilter = filter as Filter & { postFilteringTag: string };
3174+
taggedFilter.postFilteringTag = `${i}`;
3175+
return taggedFilter;
3176+
})
31323177
: [];
31333178

31343179
if (taggedFilters.length > 0) {

opencti-platform/opencti-graphql/src/modules/internal/document/document.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { assertType } from '../../../utils/type-utils';
2-
import type { AttachmentProcessorExtractedProp } from '../../../database/attachment-processor-props';
31
import { ENTITY_TYPE_INTERNAL_FILE } from '../../../schema/internalObject';
42
import { schemaAttributesDefinition } from '../../../schema/schema-attributes';
53
import { type AttributeDefinition, createdAt, creators, entityType, id, internalId, parentTypes, refreshedAt, standardId, updatedAt } from '../../../schema/attribute-definition';
64
import { ENTITY_TYPE_MARKING_DEFINITION } from '../../../schema/stixMetaObject';
75
import { ABSTRACT_STIX_CORE_OBJECT } from '../../../schema/general';
86
import { UPLOAD_STATUS_VALUES } from './document-domain';
97

10-
const attributes = [
8+
const attributes: Array<AttributeDefinition> = [
119
id,
1210
internalId,
1311
standardId,
@@ -95,17 +93,6 @@ const attributes = [
9593
{ name: 'file_id', label: 'File identifier', type: 'string', format: 'short', mandatoryType: 'internal', editDefault: false, multiple: false, upsert: false, isFilterable: false },
9694
{ name: 'entity_id', label: 'Related entity', type: 'string', format: 'id', entityTypes: [ABSTRACT_STIX_CORE_OBJECT], mandatoryType: 'internal', editDefault: false, multiple: false, upsert: false, isFilterable: false },
9795
{ name: 'removed', label: 'Removed', type: 'boolean', mandatoryType: 'no', editDefault: false, multiple: false, upsert: false, isFilterable: false },
98-
] as const satisfies Array<AttributeDefinition>;
99-
100-
const attachmentAttributes = attributes[18];
101-
102-
type AttachmentAttributeMappingNames = typeof attachmentAttributes.mappings[number]['name'][];
103-
104-
// Make sure there's an attachment mapping for each field extracted
105-
// by the `attachment` ingest processor, exhaustively.
106-
assertType<
107-
AttachmentAttributeMappingNames,
108-
AttachmentProcessorExtractedProp[]
109-
>(attachmentAttributes.mappings.map(({ name }) => name));
96+
];
11097

11198
schemaAttributesDefinition.registerAttributes(ENTITY_TYPE_INTERNAL_FILE, attributes);

opencti-platform/opencti-graphql/src/utils/type-utils.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)