Skip to content

Commit

Permalink
Add options for enabling tls in frontend and backend
Browse files Browse the repository at this point in the history
  • Loading branch information
grs committed Nov 1, 2024
1 parent 590abaa commit b8c781d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion backend/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ async def health(request):
parser = argparse.ArgumentParser()
parser.add_argument("--host", default="0.0.0.0")
parser.add_argument("--port", type=int, default=8080)
parser.add_argument("--ssl-keyfile", default="")
parser.add_argument("--ssl-certfile", default="")
parser.add_argument("--ssl-ca-certs", default="")
parser.add_argument("--ssl-cert-reqs", type=int, default=0)

args = parser.parse_args()

uvicorn.run(star, host=args.host, port=args.port)
uvicorn.run(star, host=args.host, port=args.port, ssl_keyfile=args.ssl_keyfile, ssl_certfile=args.ssl_certfile, ssl_ca_certs=args.ssl_ca_certs, ssl_cert_reqs=args.ssl_cert_reqs)
15 changes: 14 additions & 1 deletion frontend/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def send_greeting(name, text):
"text": text,
}

async with AsyncClient() as client:
async with AsyncClient(verify=verify, cert=cert) as client:
try:
response = await client.post(f"{backend_url}/api/hello", json=request_data)
except HTTPError as e:
Expand All @@ -118,10 +118,23 @@ async def health(request):
parser.add_argument("--host", default="0.0.0.0")
parser.add_argument("--port", type=int, default=8080)
parser.add_argument("--backend", metavar="URL", default="http://backend:8080")
parser.add_argument("--ssl-keyfile", default="")
parser.add_argument("--ssl-certfile", default="")
parser.add_argument("--ssl-ca-certs", default="")

args = parser.parse_args()

global backend_url
backend_url = args.backend

global cert
if args.ssl_certfile and args.ssl_keyfile:
cert = (args.ssl_certfile, args.ssl_keyfile)

global verify
if args.ssl_ca_certs:
verify = args.ssl_ca_certs
else:
verify = True

uvicorn.run(star, host=args.host, port=args.port)

0 comments on commit b8c781d

Please sign in to comment.