forked from p15670423/monkey
Added a decorator in which the "timer start" for the timeout can be implemented
This commit is contained in:
parent
1a5ebf8dbd
commit
99bc61f9d9
|
@ -51,7 +51,6 @@ class MonkeyDrops(object):
|
|||
LOG.debug("Dropper is running with config:\n%s", pprint.pformat(self._config))
|
||||
|
||||
def start(self):
|
||||
|
||||
if self._config['destination_path'] is None:
|
||||
LOG.error("No destination path specified")
|
||||
return False
|
||||
|
|
|
@ -98,6 +98,7 @@ def main():
|
|||
except OSError:
|
||||
pass
|
||||
LOG_CONFIG['handlers']['file']['filename'] = log_path
|
||||
# noinspection PyUnresolvedReferences
|
||||
LOG_CONFIG['root']['handlers'].append('file')
|
||||
else:
|
||||
del LOG_CONFIG['handlers']['file']
|
||||
|
|
|
@ -2,11 +2,12 @@ import json
|
|||
from datetime import datetime
|
||||
|
||||
import dateutil.parser
|
||||
from flask import request
|
||||
import flask_restful
|
||||
from flask import request
|
||||
|
||||
from monkey_island.cc.database import mongo
|
||||
from monkey_island.cc.services.config import ConfigService
|
||||
from monkey_island.cc.services.monkey_timeout import start_timer_decorator
|
||||
from monkey_island.cc.services.node import NodeService
|
||||
|
||||
__author__ = 'Barak'
|
||||
|
@ -17,6 +18,7 @@ __author__ = 'Barak'
|
|||
class Monkey(flask_restful.Resource):
|
||||
|
||||
# Used by monkey. can't secure.
|
||||
@start_timer_decorator
|
||||
def get(self, guid=None, **kw):
|
||||
NodeService.update_dead_monkeys() # refresh monkeys status
|
||||
if not guid:
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import functools
|
||||
import pprint
|
||||
|
||||
|
||||
def start_timer_decorator(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper_decorator(*args, **kwargs):
|
||||
print("ib4get - start the timer, folks. \nargs:")
|
||||
pprint.pprint(args)
|
||||
print("kwargs: ")
|
||||
pprint.pprint(kwargs)
|
||||
value = func(*args, **kwargs)
|
||||
print("after party woohoo")
|
||||
|
||||
try:
|
||||
print("Starting timer on " + kwargs['guid'])
|
||||
except KeyError as e:
|
||||
print("NO GUID AVAILABLE")
|
||||
|
||||
return value
|
||||
|
||||
return wrapper_decorator
|
Loading…
Reference in New Issue