Skip to content

Commit 9b1c763

Browse files
authored
Merge pull request #187 from datakind/develop
feat: custom job add feature
2 parents ffbddcd + ddca88a commit 9b1c763

File tree

3 files changed

+558
-433
lines changed

3 files changed

+558
-433
lines changed

src/webapp/main.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""Main file for the SST API."""
22

33
import logging
4-
from typing import Any, Annotated
4+
from typing import Any, Annotated, Optional, cast
55
from datetime import timedelta
66
import secrets
77
from fastapi import FastAPI, Depends, HTTPException, status, Security
88
from fastapi.responses import FileResponse
99
from pydantic import BaseModel
1010
from sqlalchemy.future import select
1111
from sqlalchemy import update
12-
from .routers import models, users, data, institutions
12+
from .routers import models, users, data, institutions, front_end_tables
1313
from .database import (
1414
setup_db,
1515
db_engine,
@@ -58,6 +58,7 @@
5858
app.include_router(models.router)
5959
app.include_router(users.router)
6060
app.include_router(data.router)
61+
app.include_router(front_end_tables.router)
6162

6263

6364
class SelfInfo(BaseModel):
@@ -95,7 +96,9 @@ def read_root() -> Any:
9596
@app.post("/token-from-api-key")
9697
async def access_token_from_api_key(
9798
sql_session: Annotated[Session, Depends(get_session)],
98-
api_key_enduser_tuple: str = Security(get_api_key),
99+
api_key_enduser_tuple: tuple[str, Optional[str], Optional[str]] = Security(
100+
get_api_key
101+
),
99102
) -> Token:
100103
"""Generate a token from an API key."""
101104
local_session.set(sql_session)
@@ -110,10 +113,11 @@ async def access_token_from_api_key(
110113
)
111114

112115
access_token_expires = timedelta(
113-
minutes=int(env_vars["ACCESS_TOKEN_EXPIRE_MINUTES"])
116+
minutes=int(cast(str, env_vars["ACCESS_TOKEN_EXPIRE_MINUTES"]))
114117
)
115118
access_token = create_access_token(
116-
data={"sub": user.email}, expires_delta=access_token_expires
119+
data={"sub": user.email}, # type: ignore
120+
expires_delta=access_token_expires, # type: ignore
117121
)
118122
return Token(access_token=access_token, token_type="bearer")
119123

@@ -122,7 +126,7 @@ async def access_token_from_api_key(
122126
async def read_cross_inst_users(
123127
current_user: Annotated[BaseUser, Depends(get_current_active_user)],
124128
sql_session: Annotated[Session, Depends(get_session)],
125-
):
129+
) -> Any:
126130
"""Get users that don't have institution specifications.
127131
(datakinders or people who haven't set their institution yet)."""
128132
if not current_user.is_datakinder():
@@ -140,7 +144,7 @@ async def read_cross_inst_users(
140144
)
141145
.all()
142146
)
143-
res = []
147+
res: list = []
144148
if not query_result or len(query_result) == 0:
145149
return res
146150

@@ -186,7 +190,7 @@ async def set_datakinders(
186190
.all()
187191
)
188192

189-
res = []
193+
res: list = []
190194
if not query_result:
191195
return res
192196
for elem in query_result:
@@ -251,7 +255,7 @@ async def generate_api_key(
251255
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
252256
detail="Database write of the API key duplicate entries.",
253257
)
254-
return {
258+
return { # type: ignore
255259
"access_type": query_result[0][0].access_type,
256260
"key": generated_key_value,
257261
"inst_id": (

0 commit comments

Comments
 (0)