Loading src/rpc/methods.py +21 −0 Original line number Diff line number Diff line Loading @@ -94,6 +94,13 @@ from django.db.models import BinaryField, Count, Q logger = logging.getLogger(__name__) _CLIENT_CONFIGURATION_SETTINGS = ( "JAMA_RPC_MAX_BODY_SIZE", "JAMA_RPC_MAX_BATCH_SIZE", "JAMA_UPLOAD_MAX_CHUNK_SIZE", "JAMA_UPLOAD_MAX_TOTAL_CHUNKS", ) def _deskew( image_path: str, max_skew: int = 10, fast: bool = True, scale_max: int = 1000 Loading Loading @@ -328,6 +335,20 @@ def ping(user: User) -> str: return "pong {}".format(user.username) @_rpc_groups(["Utilities"]) def client_configuration(user: User) -> Dict[str, int]: """ Get the server limits that RPC clients need to construct valid requests. Only explicitly allowlisted settings are returned. Server credentials and other internal configuration are never exposed. """ return { setting_name: getattr(settings, setting_name) for setting_name in _CLIENT_CONFIGURATION_SETTINGS } @_rpc_groups(["Metadatas"]) def metadatasets(user: User, project_id: int) -> List[Dict]: """ Loading src/rpc/tests.py +24 −0 Original line number Diff line number Diff line Loading @@ -111,6 +111,30 @@ class ServiceTestCase(TestCase): methods.ping(self.test_user), "pong {}".format(self.test_user.username) ) def test_client_configuration_returns_only_allowlisted_settings(self): configured_values = { "JAMA_RPC_MAX_BODY_SIZE": 101, "JAMA_RPC_MAX_BATCH_SIZE": 102, "JAMA_UPLOAD_MAX_CHUNK_SIZE": 103, "JAMA_UPLOAD_MAX_TOTAL_CHUNKS": 104, } with ( patch.multiple(methods.settings, **configured_values), patch.object(methods.settings, "SECRET_KEY", "do-not-expose"), patch.object( methods.settings, "JAMA_DB_PASSWORD", "do-not-expose", create=True, ), ): result = methods.client_configuration(self.test_user) self.assertEqual(result, configured_values) self.assertNotIn("SECRET_KEY", result) self.assertNotIn("JAMA_DB_PASSWORD", result) def test_get_user_from_request_uses_hashed_api_key(self): request = self.factory.get("/rpc/", HTTP_X_API_KEY=self.basic_user_key) request.user = AnonymousUser() Loading Loading
src/rpc/methods.py +21 −0 Original line number Diff line number Diff line Loading @@ -94,6 +94,13 @@ from django.db.models import BinaryField, Count, Q logger = logging.getLogger(__name__) _CLIENT_CONFIGURATION_SETTINGS = ( "JAMA_RPC_MAX_BODY_SIZE", "JAMA_RPC_MAX_BATCH_SIZE", "JAMA_UPLOAD_MAX_CHUNK_SIZE", "JAMA_UPLOAD_MAX_TOTAL_CHUNKS", ) def _deskew( image_path: str, max_skew: int = 10, fast: bool = True, scale_max: int = 1000 Loading Loading @@ -328,6 +335,20 @@ def ping(user: User) -> str: return "pong {}".format(user.username) @_rpc_groups(["Utilities"]) def client_configuration(user: User) -> Dict[str, int]: """ Get the server limits that RPC clients need to construct valid requests. Only explicitly allowlisted settings are returned. Server credentials and other internal configuration are never exposed. """ return { setting_name: getattr(settings, setting_name) for setting_name in _CLIENT_CONFIGURATION_SETTINGS } @_rpc_groups(["Metadatas"]) def metadatasets(user: User, project_id: int) -> List[Dict]: """ Loading
src/rpc/tests.py +24 −0 Original line number Diff line number Diff line Loading @@ -111,6 +111,30 @@ class ServiceTestCase(TestCase): methods.ping(self.test_user), "pong {}".format(self.test_user.username) ) def test_client_configuration_returns_only_allowlisted_settings(self): configured_values = { "JAMA_RPC_MAX_BODY_SIZE": 101, "JAMA_RPC_MAX_BATCH_SIZE": 102, "JAMA_UPLOAD_MAX_CHUNK_SIZE": 103, "JAMA_UPLOAD_MAX_TOTAL_CHUNKS": 104, } with ( patch.multiple(methods.settings, **configured_values), patch.object(methods.settings, "SECRET_KEY", "do-not-expose"), patch.object( methods.settings, "JAMA_DB_PASSWORD", "do-not-expose", create=True, ), ): result = methods.client_configuration(self.test_user) self.assertEqual(result, configured_values) self.assertNotIn("SECRET_KEY", result) self.assertNotIn("JAMA_DB_PASSWORD", result) def test_get_user_from_request_uses_hashed_api_key(self): request = self.factory.get("/rpc/", HTTP_X_API_KEY=self.basic_user_key) request.user = AnonymousUser() Loading