Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit d452870

Browse files
[client] Improve vocabularies creation and edition
1 parent a2c47ab commit d452870

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

pycti/entities/opencti_vocabulary.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,34 @@ def read_or_create_unchecked(self, **kwargs):
144144
except ValueError:
145145
return None
146146
return vocab
147+
148+
def update_field(self, **kwargs):
149+
id = kwargs.get("id", None)
150+
input = kwargs.get("input", None)
151+
if id is not None and input is not None:
152+
self.opencti.log("info", "Updating Vocabulary {" + id + "}.")
153+
query = """
154+
mutation VocabularyEdit($id: ID!, $input: [EditInput!]!) {
155+
vocabularyFieldPatch(id: $id, input: $input) {
156+
id
157+
standard_id
158+
entity_type
159+
}
160+
}
161+
"""
162+
result = self.opencti.query(
163+
query,
164+
{
165+
"id": id,
166+
"input": input,
167+
},
168+
)
169+
return self.opencti.process_multiple_fields(
170+
result["data"]["vocabularyFieldPatch"]
171+
)
172+
else:
173+
self.opencti.log(
174+
"error",
175+
"[opencti_vocabulary] Missing parameters: id and key and value",
176+
)
177+
return None

pycti/utils/opencti_stix2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,8 +1968,8 @@ def import_bundle(
19681968
stix_id=item["id"],
19691969
name=item["name"],
19701970
category=item["category"],
1971-
description=item["description"],
1972-
aliases=item["aliases"],
1971+
description=item["description"] if "description" in item else None,
1972+
aliases=item["aliases"] if "aliases" in item else None,
19731973
x_opencti_stix_ids=stix_ids,
19741974
update=update,
19751975
)

pycti/utils/opencti_stix2_update.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ def update_attribute(self, entity_type, id, input):
246246
self.opencti.marking_definition.update_field(id=id, input=input)
247247
elif entity_type == "label":
248248
self.opencti.label.update_field(id=id, input=input)
249+
elif entity_type == "vocabulary":
250+
self.opencti.vocabulary.update_field(id=id, input=input)
249251
elif entity_type == "kill-chain-phase":
250252
self.opencti.kill_chain_phase.update_field(id=id, input=input)
251253
elif entity_type == "external-reference":

0 commit comments

Comments
 (0)