-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#316 Refactor cortexutils to add a Responder class
- Loading branch information
Showing
4 changed files
with
275 additions
and
139 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
import json | ||
from cortexutils.worker import Worker | ||
|
||
|
||
class Responder(Worker): | ||
|
||
def __init__(self): | ||
Worker.__init__(self) | ||
|
||
# Not breaking compatibility | ||
self.artifact = self._input | ||
|
||
def get_data(self): | ||
"""Wrapper for getting data from input dict. | ||
:return: Data (observable value) given through Cortex""" | ||
return self.get_param('data', None, 'Missing data field') | ||
|
||
def build_operation(self, op_type, parameters={}): | ||
""" | ||
:param op_type: an operation type as a string | ||
:param parameters: a dict including the operation's params | ||
:return: dict | ||
""" | ||
operation = { | ||
'type': op_type | ||
} | ||
operation.update(parameters) | ||
|
||
return operation | ||
|
||
def operations(self, raw): | ||
"""Returns the list of operations to be executed after the job completes | ||
:returns: by default return an empty array""" | ||
return [] | ||
|
||
def report(self, full_report, ensure_ascii=False): | ||
"""Returns a json dict via stdout. | ||
:param full_report: Responsder results as dict. | ||
:param ensure_ascii: Force ascii output. Default: False""" | ||
|
||
report = { | ||
'success': True, | ||
'full': full_report, | ||
'operations': | ||
} | ||
json.dump(report, self.fpoutput, ensure_ascii=ensure_ascii) | ||
|
||
def run(self): | ||
"""Overwritten by responders""" | ||
pass |
Oops, something went wrong.