diff --git a/opt/ahenk/base/plugin/Plugin.py b/opt/ahenk/base/plugin/Plugin.py index b0e121a..2a22a1e 100644 --- a/opt/ahenk/base/plugin/Plugin.py +++ b/opt/ahenk/base/plugin/Plugin.py @@ -23,14 +23,12 @@ class Context(object): def empty_data(self): self.data = {} - def create_response(self, code=None, message=None, data=None, content_type=None): + def create_response(self, code, message=None, data=None, content_type=None): self.data['responseCode'] = code self.data['responseMessage'] = message self.data['responseData'] = data self.data['contentType'] = content_type - # TODO send file,... - class Plugin(threading.Thread): """ @@ -66,13 +64,21 @@ class Plugin(threading.Thread): if obj_name == "TASK": self.logger.debug('[Plugin] Executing task') command = Scope.getInstance().getPluginManager().findCommand(self.getName(), item_obj.get_command_cls_id().lower()) + self.context.put('task_id', item_obj.get_command_cls_id().lower()) + + task_data = item_obj.get_parameter_map() self.logger.debug('[Plugin] Handling task') - command.handle_task(item_obj, self.context) + command.handle_task(task_data, self.context) + self.logger.debug('[Plugin] Creating response') - response = Response(type=MessageType.TASK_STATUS.value, id=item_obj.get_id(), code=self.context.get('responseCode'), message=self.context.get('responseMessage'), data=self.context.get('responseData'), content_type=self.context.get('contentType')) - # self.response_queue.put(self.messaging.response_msg(response)) #TODO DEBUG - self.logger.debug('[Plugin] Sending response') - Scope.getInstance().getMessager().send_direct_message(self.messaging.task_status_msg(response)) # TODO REMOVE + + if self.context.get('responseCode') is not None: + response = Response(type=MessageType.TASK_STATUS.value, id=item_obj.get_id(), code=self.context.get('responseCode'), message=self.context.get('responseMessage'), data=self.context.get('responseData'), content_type=self.context.get('contentType')) + # self.response_queue.put(self.messaging.response_msg(response)) #TODO DEBUG + self.logger.debug('[Plugin] Sending response') + Scope.getInstance().getMessager().send_direct_message(self.messaging.task_status_msg(response)) # TODO REMOVE + else: + self.logger.error('[Plugin] There is no Response. Plugin must create response after run a task!') elif obj_name == "PROFILE": self.logger.debug('[Plugin] Executing profile') @@ -80,16 +86,23 @@ class Plugin(threading.Thread): policy_module = Scope.getInstance().getPluginManager().findPolicyModule(item_obj.get_plugin().get_name()) self.context.put('username', item_obj.get_username()) - self.logger.debug('[Plugin] Handling profile') - policy_module.handle_policy(profile_data, self.context) execution_id = self.get_execution_id(item_obj.get_id()) policy_ver = self.get_policy_version(item_obj.get_id()) - self.logger.debug('[Plugin] Creating response') - response = Response(type=MessageType.POLICY_STATUS.value, id=item_obj.get_id(), code=self.context.get('responseCode'), message=self.context.get('responseMessage'), data=self.context.get('responseData'), content_type=self.context.get('contentType'), execution_id=execution_id, policy_version=policy_ver) - # self.response_queue.put(self.messaging.response_msg(response)) #TODO DEBUG - self.logger.debug('[Plugin] Sending response') - Scope.getInstance().getMessager().send_direct_message(self.messaging.policy_status_msg(response)) # TODO REMOVE + self.context.put('policy_version', policy_ver) + self.context.put('execution_id', execution_id) + + self.logger.debug('[Plugin] Handling profile') + policy_module.handle_policy(profile_data, self.context) + + if self.context.get('responseCode') is not None: + self.logger.debug('[Plugin] Creating response') + response = Response(type=MessageType.POLICY_STATUS.value, id=item_obj.get_id(), code=self.context.get('responseCode'), message=self.context.get('responseMessage'), data=self.context.get('responseData'), content_type=self.context.get('contentType'), execution_id=execution_id, policy_version=policy_ver) + # self.response_queue.put(self.messaging.response_msg(response)) #TODO DEBUG + self.logger.debug('[Plugin] Sending response') + Scope.getInstance().getMessager().send_direct_message(self.messaging.policy_status_msg(response)) # TODO REMOVE + else: + self.logger.error('[Plugin] There is no Response. Plugin must create response after run a policy!') elif obj_name == "KILL_SIGNAL": self.keep_run = False