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

Updated the API to make possible bulk add with a specified type #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions pyeti/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def observable_file_contents(self, objectid=None, filehash=None):
raise ValueError("You need to pass an id or hash parameter.")


def observable_bulk_add(self, observables, tags=None, context=None, source="API"):
def observable_bulk_add(self, observables, tags=None, context=None, source="API", enforce_type=False, enforced_type="Text"):
"""Add an observable to the dataset

Args:
Expand All @@ -325,6 +325,8 @@ def observable_bulk_add(self, observables, tags=None, context=None, source="API"
context: A dictionary object with context information
source: A string representing the source of the data. Defaults to
"API".
enforce_type: Force the type of added data.
enforced_type: A string representing the type of data to add.

Returns:
JSON representation of the created observable.
Expand All @@ -333,7 +335,10 @@ def observable_bulk_add(self, observables, tags=None, context=None, source="API"
tags = []
if context is None:
context = {}
json = {"observables": [{"tags": tags, "value": o, "source": source, "context": context} for o in observables]}
if enforce_type:
json = {"observables": [{"tags": tags, "value": o, "source": source, "context": context, "force_type":enforced_type} for o in observables]}
else:
json = {"observables": [{"tags": tags, "value": o, "source": source, "context": context} for o in observables]}
return self._make_post('observable/bulk', json=json)

def get_analytic_oneshot(self, name_of_oneshot):
Expand Down