Skip to content

Commit

Permalink
Return json on instance route
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Oct 23, 2023
1 parent 5ae5362 commit 20a40dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
13 changes: 3 additions & 10 deletions cloudview/cloudview.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
import logging
import sys
import html
from concurrent.futures import ThreadPoolExecutor
from json import JSONEncoder
from io import StringIO
Expand Down Expand Up @@ -147,8 +146,7 @@ def not_found():
"""
Not found!
"""
response = Response("Not found!")
response.status_int = 404
response = Response("Not found!", status=404)
return response


Expand Down Expand Up @@ -186,13 +184,8 @@ def handle_instance(request: Request) -> Response:
info = client.get_instance(instance_id, **request.params)
if client is None or info is None:
return not_found()
response = html.escape(
JSONEncoder(default=str, indent=4, sort_keys=True).encode(info.extra)
)
header = """<!DOCTYPE html><html><head><meta charset="utf-8">
<link rel="shortcut icon" href="/favicon.ico"></head><body>"""
footer = "</body></html>"
return Response(f"{header}<pre>{response}</pre>{footer}")
response = JSONEncoder(default=str, indent=4, sort_keys=True).encode(info.extra)
return Response(response, content_type='application/json; charset=utf-8')


def web_server():
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apache-libcloud==3.8.0
cachetools==5.3.1
certifi==2023.7.22
cffi==1.16.0
charset-normalizer==3.3.0
charset-normalizer==3.3.1
cryptography==41.0.4
hupper==1.12
idna==3.4
Expand Down

0 comments on commit 20a40dd

Please sign in to comment.