whitespace
This commit is contained in:
@@ -238,14 +238,14 @@ async def get_authenticated_google_service_oauth21(
|
||||
def _extract_oauth21_user_email(authenticated_user: Optional[str], func_name: str) -> str:
|
||||
"""
|
||||
Extract user email for OAuth 2.1 mode.
|
||||
|
||||
|
||||
Args:
|
||||
authenticated_user: The authenticated user from context
|
||||
func_name: Name of the function being decorated (for error messages)
|
||||
|
||||
|
||||
Returns:
|
||||
User email string
|
||||
|
||||
|
||||
Raises:
|
||||
Exception: If no authenticated user found in OAuth 2.1 mode
|
||||
"""
|
||||
@@ -257,27 +257,27 @@ def _extract_oauth21_user_email(authenticated_user: Optional[str], func_name: st
|
||||
|
||||
|
||||
def _extract_oauth20_user_email(
|
||||
args: tuple,
|
||||
kwargs: dict,
|
||||
args: tuple,
|
||||
kwargs: dict,
|
||||
wrapper_sig: inspect.Signature
|
||||
) -> str:
|
||||
"""
|
||||
Extract user email for OAuth 2.0 mode from function arguments.
|
||||
|
||||
|
||||
Args:
|
||||
args: Positional arguments passed to wrapper
|
||||
kwargs: Keyword arguments passed to wrapper
|
||||
wrapper_sig: Function signature for parameter binding
|
||||
|
||||
|
||||
Returns:
|
||||
User email string
|
||||
|
||||
|
||||
Raises:
|
||||
Exception: If user_google_email parameter not found
|
||||
"""
|
||||
bound_args = wrapper_sig.bind(*args, **kwargs)
|
||||
bound_args.apply_defaults()
|
||||
|
||||
|
||||
user_google_email = bound_args.arguments.get("user_google_email")
|
||||
if not user_google_email:
|
||||
raise Exception(
|
||||
@@ -476,7 +476,7 @@ def require_google_service(
|
||||
if is_oauth21_enabled():
|
||||
# Remove both 'service' and 'user_google_email' parameters
|
||||
filtered_params = [
|
||||
p for p in params[1:]
|
||||
p for p in params[1:]
|
||||
if p.name != 'user_google_email'
|
||||
]
|
||||
wrapper_sig = original_sig.replace(parameters=filtered_params)
|
||||
@@ -493,7 +493,7 @@ def require_google_service(
|
||||
authenticated_user, auth_method, mcp_session_id = _get_auth_context(
|
||||
func.__name__
|
||||
)
|
||||
|
||||
|
||||
# Extract user_google_email based on OAuth mode
|
||||
if is_oauth21_enabled():
|
||||
user_google_email = _extract_oauth21_user_email(authenticated_user, func.__name__)
|
||||
@@ -562,7 +562,7 @@ def require_google_service(
|
||||
# In OAuth 2.1 mode, we need to add user_google_email to kwargs since it was removed from signature
|
||||
if is_oauth21_enabled():
|
||||
kwargs["user_google_email"] = user_google_email
|
||||
|
||||
|
||||
# Prepend the fetched service object to the original arguments
|
||||
return await func(service, *args, **kwargs)
|
||||
except RefreshError as e:
|
||||
@@ -607,24 +607,24 @@ def require_multiple_services(service_configs: List[Dict[str, Any]]):
|
||||
|
||||
def decorator(func: Callable) -> Callable:
|
||||
original_sig = inspect.signature(func)
|
||||
|
||||
|
||||
# In OAuth 2.1 mode, remove user_google_email from the signature
|
||||
if is_oauth21_enabled():
|
||||
params = list(original_sig.parameters.values())
|
||||
filtered_params = [
|
||||
p for p in params
|
||||
p for p in params
|
||||
if p.name != 'user_google_email'
|
||||
]
|
||||
wrapper_sig = original_sig.replace(parameters=filtered_params)
|
||||
else:
|
||||
wrapper_sig = original_sig
|
||||
|
||||
|
||||
@wraps(func)
|
||||
async def wrapper(*args, **kwargs):
|
||||
# Get authentication context early
|
||||
tool_name = func.__name__
|
||||
authenticated_user, _, mcp_session_id = _get_auth_context(tool_name)
|
||||
|
||||
|
||||
# Extract user_google_email based on OAuth mode
|
||||
if is_oauth21_enabled():
|
||||
user_google_email = _extract_oauth21_user_email(authenticated_user, tool_name)
|
||||
@@ -707,7 +707,7 @@ def require_multiple_services(service_configs: List[Dict[str, Any]]):
|
||||
# In OAuth 2.1 mode, we need to add user_google_email to kwargs since it was removed from signature
|
||||
if is_oauth21_enabled():
|
||||
kwargs["user_google_email"] = user_google_email
|
||||
|
||||
|
||||
return await func(*args, **kwargs)
|
||||
except RefreshError as e:
|
||||
# Handle token refresh errors gracefully
|
||||
@@ -718,13 +718,13 @@ def require_multiple_services(service_configs: List[Dict[str, Any]]):
|
||||
|
||||
# Set the wrapper's signature
|
||||
wrapper.__signature__ = wrapper_sig
|
||||
|
||||
|
||||
# Conditionally modify docstring to remove user_google_email parameter documentation
|
||||
if is_oauth21_enabled():
|
||||
logger.debug('OAuth 2.1 mode enabled, removing user_google_email from docstring')
|
||||
if func.__doc__:
|
||||
wrapper.__doc__ = _remove_user_email_arg_from_docstring(func.__doc__)
|
||||
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
Reference in New Issue
Block a user