@@ -372,59 +372,14 @@ async def _discover_credential_files(self):
372372 old_files = set (self ._credential_files )
373373 all_files = []
374374
375- # First, check environment variables for credentials
376- env_creds_loaded = False
377- for i in range (1 , 11 ): # Support up to 10 credentials from env vars
378- env_var_name = f"GOOGLE_CREDENTIALS_{ i } " if i > 1 else "GOOGLE_CREDENTIALS"
379- env_creds = os .getenv (env_var_name )
380-
381- if env_creds :
382- try :
383- # Try to decode if it's base64 encoded
384- try :
385- # Check if it's base64 encoded
386- decoded = base64 .b64decode (env_creds )
387- env_creds = decoded .decode ('utf-8' )
388- log .debug (f"Decoded base64 credential from { env_var_name } " )
389- except :
390- # Not base64, use as is
391- pass
392-
393- # Parse the JSON credential from environment variable
394- cred_data = json .loads (env_creds )
395-
396- # Auto-add 'type' field if missing but has required OAuth fields
397- if 'type' not in cred_data and all (key in cred_data for key in ['client_id' , 'refresh_token' ]):
398- cred_data ['type' ] = 'authorized_user'
399- log .debug (f"Auto-added 'type' field to credential from { env_var_name } " )
400-
401- if all (key in cred_data for key in ['type' , 'client_id' , 'refresh_token' ]):
402- # Save to a temporary file for compatibility with existing code
403- temp_file = os .path .join (CREDENTIALS_DIR , f"env_credential_{ i } .json" )
404- os .makedirs (CREDENTIALS_DIR , exist_ok = True )
405- with open (temp_file , 'w' ) as f :
406- json .dump (cred_data , f )
407- all_files .append (temp_file )
408- log .info (f"Loaded credential from environment variable: { env_var_name } " )
409- env_creds_loaded = True
410- else :
411- log .warning (f"Invalid credential format in { env_var_name } " )
412- except json .JSONDecodeError as e :
413- log .warning (f"Failed to parse JSON from { env_var_name } : { e } " )
414- except Exception as e :
415- log .warning (f"Error loading credential from { env_var_name } : { e } " )
375+ # Discover from directory
376+ credentials_dir = CREDENTIALS_DIR
377+ patterns = [os .path .join (credentials_dir , "*.json" )]
416378
417- # If no env credentials, discover from directory
418- if not env_creds_loaded :
419- credentials_dir = CREDENTIALS_DIR
420- patterns = [os .path .join (credentials_dir , "*.json" )]
421-
422- for pattern in patterns :
423- discovered_files = glob .glob (pattern )
424- # Skip env_credential files if loading from directory
425- for file in discovered_files :
426- if not os .path .basename (file ).startswith ("env_credential_" ):
427- all_files .append (file )
379+ for pattern in patterns :
380+ discovered_files = glob .glob (pattern )
381+ for file in discovered_files :
382+ all_files .append (file )
428383
429384 all_files = sorted (list (set (all_files )))
430385
@@ -547,32 +502,6 @@ async def _discover_credential_files_unlocked(self):
547502 from config import CREDENTIALS_DIR
548503 import glob
549504
550- # 检查环境变量凭证(与 _discover_credential_files 保持一致)
551- for i in range (1 , 11 ):
552- env_var_name = f"GOOGLE_CREDENTIALS_{ i } " if i > 1 else "GOOGLE_CREDENTIALS"
553- env_creds = os .getenv (env_var_name )
554-
555- if env_creds :
556- try :
557- # 检查是否为base64编码
558- try :
559- import base64
560- decoded = base64 .b64decode (env_creds )
561- env_creds = decoded .decode ('utf-8' )
562- except :
563- pass
564-
565- # 验证JSON格式
566- import json
567- json .loads (env_creds )
568-
569- # 创建临时文件路径标识
570- temp_env_path = f"<ENV_{ env_var_name } >"
571- if not self .is_cred_disabled (temp_env_path ):
572- temp_files .append (temp_env_path )
573-
574- except (json .JSONDecodeError , UnicodeDecodeError ) as e :
575- log .error (f"Invalid JSON in { env_var_name } : { e } " )
576505
577506 # 检查文件系统中的凭证
578507 if os .path .exists (CREDENTIALS_DIR ):
0 commit comments