def report(path, tool, node): if os.path.isfile('{}/insights.json'.format(path)): with open('{}/insights.json'.format(path), 'r') as input: insights = json.load(input) print(insights) logging.info(insights) etcd_client.write('insight/{}/{}'.format(tool, node), json.dumps(insights))
def validate(details, audit_id): #make temp folder IF not exists audit_dir = config['WORKING_ENVIRONMENT']['auditdir'] + '/' + audit_id if not os.path.isdir(audit_dir): os.mkdir(audit_dir) #get csv entries for this audit files = etcd_client.directory('csv/{}'.format(audit_id)) csvs = {} # retrieve encoded csvs for result in files.children: csvs[result.key] = result.value # decode csvs decode(csvs, audit_id) #perform validation winner = audit(audit_dir) #announce leader logging.info(audit_id) logging.info(details['tool']) logging.info(details['timestamp']) logging.info(str(winner)) etcd_client.write( "winners/{}".format(audit_id), '{{"tool":"{}",\ "timestamp":"{}",\ "winner":"{}"}}'.format(details['tool'], details['timestamp'], str(winner))) #delete audit, csvs and temp files etcd_client.delete_recursive("/csv/{}".format(audit_id)) etcd_client.delete_recursive("/audit/{}".format(audit_id))
def detect(path, name): result = diff(path, name) if result['spike']: etcd_client.write('notifications/' + str(datetime.datetime.now()), name) logging.debug("Notification entry writen to cluster.") logging.debug(etcd_client.list('notifications')) return result
async def register(request): data = await request.json() etcd_client.write( "tools/{}".format(data['name']), '{{"author":"{}",\ "image":"{}",\ "data_repo":"{}",\ "code_repo":"{}",\ "artefact":"{}"}}'.format(data['author'], data['image'], data['data_repo'], data['code_repo'], data['artefact'])) return web.json_response(etcd_client.get("tools/{}".format(data['name'])))
def submit(tool, audit_id, issuer): # find most recent csv path = config['DATA_REPOS'][tool] filenames = glob.glob("{}/*.csv".format(path)) filenames.sort() # filenames[-1] is the latest file # if they are named appropriately with open(filenames[-1], 'rb') as f: encoded = base64.b64encode(f.read()) # write entry with encoded payload etcd_client.write( "csv/{}/{}".format(audit_id, issuer), '{{"tool":"{}",\ "timestamp":"{}",\ "payload":"{}"}}'.format(tool, datetime.now(), encoded)) return filenames[-1]
def create_audit(tool): # Creation of audit entry issuer = config['WORKING_ENVIRONMENT']['user'] timestamp = datetime.now() audit_id = timestamp.microsecond write( "audit/{}".format(audit_id), '{{"issuer":"{}",\ "tool":"{}",\ "timestamp":"{}"}}'.format(issuer, tool, timestamp)) # Send file if exists if config.has_option('DATA_REPOS', tool): filename = audit.submit(tool, audit_id, issuer) return "Created audit {} and submitted file {}".format( audit_id, filename) else: return "Created audit {}. No local file to submit.".format(audit_id)
async def register(request): data = await request.json() etcd_client.write("data/{}".format(data['name']), data['url']) return web.json_response(etcd_client.get("data/{}".format(data['name'])))
async def write(request): data = await request.json() etcd_client.write('raw/' + data['key'], data['value'], ephemeral=True) return web.json_response(etcd_client.get('raw/' + data['key']))