@@ -37,21 +37,21 @@ def api_auth(
37
37
db : Session ,
38
38
) -> ApiClient :
39
39
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
0 commit comments