Skip to content

Commit

Permalink
[all] Release the new Python client
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Hassine committed Jul 11, 2019
1 parent 3445ae8 commit 29fec30
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/stix2/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
config = yaml.load(open(os.path.dirname(__file__) + '/../config.yml'))

# File to import
file_to_import = './enterprise-attack.json'
file_to_import = '/home/oxid/Dropbox/Developpement/Associations/Luatix/Produits/OpenCTI/cti/enterprise-attack/enterprise-attack.json'

# OpenCTI initialization
opencti_api_client = OpenCTIApiClient(config['opencti']['url'], config['opencti']['token'])
Expand Down
13 changes: 7 additions & 6 deletions pycti/opencti_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ class OpenCTIApiClient:
"""

def __init__(self, url, token, log_level='info'):
self.log_level = log_level
# Configure logger
numeric_level = getattr(logging, log_level.upper(), None)
numeric_level = getattr(logging, self.log_level.upper(), None)
if not isinstance(numeric_level, int):
raise ValueError('Invalid log level: ' + log_level)
raise ValueError('Invalid log level: ' + self.log_level)
logging.basicConfig(level=numeric_level)

self.api_url = url + '/graphql'
Expand Down Expand Up @@ -3565,16 +3566,16 @@ def stix2_import_bundle_from_file(self, file_path, update=False, types=[]):
with open(os.path.join(file_path)) as file:
data = json.load(file)

stix2 = OpenCTIStix2(self, log_level)
stix2 = OpenCTIStix2(self, self.log_level)
stix2.import_bundle(data, update, types)

def stix2_import_bundle(self, json_data, update=False, types=[]):
data = json.loads(json_data)
stix2 = OpenCTIStix2(self, log_level)
stix2 = OpenCTIStix2(self, self.log_level)
stix2.import_bundle(data, update, types)

def stix2_export_entity(self, entity_type, entity_id, mode='simple'):
stix2 = OpenCTIStix2(self, log_level)
stix2 = OpenCTIStix2(self, self.log_level)
bundle = {
'type': 'bundle',
'id': 'bundle--' + str(uuid.uuid4()),
Expand All @@ -3589,7 +3590,7 @@ def stix2_export_entity(self, entity_type, entity_id, mode='simple'):
return bundle

def stix2_export_bundle(self, types=[]):
stix2 = OpenCTIStix2(self, log_level)
stix2 = OpenCTIStix2(self, self.log_level)
uuids = []
bundle = {
'type': 'bundle',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
print("warning: pypandoc module not found, could not convert Markdown to RST")
read_md = lambda f: open(f, 'r').read()

VERSION = "1.2.8"
VERSION = "1.2.9"


class VerifyVersionCommand(install):
Expand Down

0 comments on commit 29fec30

Please sign in to comment.