Skip to content

Commit

Permalink
Check for response validity
Browse files Browse the repository at this point in the history
  • Loading branch information
ms264556 committed Sep 1, 2023
1 parent 29d1690 commit eea5000
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions aioruckus/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ERROR_CONNECT_TIMEOUT = "Timed out while waiting for client"
ERROR_CONNECT_TEMPORARY = "Temporarily unable to handle the request"
ERROR_POST_REDIRECTED = "Insufficient permission to run this command"
ERROR_POST_BADRESULT = "Unable to parse the response"
ERROR_POST_NORESULT = "The command was not understood"
ERROR_LOGIN_INCORRECT = "Login incorrect"
ERROR_INVALID_AP = "Invalid AP"
Expand Down
3 changes: 3 additions & 0 deletions aioruckus/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

class AuthenticationError(Exception):
"""Invalid login."""

class SchemaError(KeyError):
"""Response doesn't contain expected keys"""
11 changes: 9 additions & 2 deletions aioruckus/ruckusapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

import xmltodict

from aioruckus.exceptions import SchemaError

from .abcsession import AbcSession, ConfigItem
from .const import SystemStat
from .const import ERROR_POST_BADRESULT, SystemStat

class RuckusApi(ABC):
"""Ruckus ZoneDirector or Unleashed Configuration API"""
Expand Down Expand Up @@ -125,7 +127,12 @@ def _ruckus_xml_unwrap(xml: str, collection_elements: List[str] = None, aggressi
[] if not collection_elements else [f"{ce}-list"
for ce in collection_elements] + collection_elements
)
for key in ["ajax-response", "response"] + (["apstamgr-stat"] if aggressive_unwrap else []) + collection_list:
try:
result = result["ajax-response"]["response"]
except KeyError as kerr:
raise SchemaError(ERROR_POST_BADRESULT) from kerr

for key in (["apstamgr-stat"] if aggressive_unwrap else []) + collection_list:
if result and key and key in result:
result = result[key]
return result or []
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools>=68.0", "wheel"]
requires = ["setuptools>=68.1", "wheel"]
build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = aioruckus
version = 0.31
version = 0.32
author = ms264556
author_email = [email protected]
description = Python API to interact with Ruckus Unleashed and ZoneDirector devices.
Expand Down

0 comments on commit eea5000

Please sign in to comment.