keyring lazy load so non-blocking
This commit is contained in:
+16
-1
@@ -75,8 +75,9 @@ class DropboxAuthManager:
|
||||
self.refresh_token = None
|
||||
|
||||
# Try to load from keyring only if no credentials provided
|
||||
# Skip during initialization to avoid blocking startup - will load lazily when needed
|
||||
if app_key is None or app_secret is None:
|
||||
self._try_load_from_keyring()
|
||||
pass # Load lazily in is_connected() or when actually needed
|
||||
|
||||
def _ensure_keyring_setup(self):
|
||||
"""Set up keyring backend only when needed (lazy initialization)"""
|
||||
@@ -89,17 +90,31 @@ class DropboxAuthManager:
|
||||
"""Try to load credentials from keyring, but don't block if unavailable"""
|
||||
try:
|
||||
if self._ensure_keyring_setup():
|
||||
original_app_key = self.app_key
|
||||
original_app_secret = self.app_secret
|
||||
original_refresh_token = self.refresh_token
|
||||
|
||||
if self.app_key is None:
|
||||
self.app_key = keyring.get_password(DROPBOX_KEYRING_SERVICE, "app_key")
|
||||
if self.app_secret is None:
|
||||
self.app_secret = keyring.get_password(DROPBOX_KEYRING_SERVICE, "app_secret")
|
||||
if self.refresh_token is None:
|
||||
self.refresh_token = keyring.get_password(DROPBOX_KEYRING_SERVICE, "refresh_token")
|
||||
|
||||
# Debug: Show what was loaded
|
||||
print(f"[DropboxAuthManager] Keyring load results:")
|
||||
print(f" app_key: {original_app_key} -> {self.app_key}")
|
||||
print(f" app_secret: {original_app_secret} -> {self.app_secret}")
|
||||
print(f" refresh_token: {original_refresh_token} -> {bool(self.refresh_token)}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"[DropboxAuthManager] Could not load from keyring: {e}")
|
||||
# Don't fail - just continue without keyring credentials
|
||||
|
||||
def is_connected(self):
|
||||
# Load from keyring lazily if we don't have credentials yet
|
||||
if not (self.app_key and self.app_secret and self.refresh_token):
|
||||
self._try_load_from_keyring()
|
||||
return bool(self.app_key and self.app_secret and self.refresh_token)
|
||||
|
||||
def store_tokens(self, app_key, app_secret, refresh_token):
|
||||
|
||||
+10
-4
@@ -15,16 +15,22 @@ class DropboxSetupNode:
|
||||
def INPUT_TYPES(cls):
|
||||
# Check if credentials are already stored (keyring or .env file)
|
||||
try:
|
||||
print(f"[DropboxSetup] INPUT_TYPES: Creating DropboxAuthManager for connection check...")
|
||||
auth_manager = DropboxAuthManager()
|
||||
is_connected = auth_manager.is_connected()
|
||||
|
||||
print(f"[DropboxSetup] INPUT_TYPES connection check results:")
|
||||
print(f" is_connected: {is_connected}")
|
||||
print(f" app_key present: {bool(auth_manager.app_key)}")
|
||||
print(f" app_secret present: {bool(auth_manager.app_secret)}")
|
||||
print(f" refresh_token present: {bool(auth_manager.refresh_token)}")
|
||||
|
||||
# Check keyring availability for smart defaults (non-blocking)
|
||||
keyring_available = True # Assume available until proven otherwise
|
||||
try:
|
||||
# Only test keyring if we need to know for sure
|
||||
keyring_available = auth_manager._ensure_keyring_setup()
|
||||
if not keyring_available:
|
||||
print(f"[DropboxSetup] Keyring not available in this environment")
|
||||
# Skip keyring testing during INPUT_TYPES - just assume it works for UI defaults
|
||||
# We'll test it properly when actually needed during setup()
|
||||
pass
|
||||
except Exception as e:
|
||||
print(f"[DropboxSetup] Keyring test failed: {e}")
|
||||
keyring_available = False
|
||||
|
||||
Reference in New Issue
Block a user