Ejemplo n.º 1
0
 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_condition_api(self.app_name, self.action_name)
             get_condition(self.app_name, run)
         except UnknownApp:
             errors.append('Unknown app {}'.format(self.app_name))
         except UnknownCondition:
             errors.append('Unknown condition {}'.format(self.action_name))
         self.errors = errors
Ejemplo n.º 2
0
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)))
Ejemplo n.º 3
0
 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_condition_api(
             self.app_name, self.action_name)
         self._condition_executable = get_condition(self.app_name,
                                                    self._run)
Ejemplo n.º 4
0
 def __init__(self,
              app_name,
              action_name,
              arguments=None,
              transforms=None,
              uid=None):
     """Initializes a new Condition object.
     
     Args:
         app_name (str): The name of the app which contains this condition
         action_name (str): The action name for the Condition. Defaults to an empty string.
         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.
         transforms(list[Transform], optional): A list of Transform objects for the Condition object.
             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_condition_api(
         self.app_name, self.action_name)
     self._condition_executable = get_condition(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_condition_parameters(tmp_api, arguments, self.action_name)
     self.arguments = arguments
     self.transforms = transforms if transforms is not None else []
Ejemplo n.º 5
0
 def validate(self):
     """Validates the object"""
     errors = []
     try:
         self._data_param_name, run, self._api = get_condition_api(self.app_name, self.action_name)
         self._condition_executable = get_condition(self.app_name, run)
         tmp_api = split_api_params(self._api, self._data_param_name)
         validate_condition_parameters(tmp_api, self.arguments, self.action_name)
     except UnknownApp:
         errors.append('Unknown app {}'.format(self.app_name))
     except UnknownCondition:
         errors.append('Unknown condition {}'.format(self.action_name))
     except InvalidArgument as e:
         errors.extend(e.errors)
     self.errors = errors
Ejemplo n.º 6
0
 def validate(self):
     errors = {}
     try:
         self._data_param_name, self._run, self._api = get_condition_api(
             self.app_name, self.action_name)
         self._condition_executable = get_condition(self.app_name,
                                                    self._run)
         tmp_api = split_api_params(self._api, self._data_param_name)
         validate_condition_parameters(tmp_api, self.arguments,
                                       self.action_name)
     except UnknownApp:
         errors['executable'] = 'Unknown app {}'.format(self.app_name)
     except UnknownCondition:
         errors['executable'] = 'Unknown condition {}'.format(
             self.action_name)
     except InvalidArgument as e:
         errors['arguments'] = e.errors
     if errors:
         raise InvalidExecutionElement(self.id,
                                       self.action_name,
                                       'Invalid condition {}'.format(
                                           self.id or self.action_name),
                                       errors=[errors])
Ejemplo n.º 7
0
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)))