Refactor: move helper function to avoid circular imports (#11310)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Rohit Malhotra 2025-10-10 12:40:03 -04:00 committed by GitHub
parent 9bd02440b0
commit c034cc5dfb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 21 additions and 17 deletions

View File

@ -13,7 +13,7 @@ from integrations.solvability.models.report import SolvabilityReport
from integrations.solvability.models.summary import SolvabilitySummary
from integrations.utils import ENABLE_SOLVABILITY_ANALYSIS
from pydantic import ValidationError
from server.auth.token_manager import get_config
from server.config import get_config
from storage.database import session_maker
from storage.saas_settings_store import SaasSettingsStore

View File

@ -19,7 +19,8 @@ from integrations.utils import (
from jinja2 import Environment
from pydantic.dataclasses import dataclass
from server.auth.constants import GITHUB_APP_CLIENT_ID, GITHUB_APP_PRIVATE_KEY
from server.auth.token_manager import TokenManager, get_config
from server.auth.token_manager import TokenManager
from server.config import get_config
from storage.database import session_maker
from storage.proactive_conversation_store import ProactiveConversationStore
from storage.saas_secrets_store import SaasSecretsStore

View File

@ -4,7 +4,8 @@ from integrations.models import Message
from integrations.types import ResolverViewInterface, UserData
from integrations.utils import HOST, get_oh_labels, has_exact_mention
from jinja2 import Environment
from server.auth.token_manager import TokenManager, get_config
from server.auth.token_manager import TokenManager
from server.config import get_config
from storage.database import session_maker
from storage.saas_secrets_store import SaasSecretsStore

View File

@ -13,7 +13,8 @@ from server.auth.auth_error import (
ExpiredError,
NoCredentialsError,
)
from server.auth.token_manager import TokenManager, get_config
from server.auth.token_manager import TokenManager
from server.config import get_config
from server.logger import logger
from server.rate_limit import RateLimiter, create_redis_rate_limiter
from storage.api_key_store import ApiKeyStore

View File

@ -26,6 +26,7 @@ from server.auth.constants import (
KEYCLOAK_SERVER_URL_EXT,
)
from server.auth.keycloak_manager import get_keycloak_admin, get_keycloak_openid
from server.config import get_config
from server.logger import logger
from sqlalchemy import String as SQLString
from sqlalchemy import type_coerce
@ -35,19 +36,8 @@ from storage.github_app_installation import GithubAppInstallation
from storage.offline_token_store import OfflineTokenStore
from tenacity import RetryCallState, retry, retry_if_exception_type, stop_after_attempt
from openhands.core.config import load_openhands_config
from openhands.integrations.service_types import ProviderType
# Create a function to get config to avoid circular imports
_config = None
def get_config():
global _config
if _config is None:
_config = load_openhands_config()
return _config
def _before_sleep_callback(retry_state: RetryCallState) -> None:
logger.info(f'Retry attempt {retry_state.attempt_number} for Keycloak operation')

View File

@ -19,10 +19,21 @@ from server.auth.constants import (
GITLAB_APP_CLIENT_ID,
)
from openhands.core.config.utils import load_openhands_config
from openhands.integrations.service_types import ProviderType
from openhands.server.config.server_config import ServerConfig
from openhands.server.types import AppMode
# Create a function to get config to avoid circular imports
_config = None
def get_config():
global _config
if _config is None:
_config = load_openhands_config()
return _config
def sign_token(payload: dict[str, object], jwt_secret: str, algorithm='HS256') -> str:
"""Signs a JWT token."""

View File

@ -20,7 +20,7 @@ def token_store(session_maker, mock_config):
@pytest.fixture
def token_manager():
with patch('server.auth.token_manager.get_config') as mock_get_config:
with patch('server.config.get_config') as mock_get_config:
mock_config = mock_get_config.return_value
mock_config.jwt_secret.get_secret_value.return_value = 'test_secret'
return TokenManager(external=False)

View File

@ -8,7 +8,7 @@ from openhands.integrations.service_types import ProviderType
@pytest.fixture
def token_manager():
with patch('server.auth.token_manager.get_config') as mock_get_config:
with patch('server.config.get_config') as mock_get_config:
mock_config = mock_get_config.return_value
mock_config.jwt_secret.get_secret_value.return_value = 'test_secret'
return TokenManager(external=False)