Skip to content

Commit ed4a230

Browse files
committed
fix mist_post body type
add support for list type
1 parent 540518a commit ed4a230

109 files changed

Lines changed: 295 additions & 219 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

generate_from_openapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def {operation_id}(mist_session: _APISession{code_path_params}) -> _APIResponse:
123123

124124
# Template for POST method functions with JSON body
125125
FUNCTION_POST_BODY_TEMPLATE = """
126-
def {operation_id}(mist_session: _APISession{code_path_params}, body:dict) -> _APIResponse:
126+
def {operation_id}(mist_session: _APISession{code_path_params}, body:dict|list) -> _APIResponse:
127127
{code_desc}
128128
uri = {uri}
129129
resp = mist_session.mist_post(uri=uri, body=body)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "mistapi"
7-
version = "0.56.00"
7+
version = "0.56.0"
88
authors = [{ name = "Thomas Munzer", email = "tmunzer@juniper.net" }]
99
description = "Python package to simplify the Mist System APIs usage"
1010
keywords = ["Mist", "Juniper", "API"]

src/mistapi/__api_request.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ def _log_proxy(self) -> None:
7373
pwd_regex = r":([^:@]*)@" # nosec bandit B105
7474
if self._session.proxies.get("https"):
7575
logger.info(
76-
f"apirequest:sending request to proxy server {re.sub(pwd_regex, ':*********@', self._session.proxies['https'])}"
76+
"apirequest:sending request to proxy server %s",
77+
re.sub(pwd_regex, ":*********@", self._session.proxies["https"]),
7778
)
7879
print(
79-
f"apirequest:sending request to proxy server {re.sub(pwd_regex, ':*********@', self._session.proxies['https'])}"
80+
"apirequest:sending request to proxy server %s",
81+
re.sub(pwd_regex, ":*********@", self._session.proxies["https"]),
8082
)
8183

8284
def _next_apitoken(self) -> None:
@@ -207,7 +209,7 @@ def mist_get(self, uri: str, query: dict[str, str] | None = None) -> APIResponse
207209
self._count += 1
208210
return APIResponse(url=url, response=resp, proxy_error=proxy_failed)
209211

210-
def mist_post(self, uri: str, body: dict | None = None) -> APIResponse:
212+
def mist_post(self, uri: str, body: dict | list | None = None) -> APIResponse:
211213
"""
212214
POST HTTP Request
213215
@@ -244,7 +246,7 @@ def mist_post(self, uri: str, body: dict | None = None) -> APIResponse:
244246
logger.error(f"apirequest:mist_post:Proxy Error: {proxy_error}")
245247
proxy_failed = True
246248
except requests.exceptions.ConnectionError as connexion_error:
247-
logger.error(f"Capirequest:mist_post:Connection Error: {connexion_error}")
249+
logger.error(f"apirequest:mist_post:Connection Error: {connexion_error}")
248250
except HTTPError as http_err:
249251
if http_err.response.status_code == 429:
250252
logger.warning(
@@ -263,7 +265,7 @@ def mist_post(self, uri: str, body: dict | None = None) -> APIResponse:
263265
logger.error("apirequest:mist_post: Exception occurred", exc_info=True)
264266
finally:
265267
self._count += 1
266-
return APIResponse(url=url, response=resp, proxy_error=proxy_failed)
268+
return APIResponse(url=url, response=resp, proxy_error=proxy_failed)
267269

268270
def mist_put(self, uri: str, body: dict | None = None) -> APIResponse:
269271
"""
@@ -321,7 +323,7 @@ def mist_put(self, uri: str, body: dict | None = None) -> APIResponse:
321323
logger.error("apirequest:mist_put: Exception occurred", exc_info=True)
322324
finally:
323325
self._count += 1
324-
return APIResponse(url=url, response=resp, proxy_error=proxy_failed)
326+
return APIResponse(url=url, response=resp, proxy_error=proxy_failed)
325327

326328
def mist_delete(self, uri: str, query: dict | None = None) -> APIResponse:
327329
"""
@@ -367,9 +369,11 @@ def mist_delete(self, uri: str, query: dict | None = None) -> APIResponse:
367369
logger.error("apirequest:mist_delete: Exception occurred", exc_info=True)
368370
finally:
369371
self._count += 1
370-
return APIResponse(url=url, response=resp, proxy_error=proxy_failed)
372+
return APIResponse(url=url, response=resp, proxy_error=proxy_failed)
371373

372-
def mist_post_file(self, uri: str, multipart_form_data: dict = {}) -> APIResponse:
374+
def mist_post_file(
375+
self, uri: str, multipart_form_data: dict | None = None
376+
) -> APIResponse:
373377
"""
374378
POST HTTP Request
375379
@@ -388,6 +392,8 @@ def mist_post_file(self, uri: str, multipart_form_data: dict = {}) -> APIRespons
388392
resp = None
389393
proxy_failed = False
390394
try:
395+
if multipart_form_data is None:
396+
multipart_form_data = {}
391397
url = self._url(uri)
392398
logger.info(f"apirequest:mist_post_file:sending request to {url}")
393399
logger.debug(
@@ -464,4 +470,4 @@ def mist_post_file(self, uri: str, multipart_form_data: dict = {}) -> APIRespons
464470
logger.error("apirequest:mist_post_file: Exception occurred", exc_info=True)
465471
finally:
466472
self._count += 1
467-
return APIResponse(url=url, response=resp, proxy_error=proxy_failed)
473+
return APIResponse(url=url, response=resp, proxy_error=proxy_failed)

src/mistapi/__version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "0.56.00"
1+
__version__ = "0.56.0"
22
__author__ = "Thomas Munzer <tmunzer@juniper.net>"

src/mistapi/api/v1/installer/orgs/devices.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def listInstallerListOfRecentlyClaimedDevices(
6666

6767

6868
def claimInstallerDevices(
69-
mist_session: _APISession, org_id: str, body: dict
69+
mist_session: _APISession, org_id: str, body: dict | list
7070
) -> _APIResponse:
7171
"""
7272
API doc: https://www.juniper.net/documentation/us/en/software/mist/api/http/api/installer/claim-installer-devices
@@ -319,7 +319,7 @@ def getInstallerDeviceVirtualChassis(
319319

320320

321321
def createInstallerVirtualChassis(
322-
mist_session: _APISession, org_id: str, fpc0_mac: str, body: dict
322+
mist_session: _APISession, org_id: str, fpc0_mac: str, body: dict | list
323323
) -> _APIResponse:
324324
"""
325325
API doc: https://www.juniper.net/documentation/us/en/software/mist/api/http/api/installer/create-installer-virtual-chassis

src/mistapi/api/v1/installer/orgs/sites.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ def deleteInstallerMap(
178178

179179

180180
def createInstallerMap(
181-
mist_session: _APISession, org_id: str, site_name: str, map_id: str, body: dict
181+
mist_session: _APISession,
182+
org_id: str,
183+
site_name: str,
184+
map_id: str,
185+
body: dict | list,
182186
) -> _APIResponse:
183187
"""
184188
API doc: https://www.juniper.net/documentation/us/en/software/mist/api/http/api/installer/create-installer-map

src/mistapi/api/v1/login/login.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from mistapi.__api_response import APIResponse as _APIResponse
1515

1616

17-
def login(mist_session: _APISession, body: dict) -> _APIResponse:
17+
def login(mist_session: _APISession, body: dict | list) -> _APIResponse:
1818
"""
1919
API doc: https://www.juniper.net/documentation/us/en/software/mist/api/http/api/admins/login/login
2020

src/mistapi/api/v1/login/lookup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from mistapi.__api_response import APIResponse as _APIResponse
1515

1616

17-
def lookup(mist_session: _APISession, body: dict) -> _APIResponse:
17+
def lookup(mist_session: _APISession, body: dict | list) -> _APIResponse:
1818
"""
1919
API doc: https://www.juniper.net/documentation/us/en/software/mist/api/http/api/admins/lookup/lookup
2020

src/mistapi/api/v1/login/oauth.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def unlinkOauth2Provider(mist_session: _APISession, provider: str) -> _APIRespon
7272
return resp
7373

7474

75-
def loginOauth2(mist_session: _APISession, provider: str, body: dict) -> _APIResponse:
75+
def loginOauth2(
76+
mist_session: _APISession, provider: str, body: dict | list
77+
) -> _APIResponse:
7678
"""
7779
API doc: https://www.juniper.net/documentation/us/en/software/mist/api/http/api/admins/login/oauth2/login-oauth2
7880

src/mistapi/api/v1/login/two_factor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from mistapi.__api_response import APIResponse as _APIResponse
1515

1616

17-
def twoFactor(mist_session: _APISession, body: dict) -> _APIResponse:
17+
def twoFactor(mist_session: _APISession, body: dict | list) -> _APIResponse:
1818
"""
1919
API doc: https://www.juniper.net/documentation/us/en/software/mist/api/http/api/admins/login/two-factor
2020

0 commit comments

Comments
 (0)