-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
134 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from typing import List | ||
|
||
from cortex4py.query import * | ||
from .abstract import AbstractController | ||
from ..models import Responder, Job, ResponderDefinition | ||
|
||
|
||
class RespondersController(AbstractController): | ||
def __init__(self, api): | ||
AbstractController.__init__(self, 'responder', api) | ||
|
||
def find_all(self, query, **kwargs) -> List[Responder]: | ||
return self._wrap(self._find_all(query, **kwargs), Responder) | ||
|
||
def find_one_by(self, query, **kwargs) -> Responder: | ||
return self._wrap(self._find_one_by(query, **kwargs), Responder) | ||
|
||
def get_by_id(self, worker_id) -> Responder: | ||
return self._wrap(self._get_by_id(worker_id), Responder) | ||
|
||
def get_by_name(self, name) -> Responder: | ||
return self._wrap(self._find_one_by(Eq('name', name)), Responder) | ||
|
||
def get_by_type(self, data_type) -> List[Responder]: | ||
return self._wrap(self._api.do_get('responder/type/{}'.format(data_type)).json(), Responder) | ||
|
||
def definitions(self) -> List[ResponderDefinition]: | ||
return self._wrap(self._api.do_get('responderdefinition').json(), ResponderDefinition) | ||
|
||
def enable(self, responder_name, config) -> Responder: | ||
url = 'organization/responder/{}'.format(responder_name) | ||
config['name'] = responder_name | ||
|
||
return self._wrap(self._api.do_post(url, config).json(), Responder) | ||
|
||
def update(self, worker_id, config) -> Responder: | ||
url = 'responder/{}'.format(worker_id) | ||
config.pop('name', None) | ||
|
||
return self._wrap(self._api.do_patch(url, config).json(), Responder) | ||
|
||
def disable(self, worker_id) -> bool: | ||
return self._api.do_delete('responder/{}'.format(worker_id)) | ||
|
||
def run_by_id(self, worker_id, data, **kwargs) -> Job: | ||
tlp = data.get('tlp', 2) | ||
data_type = data.get('dataType', None) | ||
|
||
post = { | ||
'dataType': data_type, | ||
'tlp': tlp | ||
} | ||
|
||
params = {} | ||
if 'force' in kwargs: | ||
params['force'] = kwargs.get('force', 1) | ||
|
||
# add additional details | ||
for key in ['message', 'parameters']: | ||
if key in data: | ||
post[key] = data.get(key, None) | ||
|
||
post['data'] = data.get('data') | ||
|
||
return self._wrap(self._api.do_post('responder/{}/run'.format(worker_id), post, params).json(), Job) | ||
|
||
def run_by_name(self, responder_name, observable, **kwargs) -> Job: | ||
responder = self.get_by_name(responder_name) | ||
|
||
return self.run_by_id(responder.id, observable, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from .model import Model | ||
|
||
|
||
class Responder(Model): | ||
|
||
def __init__(self, data): | ||
defaults = { | ||
'id': None, | ||
'name': None, | ||
'workerDefinitionId': None, | ||
'description': None, | ||
'version': None, | ||
'author': None, | ||
'url': None, | ||
'license': None, | ||
'dataTypeList': [], | ||
'configuration': {}, | ||
'rate': None, | ||
'rateUnit': None, | ||
'maxPap': None, | ||
'maxTlp': None | ||
} | ||
|
||
if data is None: | ||
data = dict(defaults) | ||
|
||
self.__dict__ = {k: v for k, v in data.items() if not k.startswith('_')} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from .model import Model | ||
|
||
|
||
class ResponderDefinition(Model): | ||
|
||
def __init__(self, data): | ||
defaults = { | ||
'id': None, | ||
'name': None, | ||
'description': None, | ||
'version': None, | ||
'author': None, | ||
'url': None, | ||
'license': None, | ||
'basicConfig': None, | ||
'dataTypeList': [], | ||
'configurationItems': [] | ||
} | ||
|
||
if data is None: | ||
data = dict(defaults) | ||
|
||
self.__dict__ = {k: v for k, v in data.items() if not k.startswith('_')} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters