Skip to content

Commit b8616d6

Browse files
authored
Merge pull request #14 from sqall01/master
added link_add() API and added missing arguments for observable_bulk_…
2 parents 57e0789 + 1c6e16a commit b8616d6

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

pyeti/api.py

+44-5
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,34 @@ def analysis_match(self, observables):
7878
json = {"observables": observables}
7979
return self._make_post("analysis/match", json=json)
8080

81+
def link_add(self, link_src, link_dst, type_src="observable", type_dst="observable", description=None, source="API"):
82+
"""Add link between to entities to the dataset
83+
84+
Args:
85+
link_src: The internal Yeti ID for the source entity to link
86+
link_dst: The internal Yeti ID for the destination entity to link
87+
type_src: Type of the entity (either "observable", "entity", or "indicator")
88+
type_dst: Type of the entity (either "observable", "entity", or "indicator")
89+
description: A string description of the link
90+
source: A string representing the source of the data. Defaults to "API".
91+
92+
Returns:
93+
JSON representation of the created link.
94+
"""
95+
96+
json = {
97+
"link_src": link_src,
98+
"link_dst": link_dst,
99+
"type_src": type_src,
100+
"type_dst": type_dst,
101+
"source": source,
102+
}
103+
104+
if description is not None:
105+
json["description"] = description
106+
107+
return self._make_post('link/', json=json)
108+
81109
def observable_search(self, count=50, offset=1, regex=False, **kwargs):
82110
"""Search for observables.
83111
:param count: How many Observables you want to fetch.
@@ -287,14 +315,25 @@ def observable_file_contents(self, objectid=None, filehash=None):
287315
else:
288316
raise ValueError("You need to pass an id or hash parameter.")
289317

290-
def observable_bulk_add(self, observables, tags=None):
291-
"""Add an observables in bulk mode to the dataset
292-
:param observables: list observables to add in yeti
293-
:return JSON representation of the created observable.
318+
319+
def observable_bulk_add(self, observables, tags=None, context=None, source="API"):
320+
"""Add an observable to the dataset
321+
322+
Args:
323+
observables: list of Observable value
324+
tags: An array of strings representing tags
325+
context: A dictionary object with context information
326+
source: A string representing the source of the data. Defaults to
327+
"API".
328+
329+
Returns:
330+
JSON representation of the created observable.
294331
"""
295332
if tags is None:
296333
tags = []
297-
json = {"observables": [{"tags": tags, "value": o} for o in observables]}
334+
if context is None:
335+
context = {}
336+
json = {"observables": [{"tags": tags, "value": o, "source": source, "context": context} for o in observables]}
298337
return self._make_post('observable/bulk', json=json)
299338

300339
def get_analytic_oneshot(self, name_of_oneshot):

0 commit comments

Comments
 (0)