Example #1
0
    def __load(self, rules_data: str) -> None:
        """
        loads a yaml str, serializes and normalized the rule data. Then assigns the rule data to properties.
        :param config_file: A :string: loaded from a yaml file.
        """
        if not isinstance(rules_data, str):
            raise TypeError('rules_data must be a str.')

        try:
            data = SafeLoader(rules_data).get_data()

            if data is None:
                raise AttributeError('The rules must have data in it.')

            data = normalize_keys(data, snake_case=False)
            for key, value in data.items():
                variable_name = '_{0}'.format(key)
                if hasattr(self, variable_name):
                    setattr(self, variable_name, value)
                else:
                    raise AttributeError(
                        '{0} isn\'t a valid rule attribute.'.format(key))

        except YAMLError as e:
            if hasattr(e, 'problem_mark'):
                raise SyntaxError(
                    "There is a syntax error in the rules line: {0} column: {1}"
                    .format(e.problem_mark.line, e.problem_mark.column))
            else:
                raise SyntaxError("There is a syntax error in the rules.")
Example #2
0
    def __load_checksums(self):
        checksum_data = self.kv.get('{0}/containers/checksums'.format(
            self.name))

        try:
            if checksum_data:
                data = normalize_keys(SafeLoader(checksum_data).get_data(),
                                      snake_case=False)
            else:
                data = {}

            return data

        except YAMLError as e:
            if hasattr(e, 'problem_mark'):
                raise SyntaxError(
                    "There is a syntax error in the rules line: {0} column: {1}"
                    .format(e.problem_mark.line, e.problem_mark.column))
            else:
                raise SyntaxError("There is a syntax error in the rules.")