Skip to content

Commit ec28cbb

Browse files
author
vprusakovs
committed
1.0.2 (2023-02-07)
------------------ * [fix] ccsrftoken for fortios v7
1 parent 6e668fa commit ec28cbb

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
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.0.2 (2023-02-07)
8+
------------------
9+
* [fix] ccsrftoken for fortios v7
10+
11+
712
1.0.1 (2022-11-01)
813
------------------
914
* [fix] py.typed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ or install the package from github.com release
3636

3737
.. code:: bash
3838
39-
pip install https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/1.0.1.tar.gz
39+
pip install https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/1.0.2.tar.gz
4040
4141
or install the package from github.com repository
4242

fortigate_api/fortigate.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,19 @@ def login(self) -> None:
155155
verify=self.verify)
156156
except Exception as ex:
157157
raise self._hide_secret_ex(ex)
158-
csrf_token_name = f"ccsrftoken_{self.port}"
159-
for cookie in session.cookies:
160-
if cookie.name == csrf_token_name and isinstance(cookie.value, str):
161-
session.headers.update({"X-CSRFTOKEN": cookie.value[1:-1]})
162-
break
163-
else:
164-
raise ValueError(f"invalid login credentials, absent cookie {csrf_token_name}")
158+
159+
cookie_name = "ccsrftoken"
160+
cookies = [o for o in session.cookies if o.name == cookie_name]
161+
if not cookies:
162+
regex = cookie_name + r"_\d+$"
163+
cookies = [o for o in session.cookies if re.match(regex, o.name)]
164+
cookies = [o for o in cookies if isinstance(o.value, str)]
165+
if not cookies:
166+
raise ValueError("invalid login credentials, absent cookie ccsrftoken")
167+
cookie = cookies[0]
168+
token = cookie.value.strip("\"")
169+
session.headers.update({"X-CSRFTOKEN": token})
170+
165171
response: Response = session.get(url=f"{self.url}/api/v2/cmdb/system/vdom")
166172
response.raise_for_status()
167173
self._session = session

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "fortigate_api"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
authors = [
55
{ name="Vladimir Prusakov", email="vladimir.prusakovs@gmail.com" },
66
]
@@ -30,7 +30,7 @@ classifiers = [
3030
"Homepage" = "https://github.com/vladimirs-git/fortigate-api"
3131
"Repository" = "https://github.com/vladimirs-git/fortigate-api"
3232
"Bug Tracker" = "https://github.com/vladimirs-git/fortigate-api/issues"
33-
"Download URL" = "https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/1.0.1.tar.gz"
33+
"Download URL" = "https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/1.0.2.tar.gz"
3434
[tool.setuptools.packages.find]
3535
include = ["fortigate_api"]
3636
[tool.setuptools.package-data]

0 commit comments

Comments
 (0)