Skip to content

Commit

Permalink
1.3.0 (2023-11-16)
Browse files Browse the repository at this point in the history
------------------
* [new] Fortigate.get_l()
  • Loading branch information
vladimirs-git committed Nov 16, 2023
1 parent 8c0d933 commit 811a1ab
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1,498 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
CHANGELOG
=========

1.3.0 (2023-11-16)
------------------
* [new] Fortigate.get_l()


1.2.5 (2023-11-06)
------------------
* [fix] Look for a cookie that is named "ccsrftoken" or stars with "ccsrftoken_".
Expand Down
20 changes: 18 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ or install the package from github.com release

.. code:: bash
pip install https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/1.2.5.tar.gz
pip install https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/1.3.0.tar.gz
or install the package from github.com repository

Expand Down Expand Up @@ -943,7 +943,8 @@ Return

get()
.....
**Fortigate.get(url)** GET object configured in the Fortigate
**Fortigate.get(url)** GET object configured in the Fortigate.
Fortigate returns dictionary with key="results".

=============== ======= ============================================================================
Parameter Type Description
Expand All @@ -955,6 +956,21 @@ Return
*List[dict]* of the objects data


get_l()
.....
**Fortigate.get_l(url)** GET list of objects.
Fortigate returns list of items.

=============== ======= ============================================================================
Parameter Type Description
=============== ======= ============================================================================
url *str* REST API URL
=============== ======= ============================================================================

Return
*List[dict]* of the objects


post()
......
**Fortigate.post(url, data)** POST (create) object in the Fortigate based on the data
Expand Down
12 changes: 12 additions & 0 deletions examples/fortigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@
# 'crscore': 30,
# ...

# Get list
output = fgt.get_l(url="/api/v2/monitor/firewall/policy?global=1")
pprint(output)
# [{'build': 2093,
# 'http_method': 'GET',
# 'name': 'policy',
# 'path': 'firewall',
# 'results': [{'active_sessions': 0,
# 'asic_bytes': 0,
# 'asic_packets': 0,
# ...


# Get Directory
output = fgt.directory(url="/api/v2/log")
Expand Down
29 changes: 23 additions & 6 deletions fortigate_api/fortigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,36 @@ def exist(self, url: str) -> Response:
def get(self, url: str) -> LDAny:
"""GET object configured in the Fortigate.
::
:param url: REST API URL to the object
:type url: str
Fortigate returns dictionary with key="results".
:param url: REST API URL to the object
:type url: str
:return: List of the Fortigate objects
:rtype: List[dict]
:return: List of the Fortigate objects
:rtype: List[dict]
"""
response: Response = self._response("get", url)
if not response.ok:
logging.info("code=%s, reason=%s, url=%s", response.status_code, response.reason, url)
return []
response_json = response.json()
results: LDAny = response_json.get("results") or []
results: LDAny = list(response_json.get("results") or [])
return results

def get_l(self, url: str) -> list:
"""GET list of objects.
Fortigate returns list of items.
:param url: REST API URL
:type url: str
:return: List of the objects
:rtype: List[dict]
"""
response: Response = self._response("get", url)
if not response.ok:
logging.info("code=%s, reason=%s, url=%s", response.status_code, response.reason, url)
return []
results: LDAny = list(response.json() or [])
return results

def post(self, url: str, data: DAny) -> Response:
Expand Down
Loading

0 comments on commit 811a1ab

Please sign in to comment.