|
56 | 56 |
|
57 | 57 | security = HTTPBasic()
|
58 | 58 |
|
| 59 | +RUNNING_PROD = os.getenv("RUNNING_IN_PRODUCTION", "false").lower() == "true" |
59 | 60 |
|
60 |
| -def authenticate(credentials: Optional[HTTPBasicCredentials] = Depends(security) if os.getenv("RUNNING_IN_PRODUCTION") else None) -> None: |
| 61 | +def authenticate(credentials: Optional[HTTPBasicCredentials] = Depends(security)) -> None: |
61 | 62 | # Only perform authentication if RUNNING_IN_PRODUCTION is set to "true" (case-insensitive)
|
62 | 63 | if not os.getenv("RUNNING_IN_PRODUCTION"):
|
63 | 64 | # Not in production mode (or RUNNING_IN_PRODUCTION is not "true"),
|
@@ -86,6 +87,8 @@ def authenticate(credentials: Optional[HTTPBasicCredentials] = Depends(security)
|
86 | 87 | )
|
87 | 88 | return
|
88 | 89 |
|
| 90 | +auth_dependency = Depends(authenticate) if RUNNING_PROD else None |
| 91 | + |
89 | 92 |
|
90 | 93 | def get_ai_project(request: Request) -> AIProjectClient:
|
91 | 94 | return request.app.state.ai_project
|
@@ -190,7 +193,7 @@ async def on_run_step(self, step: RunStep) -> Optional[str]:
|
190 | 193 | return None
|
191 | 194 |
|
192 | 195 | @router.get("/", response_class=HTMLResponse)
|
193 |
| -async def index(request: Request, _ = Depends(authenticate)): |
| 196 | +async def index(request: Request, _ = auth_dependency): |
194 | 197 | return templates.TemplateResponse(
|
195 | 198 | "index.html",
|
196 | 199 | {
|
@@ -236,7 +239,7 @@ async def history(
|
236 | 239 | request: Request,
|
237 | 240 | ai_project : AIProjectClient = Depends(get_ai_project),
|
238 | 241 | agent : Agent = Depends(get_agent),
|
239 |
| - _ = Depends(authenticate) |
| 242 | + _ = auth_dependency |
240 | 243 | ):
|
241 | 244 | with tracer.start_as_current_span("chat_history"):
|
242 | 245 | # Retrieve the thread ID from the cookies (if available).
|
@@ -295,7 +298,7 @@ async def chat(
|
295 | 298 | agent : Agent = Depends(get_agent),
|
296 | 299 | ai_project: AIProjectClient = Depends(get_ai_project),
|
297 | 300 | app_insights_conn_str : str = Depends(get_app_insights_conn_str),
|
298 |
| - _ = Depends(authenticate) |
| 301 | + _ = auth_dependency |
299 | 302 | ):
|
300 | 303 | # Retrieve the thread ID from the cookies (if available).
|
301 | 304 | thread_id = request.cookies.get('thread_id')
|
|
0 commit comments