def init_on_load(self): """Loads all necessary fields upon Condition being loaded from database""" if not self.errors: errors = [] try: self._data_param_name, run, self._api = get_transform_api(self.app_name, self.action_name) get_transform(self.app_name, run) except UnknownApp: errors.append('Unknown app {}'.format(self.app_name)) except UnknownTransform: errors.append('Unknown transform {}'.format(self.action_name)) self.errors = errors
def validate(self): """Validates the object""" errors = [] try: self._data_param_name, run, self._api = get_transform_api(self.app_name, self.action_name) get_transform(self.app_name, run) tmp_api = split_api_params(self._api, self._data_param_name) validate_transform_parameters(tmp_api, self.arguments, self.action_name) except UnknownApp: errors.append('Unknown app {}'.format(self.app_name)) except UnknownTransform: errors.append('Unknown transform {}'.format(self.action_name)) except InvalidArgument as e: errors.extend(e.errors) self.errors = errors
def validate_condition_transform_params(spec, app_name, action_type, defined_actions, dereferencer): from walkoff.appgateway import get_transform from walkoff.appgateway import get_condition seen = set() for action_name, action in spec.items(): action = dereferencer(action) action_params = dereferencer(action.get('parameters', [])) if action['run'] not in defined_actions: raise InvalidApi('{0} action {1} has a "run" param {2} ' 'which is not defined'.format( action_type, action_name, action['run'])) data_in_param_name = action['data_in'] validate_data_in_param( action_params, data_in_param_name, '{0} action {1}'.format(action_type, action_name)) if action_type == 'Condition': function_ = get_condition(app_name, action['run']) else: function_ = get_transform(app_name, action['run']) validate_action_params(action_params, dereferencer, action_type, action_name, function_) seen.add(action['run']) if seen != set(defined_actions): logger.warning( 'Global {0}s have defined the following actions which do not have a corresponding API: ' '{1}'.format(action_type.lower(), (set(defined_actions) - seen)))
def __init__(self, app_name, action_name, id=None, arguments=None): """Initializes a new Transform object. A Transform is used to transform input into a workflow. Args: app_name (str): The app name associated with this transform action_name (str): The action name for the transform. id (str|UUID, optional): Optional UUID to pass into the Transform. Must be UUID object or valid UUID string. Defaults to None. arguments (list[Argument], optional): Dictionary of Argument keys to Argument values. This dictionary will be converted to a dictionary of str:Argument. Defaults to None. """ ExecutionElement.__init__(self, id) self.app_name = app_name self.action_name = action_name self._data_param_name = None self._run = None self._api = None self.arguments = [] if arguments: self.arguments = arguments self.validate() self._transform_executable = get_transform(self.app_name, self._run)
def __init__(self, app_name, action_name, arguments=None, uid=None): """Initializes a new Transform object. A Transform is used to transform input into a workflow. Args: app_name (str): The app name associated with this transform action_name (str): The action name for the transform. arguments (list[Argument], optional): Dictionary of Argument keys to Argument values. This dictionary will be converted to a dictionary of str:Argument. Defaults to None. uid (str, optional): A universally unique identifier for this object. Created from uuid.uuid4() in Python """ ExecutionElement.__init__(self, uid) self.app_name = app_name self.action_name = action_name self._data_param_name, self._run, self._api = get_transform_api(self.app_name, self.action_name) self._transform_executable = get_transform(self.app_name, self._run) arguments = {arg.name: arg for arg in arguments} if arguments is not None else {} tmp_api = split_api_params(self._api, self._data_param_name) validate_transform_parameters(tmp_api, arguments, self.action_name) self.arguments = arguments
def validate_condition_transform_params(spec, app_name, action_type, defined_actions, dereferencer): from walkoff.appgateway import get_transform from walkoff.appgateway import get_condition seen = set() for action_name, action in spec.items(): action = dereferencer(action) action_params = dereferencer(action.get('parameters', [])) if action['run'] not in defined_actions: raise InvalidApi('{0} action {1} has a "run" param {2} ' 'which is not defined'.format(action_type, action_name, action['run'])) data_in_param_name = action['data_in'] validate_data_in_param(action_params, data_in_param_name, '{0} action {1}'.format(action_type, action_name)) if action_type == 'Condition': function_ = get_condition(app_name, action['run']) else: function_ = get_transform(app_name, action['run']) validate_action_params(action_params, dereferencer, action_type, action_name, function_) seen.add(action['run']) if seen != set(defined_actions): logger.warning('Global {0}s have defined the following actions which do not have a corresponding API: ' '{1}'.format(action_type.lower(), (set(defined_actions) - seen)))
def init_on_load(self): """Loads all necessary fields upon Condition being loaded from database""" if not self.errors: self._data_param_name, self._run, self._api = get_transform_api(self.app_name, self.action_name) self._transform_executable = get_transform(self.app_name, self._run)