コード例 #1
0
 def test_to_dict(self, generic_rule: RuleGeneric):
     data = {'permit': True, 'sourceAddress': {'kind': 'IPv4Network', 'value': '192.168.23.0/24'},
             'destinationAddress': {'kind': 'IPv4Network', 'value': '192.168.24.0/24'},
             'sourceService': {'kind': 'NetworkProtocol', 'value': 'eigrp'},
             'destinationService': {'kind': 'NetworkProtocol', 'value': 'eigrp'}, 'active': False,
             'remarks': ['EIGRP Test Rule'], 'ruleLogging': {'logStatus': 'Debugging', 'logInterval': 60},
             'position': 17, 'isAccessRule': True, 'objectId': 1234567}
     assert generic_rule.to_dict() == data
コード例 #2
0
ファイル: acl.py プロジェクト: falkowich/pyASA
    def append_rule(self, acl: str, rule: RuleGeneric):
        """
        Append rule to ACL.

        Uses position of rule object if position > 0, else appends to end of ACL.

        Args:
            acl: name of ACL to which rule is to be appended
            rule: rule object to append
        """
        if not isinstance(acl, str):
            raise ValueError(f"{type(acl)} is not a valid acl argument type")
        if not isinstance(rule, RuleGeneric):
            raise ValueError(f"{type(rule)} is not a valid rule argument type")
        response = self._caller.post(f"objects/extendedacls/{acl}/aces", rule.to_dict())
        if response.status_code == requests.codes.bad_request and "messages" in response.json() and "code" in \
                response.json()["messages"] and response.json()["messages"]["code"] == "DUPLICATE":
            raise ValueError(
                f"Rule creation denied because rule is duplicate of rule object {response.json()['messages']['details']}")
        elif response.status_code != requests.codes.created:
            raise RuntimeError(
                f"Appending rule to ACL {acl} failed with HTTP {response.status_code}: {response.json()}")