Exemplo n.º 1
0
    def load_rules(self):
        """Load the rules from file.

        :return: A list of rules to create.
        """
        rules = []
        try:
            self._logging.info("Loading config from file: %s",
                               self._rule_file)
            with open(self._rule_file) as buf_in:
                rule_yaml = yaml.load(buf_in)
        except:
            self._logging.error("Error reading from file %s: %s",
                                self._rule_file, sys.exc_info()[1])
            sys.exit("Error reading from file {0}: {1}".format(
                self._rule_file, sys.exc_info()[0]))
        # Perform a configuration file key check
        if not self._check_conf_keys(rule_yaml, self._ACL_RULE_CONF_KEYS,
                                     self._rule_file):
            self._logging.critical("Please correct configuration file: "
                                   "%s", self._rule_file)
            sys.exit("Please correct configuration file: {0}".format(
                self._rule_file))
        # Copy declared ACL rules into a list, if there are any
        if rule_yaml["acl_rules"] is not None:
            for rule in rule_yaml["acl_rules"]:
                if rule is not None:
                    if not data_templates.check_rule_creation_data(rule):
                        self._logging.warning("%s is not formatted "
                                              "correctly.", rule)
                        continue
                    self._logging.debug("Reading ACL rule: %s", rule)
                    rules.append(rule)
        return rules
Exemplo n.º 2
0
    def post_acl(self, req, **kwargs):
        """Endpoint for creating an ACL rule.

        :return: A response containing the result of the operation.
        """
        try:
            rule_req = json.loads(req.body)
            if not data_templates.check_rule_creation_data(rule_req[
                                                               "rule"]):
                raise KeyError
        except (ValueError, KeyError):
            error = self._MSG_ERROR.copy()
            error["error"] = "Invalid rule creation JSON passed."
            return Response(status=400, body=json.dumps(error))
        return_status = self._api.acl_create_rule(rule_req["rule"])
        return self._api_response(return_status)
Exemplo n.º 3
0
    def load_rules(self):
        """Load the rules from file.

        :return: A list of rules to create.
        """
        rules = []
        try:
            self._logging.info("Loading config from file: %s", self._rule_file)
            with open(self._rule_file) as buf_in:
                rule_yaml = yaml.load(buf_in)
        except:
            self._logging.error("Error reading from file %s: %s",
                                self._rule_file,
                                sys.exc_info()[1])
            sys.exit("Error reading from file {0}: {1}".format(
                self._rule_file,
                sys.exc_info()[0]))
        # Perform a configuration file key check
        if not self._check_conf_keys(rule_yaml, self._ACL_RULE_CONF_KEYS,
                                     self._rule_file):
            self._logging.critical("Please correct configuration file: "
                                   "%s", self._rule_file)
            sys.exit("Please correct configuration file: {0}".format(
                self._rule_file))
        # Copy declared ACL rules into a list, if there are any
        if rule_yaml["acl_rules"] is not None:
            for rule in rule_yaml["acl_rules"]:
                if rule is not None:
                    if not data_templates.check_rule_creation_data(rule):
                        self._logging.warning(
                            "%s is not formatted "
                            "correctly.", rule)
                        continue
                    self._logging.debug("Reading ACL rule: %s", rule)
                    rules.append(rule)
        return rules