refactored the credential checking logic into a shared helper function to reduce code duplication
This commit is contained in:
@@ -232,6 +232,19 @@ def load_client_secrets(client_secrets_path: str) -> Dict[str, Any]:
|
||||
except (IOError, json.JSONDecodeError) as e:
|
||||
logger.error(f"Error loading client secrets file {client_secrets_path}: {e}")
|
||||
raise
|
||||
def check_client_secrets() -> Optional[str]:
|
||||
"""
|
||||
Checks for the presence of OAuth client secrets, either as environment
|
||||
variables or as a file.
|
||||
|
||||
Returns:
|
||||
An error message string if secrets are not found, otherwise None.
|
||||
"""
|
||||
env_config = load_client_secrets_from_env()
|
||||
if not env_config and not os.path.exists(CONFIG_CLIENT_SECRETS_PATH):
|
||||
logger.error(f"OAuth client credentials not found. No environment variables set and no file at {CONFIG_CLIENT_SECRETS_PATH}")
|
||||
return "OAuth client credentials not found. Please set GOOGLE_OAUTH_CLIENT_ID and GOOGLE_OAUTH_CLIENT_SECRET environment variables or provide client_secret.json file."
|
||||
return None
|
||||
|
||||
def create_oauth_flow(scopes: List[str], redirect_uri: str, state: Optional[str] = None) -> Flow:
|
||||
"""Creates an OAuth flow using environment variables or client secrets file."""
|
||||
|
||||
Reference in New Issue
Block a user