11#!/usr/bin/env python
22# encoding: utf-8
33
4- import os
5- import sys
64import codecs
75import json
6+ import os
87import select
8+ import sys
99
10+ DEFAULT_SECRET_PHRASES = ("key" , "password" , "secret" )
1011
1112class Worker (object ):
1213 READ_TIMEOUT = 3 # seconds
1314
14- def __init__ (self , job_directory ):
15+ def __init__ (self , job_directory , secret_phrases ):
1516 if job_directory is None :
1617 if len (sys .argv ) > 1 :
1718 job_directory = sys .argv [1 ]
1819 else :
1920 job_directory = '/job'
2021 self .job_directory = job_directory
22+ if secret_phrases is None :
23+ self .secret_phrases = DEFAULT_SECRET_PHRASES
24+ else :
25+ self .secret_phrases = secret_phrases
2126 # Load input
2227 self ._input = {}
2328 if os .path .isfile ('%s/input/input.json' % self .job_directory ):
@@ -127,6 +132,26 @@ def get_data(self):
127132 :return: Data (observable value) given through Cortex"""
128133 return self .get_param ('data' , None , 'Missing data field' )
129134
135+ @staticmethod
136+ def build_operation (op_type , ** parameters ):
137+ """
138+ :param op_type: an operation type as a string
139+ :param parameters: a dict including the operation's params
140+ :return: dict
141+ """
142+ operation = {
143+ 'type' : op_type
144+ }
145+ operation .update (parameters )
146+
147+ return operation
148+
149+ def operations (self , raw ):
150+ """Returns the list of operations to be executed after the job completes
151+
152+ :returns: by default return an empty array"""
153+ return []
154+
130155 def get_param (self , name , default = None , message = None ):
131156 """Just a wrapper for Analyzer.__get_param.
132157 :param name: Name of the parameter to get. JSON-like syntax, e.g. `config.username`
@@ -144,13 +169,13 @@ def error(self, message, ensure_ascii=False):
144169 # Get analyzer input
145170 analyzer_input = self ._input
146171
147- # Define sensitive key values
148- secrets = ['password' , 'key' , 'secret' ]
149-
150172 # Loop over all the sensitive config names and clean them
151- for config_key , v in analyzer_input .get ('config' , {}).items ():
152- if any (secret in config_key .lower () for secret in secrets ):
153- analyzer_input .get ('config' , {})[config_key ] = 'REMOVED'
173+ for config_key in analyzer_input .get ('config' , {}).keys ():
174+ if any (
175+ secret_phrase in config_key .lower ()
176+ for secret_phrase in self .secret_phrases
177+ ):
178+ analyzer_input ['config' ][config_key ] = 'REMOVED'
154179
155180 self .__write_output ({'success' : False ,
156181 'input' : analyzer_input ,
0 commit comments