Skip to content

Commit

Permalink
Change update response code
Browse files Browse the repository at this point in the history
  • Loading branch information
RasmusThing committed Dec 1, 2023
1 parent ebe477a commit 05f3395
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions pyfortiztp/models/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Devices(FortiZTP):
def __init__(self, **kwargs):
super(Devices, self).__init__(**kwargs)

def all(self, deviceSN: str=None):
def all(self, deviceSN: str = None):
"""Retrieves the status of a device.
Args:
Expand All @@ -27,12 +27,17 @@ def all(self, deviceSN: str=None):

# Send our request to the API
response = requests.get(url, headers={"Authorization": f"Bearer {self.api.access_token}"}, verify=self.api.verify)

# HTTP 200 OK
if response.status_code == 200:
return response.json()
else:
try:
return response.json()
except Exception:
return response

def update(self, deviceSN: list, deviceType: str, provisionStatus: str, provisionTarget: str, region: str=None, externalControllerIp: str=None, externalControllerSn: str=None):
def update(self, deviceSN: list, deviceType: str, provisionStatus: str, provisionTarget: str, region: str = None, externalControllerIp: str = None, externalControllerSn: str = None):
"""Provisions or unprovisions a device.
Args:
Expand Down Expand Up @@ -81,8 +86,11 @@ def update(self, deviceSN: list, deviceType: str, provisionStatus: str, provisio
# Send our request to the API
response = requests.put(self.api.fortiztp_host + f"/devices", headers={"Authorization": f"Bearer {self.api.access_token}"}, json=devices, verify=self.api.verify)

# API returns 204 No Content on successful request
if response.status_code == 204:
# API returns 200 OK on successful request
if response.status_code == 200:
return response.status_code
else:
return response.json()
try:
return response.json()
except Exception:
return response
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="pyfortiztp",
version="1.0.0",
version="1.0.1",
description="Python API client library for Fortinet's FortiZTP.",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 05f3395

Please sign in to comment.