From 0091fb29ecbcbbbdd90bdbddc0b811521b9319d6 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Wed, 13 Sep 2023 10:48:31 +0100 Subject: [PATCH] add README section for https --- .gitignore | 3 +++ openbb_sdk/sdk/core/README.md | 44 +++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2f60c1d5258..15fdeeeaafc 100644 --- a/.gitignore +++ b/.gitignore @@ -80,3 +80,6 @@ lightning_logs/ !openbb_sdk/install_all.sh openbb_sdk/sdk/core/tests/app/model/charts/test_chart_settings.py */mocked_path + +# CA certificates +*.pem diff --git a/openbb_sdk/sdk/core/README.md b/openbb_sdk/sdk/core/README.md index d58a60d3068..d6689a6ae2d 100644 --- a/openbb_sdk/sdk/core/README.md +++ b/openbb_sdk/sdk/core/README.md @@ -23,7 +23,8 @@ - [4.1.5. Environment variables](#415-environment-variables) - [4.2 Dynamic version](#42-dynamic-version) - [5. REST API](#5-rest-api) - - [5.1 Test users](#51-test-users) + - [5.1 HTTPS](#51-https) + - [5.2 Test users](#52-test-users) - [6. Front-end typing](#6-front-end-typing) ## 1. Introduction @@ -398,7 +399,46 @@ OpenBB SDK comes with a ready to use Rest API built with FastAPI. Start the appl uvicorn openbb_core.api.rest_api:app --reload ``` -## 5.1 Test users +### 5.1 HTTPS + +If you want to run your FastAPI app over HTTPS locally you can use [mkcert](https://github.com/FiloSottile/mkcert) and pass the certificate and key to `uvicorn`. + +0. Install `mkcert` (see instructions [here](https://github.com/FiloSottile/mkcert)) +1. cd into "openbb_sdk/sdk/core/openbb_core/api" +2. Run the following commands: + + ```shell + mkcert -install + mkcert localhost 127.0.0.1 ::1 + ``` + + You will see two files created in the current directory. + - Certificate: "localhost+2.pem" + - Key: "localhost+2-key.pem" + +3. Change the code to start the server inside "rest_api.py" to: + + ```python + if __name__ == "__main__": + import uvicorn + + uvicorn.run( + "openbb_core.api.rest_api:app", + reload=True, + ssl_keyfile="./localhost+2-key.pem", + ssl_certfile="./localhost+2.pem", + ) + ``` + +4. Run the server from the terminal with: + + ```shell + python rest_api.py + ``` + + Your app will be available at https://127.0.0.1:8000/ + +### 5.2 Test users There are 2 default users for testing purpose: