Skip to content

Commit e02bfe9

Browse files
committed
Exposing the port in the dockerfile and making sure hte openapi docs can be viewed when mounted under a base path
1 parent ccb9c7e commit e02bfe9

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
88

99
COPY ./app /code/app
1010

11+
EXPOSE 80
12+
1113
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]

app/main.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@
4040
ADMIN_USER_USERNAME = "admin"
4141
ADMIN_USER_PASSWORD = env("ADMIN_USER_PASSWORD", "admin")
4242

43+
BASE_URL = env("BASE_URL", "")
44+
4345

4446
# Setting up app and other context
45-
app = FastAPI()
47+
app = FastAPI(root_path=BASE_URL)
4648
oauth2_scheme = OAuth2PasswordBearerOrCookie(
4749
tokenUrl="login", cookie_name=ACCESS_COOKIE_NAME
4850
)
@@ -162,7 +164,11 @@ async def login(form_data: OAuth2PasswordRequestForm = Depends()):
162164

163165
# Query database
164166
query = users.select().where(User.username == username)
165-
user = User.from_record(await database.fetch_one(query))
167+
record = await database.fetch_one(query)
168+
if not record:
169+
raise HTTPException(401, "Could not validate credentials")
170+
171+
user = User.from_record(record)
166172

167173
# Compare credentials
168174
if not pwd_context.verify(password, user.hashed_password):
@@ -256,7 +262,11 @@ async def verify_emqx(
256262
):
257263
"""Authenticate and authorize a request according to EMQX HTTP ACL plugin"""
258264
query = users.select().where(User.username == username)
259-
user: User = User.from_record(await database.fetch_one(query))
265+
record = await database.fetch_one(query)
266+
if not record:
267+
raise HTTPException(403, "Access not allowed")
268+
269+
user = User.from_record(record)
260270

261271
# ACL checks
262272
if patterns := user.topic_whitelist:

0 commit comments

Comments
 (0)