Skip to content

Commit

Permalink
disable swagger UI docs in non-dev environments
Browse files Browse the repository at this point in the history
Start Swagger UI interactive FastAPI docs **only**
when env var DEPLOYMENT is set as "development"

Signed-off-by: Vallari Agrawal <[email protected]>
  • Loading branch information
VallariAg committed Nov 6, 2023
1 parent f92d3f3 commit 0665628
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ A REST API to execute [teuthology commands](https://docs.ceph.com/projects/teuth
volumes:
- ../../../teuthology-api:/teuthology_api/:rw
```
`DEPLOYMENT: development` would run the server in `--reload` mode (server would restart when changes are made in `/src` dir) and `volumes` would mount host directory to docker's directory (local changes would reflect in docker container).
`DEPLOYMENT: development` would:
1) run the server in `--reload` mode (server would restart when changes are made in `/src` dir),
2) `volumes` would mount host directory to docker's directory (local changes would reflect in docker container),
3) start Swagger UI interactive docs at `/docs` endpoint.

5. Follow teuthology development setup instructions from [here](https://github.com/ceph/teuthology/tree/main/docs/docker-compose).

Expand All @@ -64,7 +67,7 @@ A REST API to execute [teuthology commands](https://docs.ceph.com/projects/teuth

## Documentation

The documentation can be accessed at http://localhost:8082/docs after running the application.
The documentation can be accessed at http://localhost:8082/docs after running the application (with environment variable `DEPLOYMENT` set as `"development"`).

Note: To run commands, authenticate by visiting `http://localhost:8082/login` through browser and follow the github authentication steps (this stores the auth token in browser cookies).

Expand Down
10 changes: 9 additions & 1 deletion src/teuthology_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
PADDLES_URL = os.getenv("PADDLES_URL")

log = logging.getLogger(__name__)
app = FastAPI()


app_config = {}
if DEPLOYMENT == "development":
app_config["docs_url"] = "/docs"
else:
app_config["docs_url"] = None

app = FastAPI(**app_config)


@app.get("/")
Expand Down

0 comments on commit 0665628

Please sign in to comment.