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 4
4
CHANGELOG
5
5
=========
6
6
7
+ 1.0.2 (2023-02-07)
8
+ ------------------
9
+ * [fix] ccsrftoken for fortios v7
10
+
11
+
7
12
1.0.1 (2022-11-01)
8
13
------------------
9
14
* [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
36
36
37
37
.. code :: bash
38
38
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
40
40
41
41
or install the package from github.com repository
42
42
Original file line number Diff line number Diff line change @@ -155,13 +155,19 @@ def login(self) -> None:
155
155
verify = self .verify )
156
156
except Exception as ex :
157
157
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
+
165
171
response : Response = session .get (url = f"{ self .url } /api/v2/cmdb/system/vdom" )
166
172
response .raise_for_status ()
167
173
self ._session = session
Original file line number Diff line number Diff line change 1
1
[project ]
2
2
name = " fortigate_api"
3
- version = " 1.0.1 "
3
+ version = " 1.0.2 "
4
4
authors = [
5
5
{ name =" Vladimir Prusakov" , email =" vladimir.prusakovs@gmail.com" },
6
6
]
@@ -30,7 +30,7 @@ classifiers = [
30
30
"Homepage" = " https://github.com/vladimirs-git/fortigate-api"
31
31
"Repository" = " https://github.com/vladimirs-git/fortigate-api"
32
32
"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"
34
34
[tool .setuptools .packages .find ]
35
35
include = [" fortigate_api" ]
36
36
[tool .setuptools .package-data ]
You can’t perform that action at this time.
0 commit comments