Skip to content

Commit 703c112

Browse files
committedDec 25, 2022
re-introduced ALLOW_ANY_API_KEY
1 parent 21f44d2 commit 703c112

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed
 

‎ansible/dev.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
network_mode: oasst
5151
env:
5252
POSTGRES_HOST: oasst-postgres
53-
DEBUG_SKIP_API_KEY_CHECK: "true"
53+
DEBUG_ALLOW_ANY_API_KEY: "true"
5454
MAX_WORKERS: "1"
5555
ports:
5656
- 8080:8080

‎backend/oasst_backend/api/deps.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ def api_auth(
3737
db: Session,
3838
) -> ApiClient:
3939

40-
if api_key is not None or settings.DEBUG_SKIP_API_KEY_CHECK:
41-
if settings.DEBUG_SKIP_API_KEY_CHECK:
42-
# make sure that a dummy api key exits in db (foreign key references)
43-
ANY_API_KEY_ID = UUID("00000000-1111-2222-3333-444444444444")
44-
api_client: ApiClient = db.query(ApiClient).filter(ApiClient.id == ANY_API_KEY_ID).first()
45-
if api_client is None:
46-
token = token_hex(32)
47-
logger.info(f"ANY_API_KEY missing, inserting api_key: {token}")
48-
api_client = ApiClient(id=ANY_API_KEY_ID, api_key=token, description="ANY_API_KEY, random token")
49-
db.add(api_client)
50-
db.commit()
51-
return api_client
52-
53-
api_client = db.query(ApiClient).filter(ApiClient.api_key == api_key).first()
54-
if api_client is not None and api_client.enabled:
55-
return api_client
56-
57-
raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Could not validate credentials")
40+
if api_key is None and not settings.DEBUG_SKIP_API_KEY_CHECK:
41+
raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Could not validate credentials")
42+
43+
if settings.DEBUG_SKIP_API_KEY_CHECK or settings.DEBUG_ALLOW_ANY_API_KEY:
44+
# make sure that a dummy api key exits in db (foreign key references)
45+
ANY_API_KEY_ID = UUID("00000000-1111-2222-3333-444444444444")
46+
api_client: ApiClient = db.query(ApiClient).filter(ApiClient.id == ANY_API_KEY_ID).first()
47+
if api_client is None:
48+
token = token_hex(32)
49+
logger.info(f"ANY_API_KEY missing, inserting api_key: {token}")
50+
api_client = ApiClient(id=ANY_API_KEY_ID, api_key=token, description="ANY_API_KEY, random token")
51+
db.add(api_client)
52+
db.commit()
53+
return api_client
54+
55+
api_client = db.query(ApiClient).filter(ApiClient.api_key == api_key).first()
56+
if api_client is not None and api_client.enabled:
57+
return api_client

‎backend/oasst_backend/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Settings(BaseSettings):
1515
POSTGRES_DB: str = "postgres"
1616
DATABASE_URI: Optional[PostgresDsn] = None
1717

18+
DEBUG_ALLOW_ANY_API_KEY: bool = False
1819
DEBUG_SKIP_API_KEY_CHECK: bool = False
1920

2021
@validator("DATABASE_URI", pre=True)

0 commit comments

Comments
 (0)
Please sign in to comment.