Skip to content

Commit

Permalink
Merge pull request #7 from edanalytics/bugfix/swagger_fetch_error
Browse files Browse the repository at this point in the history
Bugfix/swagger fetch error
  • Loading branch information
tomreitz authored Apr 7, 2023
2 parents 8ed3cbe + 5079aa7 commit 87e0792
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### v0.0.6
<details>
<summary>Released 2023-04-07</summary>

* bugfix: resolve error fetching Swagger docs
</details>

### v0.0.5
<details>
<summary>Released 2023-04-07</summary>
Expand Down
2 changes: 1 addition & 1 deletion lightbeam/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.5
0.0.6
15 changes: 8 additions & 7 deletions lightbeam/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def get_sorted_endpoints(self):
response = requests.get(self.config["dependencies_url"],
verify=self.lightbeam.config["connection"]["verify_ssl"])
if response.status_code not in [ 200, 201 ]:
raise Exception("Dependencies URL returned status {0} ({1})".format(response.status_code, (response.body[:75] + "...") if len(response.body)>75 else response.body))
raise Exception("Dependencies URL returned status {0} ({1})".format(response.status_code, (response.content[:75] + "...") if len(response.content)>75 else response.content))
data = response.json()
except Exception as e:
self.logger.critical("Unable to load dependencies from API... terminating. Check API connectivity. ({0})".format(str(e)))
Expand All @@ -165,9 +165,10 @@ def load_swagger_docs(self):
try:
self.logger.debug("fetching swagger docs...")
response = requests.get(self.config["open_api_metadata_url"],
verify=self.lightbeam.config["connection"]["verify_ssl"]).json()
if response.status_code not in [ 200, 201 ]:
raise Exception("OpenAPI metadata URL returned status {0} ({1})".format(response.status_code, (response.body[:75] + "...") if len(response.body)>75 else response.body))
verify=self.lightbeam.config["connection"]["verify_ssl"])
if not response.ok:
raise Exception("OpenAPI metadata URL returned status {0} ({1})".format(response.status_code, (response.content[:75] + "...") if len(response.content)>75 else response.content))
openapi = response.json()

except Exception as e:
self.logger.critical("Unable to load Swagger docs from API... terminating. Check API connectivity.")
Expand All @@ -182,7 +183,7 @@ def load_swagger_docs(self):
self.logger.debug("creating cache dir {0}".format(cache_dir))
os.mkdir(cache_dir)

for endpoint in response:
for endpoint in openapi:
endpoint_type = endpoint["name"].lower()
if endpoint_type=="descriptors" or endpoint_type=="resources":
swagger_url = endpoint["endpointUri"]
Expand All @@ -204,8 +205,8 @@ def load_swagger_docs(self):
response = requests.get(swagger_url,
verify=self.lightbeam.config["connection"]["verify_ssl"]
)
if response.status_code not in [ 200, 201 ]:
raise Exception("OpenAPI metadata URL returned status {0} ({1})".format(response.status_code, (response.body[:75] + "...") if len(response.body)>75 else response.body))
if not response.ok:
raise Exception("OpenAPI metadata URL returned status {0} ({1})".format(response.status_code, (response.content[:75] + "...") if len(response.content)>75 else response.content))
swagger = response.json()

except Exception as e:
Expand Down

0 comments on commit 87e0792

Please sign in to comment.