common
Common objects
OP
module-attribute
#
OP = {
"eq": "==",
"neq": "!=",
"lt": "<",
"le": "<=",
"gt": ">",
"ge": ">=",
"or": "&",
"in": "in",
"contain": "contain",
"like": "like",
"not_like": "!like",
"glob": "glob",
"not_glob": "!glob",
}
ComplexFilter #
ComplexFilter(
a: Union[ComplexFilter, FilterList, F], op: Literal[",", "||", "&&"], b: Union[ComplexFilter, FilterList, F]
)
Complex handling of filters and their operator
Source code in pyfortinet/fmg_api/common.py
generate #
F #
Filter class that allows us to define a single filter for an object
Argument format is {field}={value} or {field}__{operator}={value}
Special argument _sep can be passed to indicate the search field separator character, if it's not the _.
Only one argument can be passed!
Filter object can be used at FMG.get method
Attributes:
| Name | Type | Description |
|---|---|---|
negate |
bool
|
If true the filter is negated |
source |
str
|
The source is the API attribute we are looking at |
op |
str
|
The operator for the search |
targets |
str
|
The target is the value we are searching for |
Source code in pyfortinet/fmg_api/common.py
generate #
Generate API filter list
Source code in pyfortinet/fmg_api/common.py
FilterList #
FilterList(*members: Union[F, FilterList], op: Literal[',', '||', '&&'])
List of F objects
Source code in pyfortinet/fmg_api/common.py
generate #
Generate API filter output
Source code in pyfortinet/fmg_api/common.py
Scope #
Specify scope for an object
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Scope name (e.g. firewall name or group name) |
vdom |
str
|
VDOM if applicable |
find_matching_parenthesis #
Helper function to find matching parenthesis
Find the index of the closing parenthesis that matches the first opening parenthesis in the input string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_string
|
str
|
The string to be scanned for matching parentheses. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The index of the matching closing parenthesis if found, else returns None. |
Source code in pyfortinet/fmg_api/common.py
text_to_filter #
text_to_filter(text: str) -> FILTER_TYPE
Text to filter object
Format of the text follows the OP definition!
This is a simple text to filter object converter. Parenthesis are supported.
Simple field comparisons with and/or and , operators are supported. , means a simple or between same
type fields.
Field name can contain - and characters, refer to API docs for available field names.
structure::
fname fop fvalue OP fname fop fvalue OP ...
---------------- ----------------
F token F token
Examples:
simple F filter
inversing
simple or function
>>> text_to_filter('name eq host_1, name eq host_2').generate()
[['name', '==', 'host_1'], ['name', '==', 'host_2']]
more complex filter
>>> text_to_filter('name eq host_1 and conf_status eq insync').generate()
[['name', '==', 'host_1'], '&&', ['conf_status', '==', 'insync']]
>>> assert text_to_filter("(name eq host_1 and (conf_status eq insync or conf_status eq modified))").generate()
[
["name", "==", "host_1"],
"&&",
[["conf_status", "==", "insync"], "||", ["conf_status", "==", "modified"]],
]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to parse |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FILTER_TYPE |
FILTER_TYPE
|
Filter object which can be used in FMG.get calls |
Raises: ValueError: text cannot be parsed
Source code in pyfortinet/fmg_api/common.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |