π OpenHands: AI-Driven Development
Fix git secrets (#8258)
Robert Brennana9f44b0ca583
diff --git a/openhands/server/config/server_config.py b/openhands/server/config/server_config.pyindex 7dbcaf8235..9dbf83c93f 100644--- a/openhands/server/config/server_config.py+++ b/openhands/server/config/server_config.py@@ -16,7 +16,7 @@ class ServerConfig(ServerConfigInterface):'openhands.storage.settings.file_settings_store.FileSettingsStore')secret_store_class: str = (- 'openhands.storage.settings.file_secrets_store.FileSecretsStore'+ 'openhands.storage.secrets.file_secrets_store.FileSecretsStore')conversation_store_class: str = ('openhands.storage.conversation.file_conversation_store.FileConversationStore'diff --git a/openhands/server/routes/secrets.py b/openhands/server/routes/secrets.pyindex e4fb07f746..20df522d5f 100644--- a/openhands/server/routes/secrets.py+++ b/openhands/server/routes/secrets.py@@ -14,7 +14,7 @@ from openhands.server.user_auth import ()from openhands.storage.data_models.settings import Settingsfrom openhands.storage.data_models.user_secrets import UserSecrets-from openhands.storage.settings.secret_store import SecretsStore+from openhands.storage.secrets.secrets_store import SecretsStorefrom openhands.storage.settings.settings_store import SettingsStoreapp = APIRouter(prefix='/api')@@ -78,34 +78,31 @@ async def store_provider_tokens(try:user_secrets = await secrets_store.load()+ if not user_secrets:+ user_secrets = UserSecrets()- if user_secrets:- if provider_info.provider_tokens:- existing_providers = [- provider for provider in user_secrets.provider_tokens- ]-- # Merge incoming settings store with the existing one- for provider, token_value in list(- provider_info.provider_tokens.items()- ):- if provider in existing_providers and not token_value.token:- existing_token = user_secrets.provider_tokens.get(provider)- if existing_token and existing_token.token:- provider_info.provider_tokens[provider] = existing_token-- else: # nothing passed in means keep current settings- provider_info.provider_tokens = dict(user_secrets.provider_tokens)-- updated_secrets = user_secrets.model_copy(- update={'provider_tokens': provider_info.provider_tokens}- )- await secrets_store.store(updated_secrets)+ if provider_info.provider_tokens:+ existing_providers = [provider for provider in user_secrets.provider_tokens]- return JSONResponse(- status_code=status.HTTP_200_OK,- content={'message': 'Git providers stored'},- )+ # Merge incoming settings store with the existing one+ for provider, token_value in list(provider_info.provider_tokens.items()):+ if provider in existing_providers and not token_value.token:+ existing_token = user_secrets.provider_tokens.get(provider)+ if existing_token and existing_token.token:+ provider_info.provider_tokens[provider] = existing_token++ else: # nothing passed in means keep current settings+ provider_info.provider_tokens = dict(user_secrets.provider_tokens)++ updated_secrets = user_secrets.model_copy(+ update={'provider_tokens': provider_info.provider_tokens}+ )+ await secrets_store.store(updated_secrets)++ return JSONResponse(+ status_code=status.HTTP_200_OK,+ content={'message': 'Git providers stored'},+ )except Exception as e:logger.warning(f'Something went wrong storing git providers: {e}')return JSONResponse(diff --git a/openhands/server/routes/settings.py b/openhands/server/routes/settings.pyindex f1ce9ded84..0418be060c 100644--- a/openhands/server/routes/settings.py+++ b/openhands/server/routes/settings.py@@ -17,7 +17,7 @@ from openhands.server.user_auth import (get_user_settings_store,)from openhands.storage.data_models.settings import Settings-from openhands.storage.settings.secret_store import SecretsStore+from openhands.storage.secrets.secrets_store import SecretsStorefrom openhands.storage.settings.settings_store import SettingsStoreapp = APIRouter(prefix='/api')diff --git a/openhands/server/shared.py b/openhands/server/shared.pyindex 9e7b4be326..454bd95de1 100644--- a/openhands/server/shared.py+++ b/openhands/server/shared.py@@ -11,7 +11,7 @@ from openhands.server.conversation_manager.conversation_manager import (from openhands.server.monitoring import MonitoringListenerfrom openhands.storage import get_file_storefrom openhands.storage.conversation.conversation_store import ConversationStore-from openhands.storage.settings.secret_store import SecretsStore+from openhands.storage.secrets.secrets_store import SecretsStorefrom openhands.storage.settings.settings_store import SettingsStorefrom openhands.utils.import_utils import get_impldiff --git a/openhands/server/user_auth/__init__.py b/openhands/server/user_auth/__init__.pyindex 2ca913bc32..fd51cd5660 100644--- a/openhands/server/user_auth/__init__.py+++ b/openhands/server/user_auth/__init__.py@@ -6,7 +6,7 @@ from openhands.integrations.service_types import ProviderTypefrom openhands.server.settings import Settingsfrom openhands.server.user_auth.user_auth import AuthType, get_user_authfrom openhands.storage.data_models.user_secrets import UserSecrets-from openhands.storage.settings.secret_store import SecretsStore+from openhands.storage.secrets.secrets_store import SecretsStorefrom openhands.storage.settings.settings_store import SettingsStorediff --git a/openhands/server/user_auth/default_user_auth.py b/openhands/server/user_auth/default_user_auth.pyindex 600b953aac..d2472e110d 100644--- a/openhands/server/user_auth/default_user_auth.py+++ b/openhands/server/user_auth/default_user_auth.py@@ -8,7 +8,7 @@ from openhands.server import sharedfrom openhands.server.settings import Settingsfrom openhands.server.user_auth.user_auth import UserAuthfrom openhands.storage.data_models.user_secrets import UserSecrets-from openhands.storage.settings.secret_store import SecretsStore+from openhands.storage.secrets.secrets_store import SecretsStorefrom openhands.storage.settings.settings_store import SettingsStorediff --git a/openhands/server/user_auth/user_auth.py b/openhands/server/user_auth/user_auth.pyindex a0ff8f7230..6ba1e7adff 100644--- a/openhands/server/user_auth/user_auth.py+++ b/openhands/server/user_auth/user_auth.py@@ -10,7 +10,7 @@ from openhands.integrations.provider import PROVIDER_TOKEN_TYPEfrom openhands.server.settings import Settingsfrom openhands.server.shared import server_configfrom openhands.storage.data_models.user_secrets import UserSecrets-from openhands.storage.settings.secret_store import SecretsStore+from openhands.storage.secrets.secrets_store import SecretsStorefrom openhands.storage.settings.settings_store import SettingsStorefrom openhands.utils.import_utils import get_impldiff --git a/openhands/storage/settings/file_secrets_store.py b/openhands/storage/secrets/file_secrets_store.pysimilarity index 95%rename from openhands/storage/settings/file_secrets_store.pyrename to openhands/storage/secrets/file_secrets_store.pyindex 00b4c8e911..12b5d16d04 100644--- a/openhands/storage/settings/file_secrets_store.py+++ b/openhands/storage/secrets/file_secrets_store.py@@ -7,7 +7,7 @@ from openhands.core.config.app_config import AppConfigfrom openhands.storage import get_file_storefrom openhands.storage.data_models.user_secrets import UserSecretsfrom openhands.storage.files import FileStore-from openhands.storage.settings.secret_store import SecretsStore+from openhands.storage.secrets.secrets_store import SecretsStorefrom openhands.utils.async_utils import call_sync_from_asyncdiff --git a/openhands/storage/settings/secret_store.py b/openhands/storage/secrets/secrets_store.pysimilarity index 100%rename from openhands/storage/settings/secret_store.pyrename to openhands/storage/secrets/secrets_store.pydiff --git a/tests/unit/test_secrets_api.py b/tests/unit/test_secrets_api.pyindex cd49a82b3b..ded24d3209 100644--- a/tests/unit/test_secrets_api.py+++ b/tests/unit/test_secrets_api.py@@ -12,7 +12,7 @@ from openhands.integrations.provider import ProviderToken, ProviderTypefrom openhands.server.routes.secrets import app as secrets_appfrom openhands.storage import get_file_storefrom openhands.storage.data_models.user_secrets import UserSecrets-from openhands.storage.settings.file_secrets_store import FileSecretsStore+from openhands.storage.secrets.file_secrets_store import FileSecretsStore@pytest.fixture@@ -33,7 +33,7 @@ def file_secrets_store(temp_dir):file_store = get_file_store('local', temp_dir)store = FileSecretsStore(file_store)with patch(- 'openhands.storage.settings.file_secrets_store.FileSecretsStore.get_instance',+ 'openhands.storage.secrets.file_secrets_store.FileSecretsStore.get_instance',AsyncMock(return_value=store),):yield storediff --git a/tests/unit/test_settings_api.py b/tests/unit/test_settings_api.pyindex 399cf9ea37..ff4953e47f 100644--- a/tests/unit/test_settings_api.py+++ b/tests/unit/test_settings_api.py@@ -10,8 +10,8 @@ from openhands.server.app import appfrom openhands.server.user_auth.user_auth import UserAuthfrom openhands.storage.data_models.user_secrets import UserSecretsfrom openhands.storage.memory import InMemoryFileStore+from openhands.storage.secrets.secrets_store import SecretsStorefrom openhands.storage.settings.file_settings_store import FileSettingsStore-from openhands.storage.settings.secret_store import SecretsStorefrom openhands.storage.settings.settings_store import SettingsStorediff --git a/tests/unit/test_settings_store_functions.py b/tests/unit/test_settings_store_functions.pyindex 256339b124..959466e30e 100644--- a/tests/unit/test_settings_store_functions.py+++ b/tests/unit/test_settings_store_functions.py@@ -15,7 +15,7 @@ from openhands.server.settings import POSTProviderModelfrom openhands.storage import get_file_storefrom openhands.storage.data_models.settings import Settingsfrom openhands.storage.data_models.user_secrets import UserSecrets-from openhands.storage.settings.file_secrets_store import FileSecretsStore+from openhands.storage.secrets.file_secrets_store import FileSecretsStore# Mock functions to simulate the actual functions in settings.py@@ -47,7 +47,7 @@ def file_secrets_store(temp_dir):file_store = get_file_store('local', temp_dir)store = FileSecretsStore(file_store)with patch(- 'openhands.storage.settings.file_secrets_store.FileSecretsStore.get_instance',+ 'openhands.storage.secrets.file_secrets_store.FileSecretsStore.get_instance',AsyncMock(return_value=store),):yield store