PyPANRestV2 2.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pypanrestv2/ApplicationHelper.py +220 -0
- pypanrestv2/Base.py +1772 -0
- pypanrestv2/Device.py +21 -0
- pypanrestv2/Exceptions.py +11 -0
- pypanrestv2/Network.py +1722 -0
- pypanrestv2/Objects.py +1428 -0
- pypanrestv2/Panorama.py +426 -0
- pypanrestv2/Policies.py +755 -0
- pypanrestv2/XDR.py +299 -0
- pypanrestv2/__init__.py +4 -0
- pypanrestv2-2.1.0.dist-info/METADATA +209 -0
- pypanrestv2-2.1.0.dist-info/RECORD +13 -0
- pypanrestv2-2.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
class Operator:
|
|
2
|
+
def __init__(self, context):
|
|
3
|
+
self.context = context
|
|
4
|
+
|
|
5
|
+
@property
|
|
6
|
+
def context(self) -> str:
|
|
7
|
+
return self._context
|
|
8
|
+
|
|
9
|
+
@context.setter
|
|
10
|
+
def context(self, value):
|
|
11
|
+
if not isinstance(value, str):
|
|
12
|
+
raise ValueError("Context must be a string.")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class PatternMatchOperator(Operator):
|
|
16
|
+
def __init__(self, context, pattern, qualifier):
|
|
17
|
+
super().__init__(context)
|
|
18
|
+
self.pattern = pattern
|
|
19
|
+
self.qualifier = self.initialize_qualifier(qualifier)
|
|
20
|
+
|
|
21
|
+
def initialize_qualifier(self, qualifier):
|
|
22
|
+
if 'entry' in qualifier:
|
|
23
|
+
return [{entry['@name']: entry['value']} for entry in qualifier['entry']]
|
|
24
|
+
return []
|
|
25
|
+
|
|
26
|
+
def to_dict(self):
|
|
27
|
+
return {
|
|
28
|
+
'type': 'pattern-match',
|
|
29
|
+
'context': self.context,
|
|
30
|
+
'pattern': self.pattern,
|
|
31
|
+
'qualifier': {'entry': self.qualifier},
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class GreaterThanOperator(Operator):
|
|
36
|
+
def __init__(self, context, value, qualifier):
|
|
37
|
+
super().__init__(context)
|
|
38
|
+
self.value = value
|
|
39
|
+
self.validate_value(value)
|
|
40
|
+
self.qualifier = self.initialize_qualifier(qualifier)
|
|
41
|
+
|
|
42
|
+
def validate_value(self, value):
|
|
43
|
+
if not isinstance(value, int) or not (0 <= value <= 4294967295):
|
|
44
|
+
raise ValueError("Value must be an integer between 0 and 4294967295.")
|
|
45
|
+
|
|
46
|
+
def initialize_qualifier(self, qualifier):
|
|
47
|
+
if 'entry' in qualifier:
|
|
48
|
+
return [{entry['@name']: entry['value']} for entry in qualifier['entry']]
|
|
49
|
+
return []
|
|
50
|
+
|
|
51
|
+
def to_dict(self):
|
|
52
|
+
return {
|
|
53
|
+
'type': 'greater-than',
|
|
54
|
+
'context': self.context,
|
|
55
|
+
'value': self.value,
|
|
56
|
+
'qualifier': {'entry': self.qualifier},
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class LessThanOperator(Operator):
|
|
61
|
+
def __init__(self, context, value, qualifier):
|
|
62
|
+
super().__init__(context)
|
|
63
|
+
self.value = value
|
|
64
|
+
self.validate_value(value)
|
|
65
|
+
self.qualifier = self.initialize_qualifier(qualifier)
|
|
66
|
+
|
|
67
|
+
def validate_value(self, value):
|
|
68
|
+
if not isinstance(value, int) or not (0 <= value <= 4294967295):
|
|
69
|
+
raise ValueError("Value must be an integer between 0 and 4294967295.")
|
|
70
|
+
|
|
71
|
+
def initialize_qualifier(self, qualifier):
|
|
72
|
+
if 'entry' in qualifier:
|
|
73
|
+
return [{entry['@name']: entry['value']} for entry in qualifier['entry']]
|
|
74
|
+
return []
|
|
75
|
+
|
|
76
|
+
def to_dict(self):
|
|
77
|
+
return {
|
|
78
|
+
'type': 'less-than',
|
|
79
|
+
'context': self.context,
|
|
80
|
+
'value': self.value,
|
|
81
|
+
'qualifier': {'entry': self.qualifier},
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class EqualToOperator(Operator):
|
|
86
|
+
def __init__(self, context, position, mask, value):
|
|
87
|
+
super().__init__(context)
|
|
88
|
+
self.position = position
|
|
89
|
+
self.mask = mask
|
|
90
|
+
self.value = value
|
|
91
|
+
self.validate_position(position)
|
|
92
|
+
self.validate_mask(mask)
|
|
93
|
+
self.validate_value(value)
|
|
94
|
+
|
|
95
|
+
def validate_position(self, position):
|
|
96
|
+
if not isinstance(position, str) or len(position) > 127:
|
|
97
|
+
raise ValueError("Position must be a string up to 127 characters long.")
|
|
98
|
+
|
|
99
|
+
def validate_mask(self, mask):
|
|
100
|
+
if not isinstance(mask, str) or not re.match(r'^0[xX][0-9A-Fa-f]{8}$', mask):
|
|
101
|
+
raise ValueError("Mask must be a 4-byte hex value.")
|
|
102
|
+
|
|
103
|
+
def validate_value(self, value):
|
|
104
|
+
if not isinstance(value, str) or len(value) > 10:
|
|
105
|
+
raise ValueError("Value must be a string up to 10 characters long.")
|
|
106
|
+
|
|
107
|
+
def to_dict(self):
|
|
108
|
+
return {
|
|
109
|
+
'type': 'equal-to',
|
|
110
|
+
'context': self.context,
|
|
111
|
+
'position': self.position,
|
|
112
|
+
'mask': self.mask,
|
|
113
|
+
'value': self.value,
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
class OrConditionEntry:
|
|
117
|
+
def __init__(self, name, operator_data):
|
|
118
|
+
self.validate_name(name)
|
|
119
|
+
self.name = name
|
|
120
|
+
self.operator = self.initialize_operator(operator_data)
|
|
121
|
+
|
|
122
|
+
def validate_name(self, name):
|
|
123
|
+
if not isinstance(name, str) or len(name) > 31:
|
|
124
|
+
raise ValueError("Invalid name in or-condition entry.")
|
|
125
|
+
|
|
126
|
+
def initialize_operator(self, operator_data):
|
|
127
|
+
if not isinstance(operator_data, dict):
|
|
128
|
+
raise ValueError("Operator data must be a dictionary.")
|
|
129
|
+
|
|
130
|
+
operator_type = operator_data.get('type')
|
|
131
|
+
if operator_type == 'pattern-match':
|
|
132
|
+
return PatternMatchOperator(context=operator_data.get('context'),
|
|
133
|
+
pattern=operator_data.get('pattern'),
|
|
134
|
+
qualifier=operator_data.get('qualifier'))
|
|
135
|
+
elif operator_type == 'greater-than':
|
|
136
|
+
return GreaterThanOperator(context=operator_data.get('context'),
|
|
137
|
+
value=operator_data.get('value'),
|
|
138
|
+
qualifier=operator_data.get('qualifier'))
|
|
139
|
+
elif operator_type == 'less-than':
|
|
140
|
+
return GreaterThanOperator(context=operator_data.get('context'),
|
|
141
|
+
value=operator_data.get('value'),
|
|
142
|
+
qualifier=operator_data.get('qualifier'))
|
|
143
|
+
elif operator_type == 'equal-to':
|
|
144
|
+
return EqualToOperator(context=operator_data.get('context'),
|
|
145
|
+
position=operator_data.get('position'),
|
|
146
|
+
mask=operator_data.get('mask'),
|
|
147
|
+
value=operator_data.get('value'))
|
|
148
|
+
else:
|
|
149
|
+
raise ValueError(f"Unsupported operator type: {operator_type}")
|
|
150
|
+
|
|
151
|
+
def to_dict(self):
|
|
152
|
+
# Convert the OrConditionEntry instance to a dictionary format
|
|
153
|
+
or_condition_dict = {
|
|
154
|
+
'name': self.name,
|
|
155
|
+
# Include operator serialization here once operator.to_dict() is defined
|
|
156
|
+
'operator': self.operator.to_dict() if self.operator else None,
|
|
157
|
+
}
|
|
158
|
+
return or_condition_dict
|
|
159
|
+
|
|
160
|
+
class AndConditionEntry:
|
|
161
|
+
def __init__(self, name, or_condition=None):
|
|
162
|
+
self.validate_name(name)
|
|
163
|
+
self.name = name
|
|
164
|
+
self.or_condition = self.initialize_or_condition(or_condition)
|
|
165
|
+
|
|
166
|
+
def validate_name(self, name):
|
|
167
|
+
if not isinstance(name, str) or len(name) > 31:
|
|
168
|
+
raise ValueError("Invalid name in and-condition entry.")
|
|
169
|
+
# Ensures the name consists only of allowed characters
|
|
170
|
+
if not all(char.isalnum() or char in "._-" for char in name):
|
|
171
|
+
raise ValueError("Name in and-condition entry contains invalid characters.")
|
|
172
|
+
|
|
173
|
+
def initialize_or_condition(self, or_condition):
|
|
174
|
+
if or_condition and 'entry' in or_condition:
|
|
175
|
+
return [OrConditionEntry(**entry) for entry in or_condition['entry']]
|
|
176
|
+
return []
|
|
177
|
+
|
|
178
|
+
def to_dict(self):
|
|
179
|
+
# Convert the AndConditionEntry instance to a dictionary format
|
|
180
|
+
and_condition_dict = {
|
|
181
|
+
'name': self.name,
|
|
182
|
+
# Serialize or-condition if it's present
|
|
183
|
+
'or-condition': {'entry': [condition.to_dict() for condition in self.or_condition] if self.or_condition else None},
|
|
184
|
+
}
|
|
185
|
+
return and_condition_dict
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
class SignatureEntry:
|
|
189
|
+
def __init__(self, name, comment="", scope="protocol-data-unit", order_free="no", and_condition=None):
|
|
190
|
+
self.validate_name(name)
|
|
191
|
+
self.name = name
|
|
192
|
+
self.comment = comment
|
|
193
|
+
self.scope = self.validate_scope(scope)
|
|
194
|
+
self.order_free = self.validate_order_free(order_free)
|
|
195
|
+
self.and_condition = self.initialize_and_condition(and_condition)
|
|
196
|
+
|
|
197
|
+
def to_dict(self):
|
|
198
|
+
# Convert the SignatureEntry instance to a dictionary format suitable for inclusion in self.entry
|
|
199
|
+
signature_dict = {
|
|
200
|
+
'name': self.name,
|
|
201
|
+
'comment': self.comment,
|
|
202
|
+
'scope': self.scope,
|
|
203
|
+
'order-free': self.order_free,
|
|
204
|
+
'and-condition': {'entry': [condition.to_dict() for condition in self.and_condition] if self.and_condition else None},
|
|
205
|
+
}
|
|
206
|
+
return signature_dict
|
|
207
|
+
|
|
208
|
+
def validate_name(self, name):
|
|
209
|
+
if not isinstance(name, str) or len(name) > 31 or not all(char.isalnum() or char in "._-" for char in name):
|
|
210
|
+
raise ValueError("Invalid name for signature entry.")
|
|
211
|
+
|
|
212
|
+
def validate_scope(self, scope):
|
|
213
|
+
if scope not in ["protocol-data-unit", "session"]:
|
|
214
|
+
raise ValueError("Invalid scope value.")
|
|
215
|
+
return scope
|
|
216
|
+
|
|
217
|
+
def validate_order_free(self, order_free):
|
|
218
|
+
if order_free not in ["yes", "no"]:
|
|
219
|
+
raise ValueError("Invalid order-free value.")
|
|
220
|
+
return order_free
|