File tree Expand file tree Collapse file tree 4 files changed +21
-10
lines changed Expand file tree Collapse file tree 4 files changed +21
-10
lines changed Original file line number Diff line number Diff line change 44 CHANGELOG
55=========
66
7+ 1.0.2 (2023-02-07)
8+ ------------------
9+ * [fix] ccsrftoken for fortios v7
10+
11+
7121.0.1 (2022-11-01)
813------------------
914* [fix] py.typed
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11[project ]
22name = " fortigate_api"
3- version = " 1.0.1 "
3+ version = " 1.0.2 "
44authors = [
55 {
name =
" Vladimir Prusakov" ,
email =
" [email protected] " },
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 ]
3535include = [" fortigate_api" ]
3636[tool .setuptools .package-data ]
You can’t perform that action at this time.
0 commit comments