Skip to content

Commit

Permalink
[client] Refactor batch list through (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelHassine authored Jan 29, 2024
1 parent 5b61722 commit 16c8fe1
Show file tree
Hide file tree
Showing 39 changed files with 1,354 additions and 2,329 deletions.
14 changes: 14 additions & 0 deletions pycti/api/opencti_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,18 @@ def process_multiple(self, data: dict, with_pagination=False) -> Union[dict, lis
result = []
if data is None:
return result

# Data can be multiple in edges or directly.
# -- When data is directly a listing
if isinstance(data, list):
for row in data:
if with_pagination:
result["entities"].append(self.process_multiple_fields(row))
else:
result.append(self.process_multiple_fields(row))
return result

# -- When data is wrapper in edges
for edge in (
data["edges"] if "edges" in data and data["edges"] is not None else []
):
Expand All @@ -466,6 +478,8 @@ def process_multiple(self, data: dict, with_pagination=False) -> Union[dict, lis
result["entities"].append(self.process_multiple_fields(row))
else:
result.append(self.process_multiple_fields(row))

# -- Add page info if required
if with_pagination and "pageInfo" in data:
result["pagination"] = data["pageInfo"]
return result
Expand Down
124 changes: 46 additions & 78 deletions pycti/entities/opencti_attack_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ def __init__(self, opencti):
created
modified
objectLabel {
edges {
node {
id
value
color
}
}
id
value
color
}
}
... on Organization {
Expand All @@ -52,28 +48,20 @@ def __init__(self, opencti):
}
}
objectMarking {
edges {
node {
id
standard_id
entity_type
definition_type
definition
created
modified
x_opencti_order
x_opencti_color
}
}
id
standard_id
entity_type
definition_type
definition
created
modified
x_opencti_order
x_opencti_color
}
objectLabel {
edges {
node {
id
value
color
}
}
id
value
color
}
externalReferences {
edges {
Expand Down Expand Up @@ -103,18 +91,14 @@ def __init__(self, opencti):
x_mitre_detection
x_mitre_id
killChainPhases {
edges {
node {
id
standard_id
entity_type
kill_chain_name
phase_name
x_opencti_order
created
modified
}
}
id
standard_id
entity_type
kill_chain_name
phase_name
x_opencti_order
created
modified
}
"""
self.properties_with_files = """
Expand All @@ -141,13 +125,9 @@ def __init__(self, opencti):
created
modified
objectLabel {
edges {
node {
id
value
color
}
}
id
value
color
}
}
... on Organization {
Expand All @@ -160,28 +140,20 @@ def __init__(self, opencti):
}
}
objectMarking {
edges {
node {
id
standard_id
entity_type
definition_type
definition
created
modified
x_opencti_order
x_opencti_color
}
}
id
standard_id
entity_type
definition_type
definition
created
modified
x_opencti_order
x_opencti_color
}
objectLabel {
edges {
node {
id
value
color
}
}
id
value
color
}
externalReferences {
edges {
Expand Down Expand Up @@ -224,18 +196,14 @@ def __init__(self, opencti):
x_mitre_detection
x_mitre_id
killChainPhases {
edges {
node {
id
standard_id
entity_type
kill_chain_name
phase_name
x_opencti_order
created
modified
}
}
id
standard_id
entity_type
kill_chain_name
phase_name
x_opencti_order
created
modified
}
importFiles {
edges {
Expand Down
84 changes: 30 additions & 54 deletions pycti/entities/opencti_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ def __init__(self, opencti):
created
modified
objectLabel {
edges {
node {
id
value
color
}
}
id
value
color
}
}
... on Organization {
Expand All @@ -52,28 +48,20 @@ def __init__(self, opencti):
}
}
objectMarking {
edges {
node {
id
standard_id
entity_type
definition_type
definition
created
modified
x_opencti_order
x_opencti_color
}
}
id
standard_id
entity_type
definition_type
definition
created
modified
x_opencti_order
x_opencti_color
}
objectLabel {
edges {
node {
id
value
color
}
}
id
value
color
}
externalReferences {
edges {
Expand Down Expand Up @@ -126,13 +114,9 @@ def __init__(self, opencti):
created
modified
objectLabel {
edges {
node {
id
value
color
}
}
id
value
color
}
}
... on Organization {
Expand All @@ -145,28 +129,20 @@ def __init__(self, opencti):
}
}
objectMarking {
edges {
node {
id
standard_id
entity_type
definition_type
definition
created
modified
x_opencti_order
x_opencti_color
}
}
id
standard_id
entity_type
definition_type
definition
created
modified
x_opencti_order
x_opencti_color
}
objectLabel {
edges {
node {
id
value
color
}
}
id
value
color
}
externalReferences {
edges {
Expand Down
Loading

0 comments on commit 16c8fe1

Please sign in to comment.