Merge pull request #205 from vladak/web_api_check

refuse any device with web API version stricly less than 4
This commit is contained in:
Dan Halbert 2024-03-09 11:05:59 -05:00 committed by GitHub
commit 27ae1f978d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -589,14 +589,31 @@ class WebBackend(Backend):
def is_device_present(self):
"""
returns True if the device is currently connected
returns True if the device is currently connected and running supported version
"""
try:
_ = self.session.get(f"{self.device_location}/cp/version.json")
return True
with self.session.get(f"{self.device_location}/cp/version.json") as r:
r.raise_for_status()
web_api_version = r.json().get("web_api_version")
if web_api_version is None:
self.logger.error("Unable to get web API version from device.")
click.secho("Unable to get web API version from device.", fg="red")
return False
if web_api_version < 4:
self.logger.error(
f"Device running unsupported web API version {web_api_version} < 4."
)
click.secho(
f"Device running unsupported web API version {web_api_version} < 4.",
fg="red",
)
return False
except requests.exceptions.ConnectionError:
return False
return True
def get_device_versions(self):
"""
Returns a dictionary of metadata from modules on the connected device.