Skip to content

Commit 3c1dbca

Browse files
committed
Refactor API parameter handling and improve documentation
- Updated `searchOrgNacClients` and `searchSiteNacClients` to correct status options from 'session_ended' to 'session_stopped'. - Rearranged parameters in `searchOrgWanClients`, `searchSiteWanClients`, and `searchSiteWirelessClients` for consistency and clarity. - Added new parameters `cert_expiry_duration` and `psk_name` to `searchSiteNacClients` and `searchSiteWirelessClients` respectively. - Removed unused parameters and cleaned up query parameter handling in various search functions. - Enhanced logging and sanitization in `test_logger.py` to ensure sensitive data is properly redacted. - Deleted obsolete test file `test.py` to streamline the test suite. - Improved test readability and structure across multiple test files.
1 parent ed05bf1 commit 3c1dbca

21 files changed

Lines changed: 374 additions & 336 deletions

src/mistapi/__api_request.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ def _request_with_retry(
188188
self._log_proxy()
189189
resp = request_fn()
190190
logger.debug(
191-
"apirequest:%s:request headers:%s", method_name, self._remove_auth_from_headers(resp)
191+
"apirequest:%s:request headers:%s",
192+
method_name,
193+
self._remove_auth_from_headers(resp),
192194
)
193195
resp.raise_for_status()
194196
break
@@ -203,7 +205,9 @@ def _request_with_retry(
203205
if e.response.status_code == 429 and attempt < self._MAX_429_RETRIES:
204206
logger.warning(
205207
"apirequest:%s:HTTP 429 (attempt %s/%s)",
206-
method_name, attempt + 1, self._MAX_429_RETRIES,
208+
method_name,
209+
attempt + 1,
210+
self._MAX_429_RETRIES,
207211
)
208212
try:
209213
self._next_apitoken()
@@ -214,7 +218,9 @@ def _request_with_retry(
214218
logger.error("apirequest:%s:HTTP error: %s", method_name, e)
215219
if resp:
216220
logger.error(
217-
"apirequest:%s:HTTP error description: %s", method_name, resp.json()
221+
"apirequest:%s:HTTP error description: %s",
222+
method_name,
223+
resp.json(),
218224
)
219225
break
220226
except Exception as e:
@@ -334,19 +340,22 @@ def mist_post_file(
334340
multipart_form_data = {}
335341
url = self._url(uri)
336342
logger.debug(
337-
"apirequest:mist_post_file:initial multipart_form_data:%s", multipart_form_data
343+
"apirequest:mist_post_file:initial multipart_form_data:%s",
344+
multipart_form_data,
338345
)
339346
generated_multipart_form_data: dict[str, Any] = {}
340347
for key in multipart_form_data:
341348
logger.debug(
342349
"apirequest:mist_post_file:multipart_form_data:%s = %s",
343-
key, multipart_form_data[key],
350+
key,
351+
multipart_form_data[key],
344352
)
345353
if multipart_form_data[key]:
346354
try:
347355
if key in ["csv", "file"]:
348356
logger.debug(
349-
"apirequest:mist_post_file:reading file:%s", multipart_form_data[key]
357+
"apirequest:mist_post_file:reading file:%s",
358+
multipart_form_data[key],
350359
)
351360
f = open(multipart_form_data[key], "rb")
352361
generated_multipart_form_data[key] = (
@@ -363,7 +372,8 @@ def mist_post_file(
363372
logger.error(
364373
"apirequest:mist_post_file:multipart_form_data:"
365374
"Unable to parse JSON object %s with value %s",
366-
key, multipart_form_data[key],
375+
key,
376+
multipart_form_data[key],
367377
)
368378
logger.error(
369379
"apirequest:mist_post_file: Exception occurred",
@@ -377,7 +387,8 @@ def mist_post_file(
377387
def _do_post_file():
378388
resp = self._session.post(url, files=generated_multipart_form_data)
379389
logger.debug(
380-
"apirequest:mist_post_file:request body:%s", self.remove_file_from_body(resp)
390+
"apirequest:mist_post_file:request body:%s",
391+
self.remove_file_from_body(resp),
381392
)
382393
return resp
383394

src/mistapi/__api_session.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,10 @@ def login_with_return(
859859
LOGGER.info("apisession:login_with_return:access authorized")
860860
return {"authenticated": True, "error": ""}
861861
else:
862-
LOGGER.error("apisession:login_with_return:access denied: status code %s", resp.status_code)
862+
LOGGER.error(
863+
"apisession:login_with_return:access denied: status code %s",
864+
resp.status_code,
865+
)
863866
return {"authenticated": False, "error": resp.data}
864867

865868
def logout(self) -> None:
@@ -1102,9 +1105,7 @@ def _getself(self) -> bool:
11021105
print()
11031106
print(" Authenticated ".center(80, "-"))
11041107
print(f"\r\nWelcome {self.first_name} {self.last_name}!\r\n")
1105-
LOGGER.info(
1106-
"apisession:_getself:account info processed successfully"
1107-
)
1108+
LOGGER.info("apisession:_getself:account info processed successfully")
11081109
return True
11091110
elif resp.proxy_error:
11101111
LOGGER.critical("apisession:_getself:proxy not valid...")

src/mistapi/api/v1/orgs/clients.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -284,20 +284,20 @@ def searchOrgWirelessClients(
284284
mist_session: _APISession,
285285
org_id: str,
286286
site_id: str | None = None,
287-
mac: str | None = None,
288-
ip: str | None = None,
289-
hostname: str | None = None,
287+
ap: str | None = None,
290288
band: str | None = None,
291289
device: str | None = None,
292-
os: str | None = None,
290+
hostname: str | None = None,
291+
ip: str | None = None,
292+
mac: str | None = None,
293293
model: str | None = None,
294-
ap: str | None = None,
294+
os: str | None = None,
295295
psk_id: str | None = None,
296296
psk_name: str | None = None,
297-
username: str | None = None,
298-
vlan: str | None = None,
299297
ssid: str | None = None,
300298
text: str | None = None,
299+
username: str | None = None,
300+
vlan: str | None = None,
301301
limit: int | None = None,
302302
start: str | None = None,
303303
end: str | None = None,
@@ -320,20 +320,20 @@ def searchOrgWirelessClients(
320320
QUERY PARAMS
321321
------------
322322
site_id : str
323-
mac : str
324-
ip : str
325-
hostname : str
323+
ap : str
326324
band : str
327325
device : str
328-
os : str
326+
hostname : str
327+
ip : str
328+
mac : str
329329
model : str
330-
ap : str
330+
os : str
331331
psk_id : str
332332
psk_name : str
333-
username : str
334-
vlan : str
335333
ssid : str
336334
text : str
335+
username : str
336+
vlan : str
337337
limit : int, default: 100
338338
start : str
339339
end : str
@@ -351,34 +351,34 @@ def searchOrgWirelessClients(
351351
query_params: dict[str, str] = {}
352352
if site_id:
353353
query_params["site_id"] = str(site_id)
354-
if mac:
355-
query_params["mac"] = str(mac)
356-
if ip:
357-
query_params["ip"] = str(ip)
358-
if hostname:
359-
query_params["hostname"] = str(hostname)
354+
if ap:
355+
query_params["ap"] = str(ap)
360356
if band:
361357
query_params["band"] = str(band)
362358
if device:
363359
query_params["device"] = str(device)
364-
if os:
365-
query_params["os"] = str(os)
360+
if hostname:
361+
query_params["hostname"] = str(hostname)
362+
if ip:
363+
query_params["ip"] = str(ip)
364+
if mac:
365+
query_params["mac"] = str(mac)
366366
if model:
367367
query_params["model"] = str(model)
368-
if ap:
369-
query_params["ap"] = str(ap)
368+
if os:
369+
query_params["os"] = str(os)
370370
if psk_id:
371371
query_params["psk_id"] = str(psk_id)
372372
if psk_name:
373373
query_params["psk_name"] = str(psk_name)
374-
if username:
375-
query_params["username"] = str(username)
376-
if vlan:
377-
query_params["vlan"] = str(vlan)
378374
if ssid:
379375
query_params["ssid"] = str(ssid)
380376
if text:
381377
query_params["text"] = str(text)
378+
if username:
379+
query_params["username"] = str(username)
380+
if vlan:
381+
query_params["vlan"] = str(vlan)
382382
if limit:
383383
query_params["limit"] = str(limit)
384384
if start:

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

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -485,17 +485,16 @@ def listOrgApsMacs(
485485
def searchOrgDevices(
486486
mist_session: _APISession,
487487
org_id: str,
488-
band_24_bandwidth: int | None = None,
489488
band_24_channel: int | None = None,
490-
band_24_power: int | None = None,
491-
band_5_bandwidth: int | None = None,
492489
band_5_channel: int | None = None,
493-
band_5_power: int | None = None,
494-
band_6_bandwidth: int | None = None,
495490
band_6_channel: int | None = None,
491+
band_24_bandwidth: int | None = None,
492+
band_5_bandwidth: int | None = None,
493+
band_6_bandwidth: int | None = None,
494+
band_24_power: int | None = None,
495+
band_5_power: int | None = None,
496496
band_6_power: int | None = None,
497-
cpu: str | None = None,
498-
clustered: str | None = None,
497+
clustered: bool | None = None,
499498
eth0_port_speed: int | None = None,
500499
evpntopo_id: str | None = None,
501500
ext_ip: str | None = None,
@@ -505,8 +504,6 @@ def searchOrgDevices(
505504
last_hostname: str | None = None,
506505
lldp_mgmt_addr: str | None = None,
507506
lldp_port_id: str | None = None,
508-
lldp_power_allocated: int | None = None,
509-
lldp_power_draw: int | None = None,
510507
lldp_system_desc: str | None = None,
511508
lldp_system_name: str | None = None,
512509
mac: str | None = None,
@@ -518,10 +515,12 @@ def searchOrgDevices(
518515
node0_mac: str | None = None,
519516
node1_mac: str | None = None,
520517
power_constrained: bool | None = None,
518+
radius_stats: str | None = None,
521519
site_id: str | None = None,
520+
stats: bool | None = None,
522521
t128agent_version: str | None = None,
523-
version: str | None = None,
524522
type: str | None = None,
523+
version: str | None = None,
525524
limit: int | None = None,
526525
start: str | None = None,
527526
end: str | None = None,
@@ -543,17 +542,16 @@ def searchOrgDevices(
543542
544543
QUERY PARAMS
545544
------------
546-
band_24_bandwidth : int
547545
band_24_channel : int
548-
band_24_power : int
549-
band_5_bandwidth : int
550546
band_5_channel : int
551-
band_5_power : int
552-
band_6_bandwidth : int
553547
band_6_channel : int
548+
band_24_bandwidth : int
549+
band_5_bandwidth : int
550+
band_6_bandwidth : int
551+
band_24_power : int
552+
band_5_power : int
554553
band_6_power : int
555-
cpu : str
556-
clustered : str
554+
clustered : bool
557555
eth0_port_speed : int
558556
evpntopo_id : str
559557
ext_ip : str
@@ -563,25 +561,26 @@ def searchOrgDevices(
563561
last_hostname : str
564562
lldp_mgmt_addr : str
565563
lldp_port_id : str
566-
lldp_power_allocated : int
567-
lldp_power_draw : int
568564
lldp_system_desc : str
569565
lldp_system_name : str
570566
mac : str
571567
model : str
572568
mxedge_id : str
573569
mxedge_ids : str
574570
mxtunnel_status : str{'down', 'up'}
575-
If `type`==`ap`, MxTunnel status, up / down
576-
node : str
571+
When `type`==`ap`, MxTunnel status, up / down.
572+
node : str{'node0', 'node1'}
573+
When `type`==`gateway`. enum: `node0`, `node1`
577574
node0_mac : str
578575
node1_mac : str
579576
power_constrained : bool
577+
radius_stats : str
580578
site_id : str
579+
stats : bool
581580
t128agent_version : str
582-
version : str
583581
type : str{'ap', 'gateway', 'switch'}, default: ap
584582
Type of device. enum: `ap`, `gateway`, `switch`
583+
version : str
585584
limit : int, default: 100
586585
start : str
587586
end : str
@@ -597,26 +596,24 @@ def searchOrgDevices(
597596

598597
uri = f"/api/v1/orgs/{org_id}/devices/search"
599598
query_params: dict[str, str] = {}
600-
if band_24_bandwidth:
601-
query_params["band_24_bandwidth"] = str(band_24_bandwidth)
602599
if band_24_channel:
603600
query_params["band_24_channel"] = str(band_24_channel)
604-
if band_24_power:
605-
query_params["band_24_power"] = str(band_24_power)
606-
if band_5_bandwidth:
607-
query_params["band_5_bandwidth"] = str(band_5_bandwidth)
608601
if band_5_channel:
609602
query_params["band_5_channel"] = str(band_5_channel)
610-
if band_5_power:
611-
query_params["band_5_power"] = str(band_5_power)
612-
if band_6_bandwidth:
613-
query_params["band_6_bandwidth"] = str(band_6_bandwidth)
614603
if band_6_channel:
615604
query_params["band_6_channel"] = str(band_6_channel)
605+
if band_24_bandwidth:
606+
query_params["band_24_bandwidth"] = str(band_24_bandwidth)
607+
if band_5_bandwidth:
608+
query_params["band_5_bandwidth"] = str(band_5_bandwidth)
609+
if band_6_bandwidth:
610+
query_params["band_6_bandwidth"] = str(band_6_bandwidth)
611+
if band_24_power:
612+
query_params["band_24_power"] = str(band_24_power)
613+
if band_5_power:
614+
query_params["band_5_power"] = str(band_5_power)
616615
if band_6_power:
617616
query_params["band_6_power"] = str(band_6_power)
618-
if cpu:
619-
query_params["cpu"] = str(cpu)
620617
if clustered:
621618
query_params["clustered"] = str(clustered)
622619
if eth0_port_speed:
@@ -637,10 +634,6 @@ def searchOrgDevices(
637634
query_params["lldp_mgmt_addr"] = str(lldp_mgmt_addr)
638635
if lldp_port_id:
639636
query_params["lldp_port_id"] = str(lldp_port_id)
640-
if lldp_power_allocated:
641-
query_params["lldp_power_allocated"] = str(lldp_power_allocated)
642-
if lldp_power_draw:
643-
query_params["lldp_power_draw"] = str(lldp_power_draw)
644637
if lldp_system_desc:
645638
query_params["lldp_system_desc"] = str(lldp_system_desc)
646639
if lldp_system_name:
@@ -663,14 +656,18 @@ def searchOrgDevices(
663656
query_params["node1_mac"] = str(node1_mac)
664657
if power_constrained:
665658
query_params["power_constrained"] = str(power_constrained)
659+
if radius_stats:
660+
query_params["radius_stats"] = str(radius_stats)
666661
if site_id:
667662
query_params["site_id"] = str(site_id)
663+
if stats:
664+
query_params["stats"] = str(stats)
668665
if t128agent_version:
669666
query_params["t128agent_version"] = str(t128agent_version)
670-
if version:
671-
query_params["version"] = str(version)
672667
if type:
673668
query_params["type"] = str(type)
669+
if version:
670+
query_params["version"] = str(version)
674671
if limit:
675672
query_params["limit"] = str(limit)
676673
if start:

0 commit comments

Comments
 (0)