|
@@ -5,7 +5,6 @@ import hashlib
|
|
|
import hmac
|
|
|
import inspect
|
|
|
import logging
|
|
|
-import pkgutil
|
|
|
from abc import abstractmethod
|
|
|
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, Sequence
|
|
|
from contextlib import contextmanager
|
|
@@ -68,26 +67,8 @@ class RpcMethodSignature(SerializableFunctionSignature):
|
|
|
self.base_service_cls.__name__, self.base_function.__name__, message
|
|
|
)
|
|
|
|
|
|
- @property
|
|
|
- def service_key(self) -> str:
|
|
|
- return self.base_service_cls.key
|
|
|
-
|
|
|
- @property
|
|
|
- def service_name(self) -> str:
|
|
|
- return self.base_service_cls.__name__
|
|
|
-
|
|
|
- @property
|
|
|
- def method_name(self) -> str:
|
|
|
- return self.base_function.__name__
|
|
|
-
|
|
|
- def __repr__(self) -> str:
|
|
|
- return f"{type(self).__name__}({self.service_name!r}, {self.method_name!r})"
|
|
|
-
|
|
|
- def __str__(self) -> str:
|
|
|
- return f"{self.service_name}.{self.method_name}"
|
|
|
-
|
|
|
def get_name_segments(self) -> Sequence[str]:
|
|
|
- return self.service_name, self.method_name
|
|
|
+ return (self.base_service_cls.__name__, self.base_function.__name__)
|
|
|
|
|
|
def _extract_region_resolution(self) -> RegionResolutionStrategy | None:
|
|
|
region_resolution = getattr(self.base_function, _REGION_RESOLUTION_ATTR, None)
|
|
@@ -142,9 +123,6 @@ class DelegatingRpcService(DelegatedBySiloMode["RpcService"]):
|
|
|
def local_mode(self) -> SiloMode:
|
|
|
return self._base_service_cls.local_mode
|
|
|
|
|
|
- def __repr__(self):
|
|
|
- return f"{type(self).__name__}({self._base_service_cls.__name__})"
|
|
|
-
|
|
|
def deserialize_rpc_arguments(
|
|
|
self, method_name: str, serial_arguments: ArgumentDict
|
|
|
) -> pydantic.BaseModel:
|
|
@@ -155,9 +133,6 @@ class DelegatingRpcService(DelegatedBySiloMode["RpcService"]):
|
|
|
signature = self._signatures[method_name]
|
|
|
return signature.deserialize_return_value(serial_response)
|
|
|
|
|
|
- def get_all_signatures(self) -> Iterable[RpcMethodSignature]:
|
|
|
- return self._signatures.values()
|
|
|
-
|
|
|
|
|
|
def rpc_method(method: Callable[..., _T]) -> Callable[..., _T]:
|
|
|
"""Decorate methods to be exposed as part of the RPC interface.
|
|
@@ -225,7 +200,7 @@ class RpcService(abc.ABC):
|
|
|
raise RpcServiceSetupException(
|
|
|
cls.key, None, "`local_mode` class attribute (SiloMode) is required"
|
|
|
)
|
|
|
- cls._signatures = {sig.method_name: sig for sig in cls._create_signatures()}
|
|
|
+ cls._signatures = cls._create_signatures()
|
|
|
|
|
|
@classmethod
|
|
|
def _get_all_rpc_methods(cls) -> Iterator[Callable[..., Any]]:
|
|
@@ -261,7 +236,8 @@ class RpcService(abc.ABC):
|
|
|
raise NotImplementedError
|
|
|
|
|
|
@classmethod
|
|
|
- def _create_signatures(cls) -> Iterable[RpcMethodSignature]:
|
|
|
+ def _create_signatures(cls) -> Mapping[str, RpcMethodSignature]:
|
|
|
+ model_table = {}
|
|
|
for base_method in cls._get_all_rpc_methods():
|
|
|
try:
|
|
|
signature = RpcMethodSignature(cls, base_method)
|
|
@@ -270,7 +246,8 @@ class RpcService(abc.ABC):
|
|
|
cls.key, base_method.__name__, "Error on parameter model"
|
|
|
) from e
|
|
|
else:
|
|
|
- yield signature
|
|
|
+ model_table[base_method.__name__] = signature
|
|
|
+ return model_table
|
|
|
|
|
|
@classmethod
|
|
|
def _get_and_validate_local_implementation(cls) -> RpcService:
|
|
@@ -373,21 +350,6 @@ class RpcService(abc.ABC):
|
|
|
return service # type: ignore[return-value]
|
|
|
|
|
|
|
|
|
-def list_all_service_method_signatures() -> Iterable[RpcMethodSignature]:
|
|
|
- """List signatures of all RPC methods in the global registry."""
|
|
|
-
|
|
|
- from sentry.services import hybrid_cloud as hybrid_cloud_service_pkg
|
|
|
-
|
|
|
- # Forcibly import all service packages to ensure the global registry is fully populated
|
|
|
- for _, name, _ in pkgutil.walk_packages(
|
|
|
- hybrid_cloud_service_pkg.__path__, prefix=f"{hybrid_cloud_service_pkg.__name__}."
|
|
|
- ):
|
|
|
- __import__(name)
|
|
|
-
|
|
|
- for service_obj in _global_service_registry.values():
|
|
|
- yield from service_obj.get_all_signatures()
|
|
|
-
|
|
|
-
|
|
|
class RpcResolutionException(Exception):
|
|
|
"""Indicate that an RPC service or method name could not be resolved."""
|
|
|
|