Skip to content

Commit 811a1ab

Browse files
committed
1.3.0 (2023-11-16)
------------------ * [new] Fortigate.get_l()
1 parent 8c0d933 commit 811a1ab

File tree

6 files changed

+60
-1498
lines changed

6 files changed

+60
-1498
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
CHANGELOG
55
=========
66

7+
1.3.0 (2023-11-16)
8+
------------------
9+
* [new] Fortigate.get_l()
10+
11+
712
1.2.5 (2023-11-06)
813
------------------
914
* [fix] Look for a cookie that is named "ccsrftoken" or stars with "ccsrftoken_".

README.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ or install the package from github.com release
4747

4848
.. code:: bash
4949
50-
pip install https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/1.2.5.tar.gz
50+
pip install https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/1.3.0.tar.gz
5151
5252
or install the package from github.com repository
5353

@@ -943,7 +943,8 @@ Return
943943

944944
get()
945945
.....
946-
**Fortigate.get(url)** GET object configured in the Fortigate
946+
**Fortigate.get(url)** GET object configured in the Fortigate.
947+
Fortigate returns dictionary with key="results".
947948

948949
=============== ======= ============================================================================
949950
Parameter Type Description
@@ -955,6 +956,21 @@ Return
955956
*List[dict]* of the objects data
956957

957958

959+
get_l()
960+
.....
961+
**Fortigate.get_l(url)** GET list of objects.
962+
Fortigate returns list of items.
963+
964+
=============== ======= ============================================================================
965+
Parameter Type Description
966+
=============== ======= ============================================================================
967+
url *str* REST API URL
968+
=============== ======= ============================================================================
969+
970+
Return
971+
*List[dict]* of the objects
972+
973+
958974
post()
959975
......
960976
**Fortigate.post(url, data)** POST (create) object in the Fortigate based on the data

examples/fortigate.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@
8181
# 'crscore': 30,
8282
# ...
8383

84+
# Get list
85+
output = fgt.get_l(url="/api/v2/monitor/firewall/policy?global=1")
86+
pprint(output)
87+
# [{'build': 2093,
88+
# 'http_method': 'GET',
89+
# 'name': 'policy',
90+
# 'path': 'firewall',
91+
# 'results': [{'active_sessions': 0,
92+
# 'asic_bytes': 0,
93+
# 'asic_packets': 0,
94+
# ...
95+
8496

8597
# Get Directory
8698
output = fgt.directory(url="/api/v2/log")

fortigate_api/fortigate.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,19 +277,36 @@ def exist(self, url: str) -> Response:
277277
def get(self, url: str) -> LDAny:
278278
"""GET object configured in the Fortigate.
279279
280-
::
281-
:param url: REST API URL to the object
282-
:type url: str
280+
Fortigate returns dictionary with key="results".
281+
:param url: REST API URL to the object
282+
:type url: str
283283
284-
:return: List of the Fortigate objects
285-
:rtype: List[dict]
284+
:return: List of the Fortigate objects
285+
:rtype: List[dict]
286286
"""
287287
response: Response = self._response("get", url)
288288
if not response.ok:
289289
logging.info("code=%s, reason=%s, url=%s", response.status_code, response.reason, url)
290290
return []
291291
response_json = response.json()
292-
results: LDAny = response_json.get("results") or []
292+
results: LDAny = list(response_json.get("results") or [])
293+
return results
294+
295+
def get_l(self, url: str) -> list:
296+
"""GET list of objects.
297+
298+
Fortigate returns list of items.
299+
:param url: REST API URL
300+
:type url: str
301+
302+
:return: List of the objects
303+
:rtype: List[dict]
304+
"""
305+
response: Response = self._response("get", url)
306+
if not response.ok:
307+
logging.info("code=%s, reason=%s, url=%s", response.status_code, response.reason, url)
308+
return []
309+
results: LDAny = list(response.json() or [])
293310
return results
294311

295312
def post(self, url: str, data: DAny) -> Response:

0 commit comments

Comments
 (0)