dynamic scope awareness
This commit is contained in:
@@ -8,6 +8,9 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Global variable to store enabled tools (set by main.py)
|
||||
_ENABLED_TOOLS = None
|
||||
|
||||
# Individual OAuth Scope Constants
|
||||
USERINFO_EMAIL_SCOPE = 'https://www.googleapis.com/auth/userinfo.email'
|
||||
USERINFO_PROFILE_SCOPE = 'https://www.googleapis.com/auth/userinfo.profile'
|
||||
@@ -121,5 +124,80 @@ CUSTOM_SEARCH_SCOPES = [
|
||||
CUSTOM_SEARCH_SCOPE
|
||||
]
|
||||
|
||||
# Combined scopes for all supported Google Workspace operations
|
||||
SCOPES = list(set(BASE_SCOPES + CALENDAR_SCOPES + DRIVE_SCOPES + GMAIL_SCOPES + DOCS_SCOPES + CHAT_SCOPES + SHEETS_SCOPES + FORMS_SCOPES + SLIDES_SCOPES + TASKS_SCOPES + CUSTOM_SEARCH_SCOPES))
|
||||
# Tool-to-scopes mapping
|
||||
TOOL_SCOPES_MAP = {
|
||||
'gmail': GMAIL_SCOPES,
|
||||
'drive': DRIVE_SCOPES,
|
||||
'calendar': CALENDAR_SCOPES,
|
||||
'docs': DOCS_SCOPES,
|
||||
'sheets': SHEETS_SCOPES,
|
||||
'chat': CHAT_SCOPES,
|
||||
'forms': FORMS_SCOPES,
|
||||
'slides': SLIDES_SCOPES,
|
||||
'tasks': TASKS_SCOPES,
|
||||
'search': CUSTOM_SEARCH_SCOPES
|
||||
}
|
||||
|
||||
def set_enabled_tools(enabled_tools):
|
||||
"""
|
||||
Set the globally enabled tools list.
|
||||
|
||||
Args:
|
||||
enabled_tools: List of enabled tool names.
|
||||
"""
|
||||
global _ENABLED_TOOLS
|
||||
_ENABLED_TOOLS = enabled_tools
|
||||
logger.info(f"Enabled tools set for scope management: {enabled_tools}")
|
||||
|
||||
def get_current_scopes():
|
||||
"""
|
||||
Returns scopes for currently enabled tools.
|
||||
Uses globally set enabled tools or all tools if not set.
|
||||
|
||||
Returns:
|
||||
List of unique scopes for the enabled tools plus base scopes.
|
||||
"""
|
||||
enabled_tools = _ENABLED_TOOLS
|
||||
if enabled_tools is None:
|
||||
# Default behavior - return all scopes
|
||||
enabled_tools = TOOL_SCOPES_MAP.keys()
|
||||
|
||||
# Start with base scopes (always required)
|
||||
scopes = BASE_SCOPES.copy()
|
||||
|
||||
# Add scopes for each enabled tool
|
||||
for tool in enabled_tools:
|
||||
if tool in TOOL_SCOPES_MAP:
|
||||
scopes.extend(TOOL_SCOPES_MAP[tool])
|
||||
|
||||
logger.debug(f"Generated scopes for tools {list(enabled_tools)}: {len(set(scopes))} unique scopes")
|
||||
# Return unique scopes
|
||||
return list(set(scopes))
|
||||
|
||||
def get_scopes_for_tools(enabled_tools=None):
|
||||
"""
|
||||
Returns scopes for enabled tools only.
|
||||
|
||||
Args:
|
||||
enabled_tools: List of enabled tool names. If None, returns all scopes.
|
||||
|
||||
Returns:
|
||||
List of unique scopes for the enabled tools plus base scopes.
|
||||
"""
|
||||
if enabled_tools is None:
|
||||
# Default behavior - return all scopes
|
||||
enabled_tools = TOOL_SCOPES_MAP.keys()
|
||||
|
||||
# Start with base scopes (always required)
|
||||
scopes = BASE_SCOPES.copy()
|
||||
|
||||
# Add scopes for each enabled tool
|
||||
for tool in enabled_tools:
|
||||
if tool in TOOL_SCOPES_MAP:
|
||||
scopes.extend(TOOL_SCOPES_MAP[tool])
|
||||
|
||||
# Return unique scopes
|
||||
return list(set(scopes))
|
||||
|
||||
# Combined scopes for all supported Google Workspace operations (backwards compatibility)
|
||||
SCOPES = get_scopes_for_tools()
|
||||
Reference in New Issue
Block a user