diff --git a/platformio/home/rpc/handlers/registry.py b/platformio/home/rpc/handlers/registry.py new file mode 100644 index 00000000..a6d5b8bf --- /dev/null +++ b/platformio/home/rpc/handlers/registry.py @@ -0,0 +1,29 @@ +# Copyright (c) 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ajsonrpc.core import JSONRPC20DispatchException + +from platformio.registry.client import RegistryClient + + +class RegistryRPC: + @staticmethod + def call_client(method, *args, **kwargs): + try: + client = RegistryClient() + return getattr(client, method)(*args, **kwargs) + except Exception as exc: # pylint: disable=bare-except + raise JSONRPC20DispatchException( + code=4003, message="Registry Call Error", data=str(exc) + ) from exc diff --git a/platformio/home/run.py b/platformio/home/run.py index a5306ad0..25f1081e 100644 --- a/platformio/home/run.py +++ b/platformio/home/run.py @@ -33,6 +33,7 @@ from platformio.home.rpc.handlers.misc import MiscRPC from platformio.home.rpc.handlers.os import OSRPC from platformio.home.rpc.handlers.piocore import PIOCoreRPC from platformio.home.rpc.handlers.project import ProjectRPC +from platformio.home.rpc.handlers.registry import RegistryRPC from platformio.home.rpc.server import WebSocketJSONRPCServerFactory from platformio.package.manager.core import get_core_package_dir from platformio.proc import force_exit @@ -72,6 +73,7 @@ def run_server(host, port, no_open, shutdown_timeout, home_url): ws_rpc_factory.add_object_handler(OSRPC(), namespace="os") ws_rpc_factory.add_object_handler(PIOCoreRPC(), namespace="core") ws_rpc_factory.add_object_handler(ProjectRPC(), namespace="project") + ws_rpc_factory.add_object_handler(RegistryRPC(), namespace="registry") path = urlparse(home_url).path routes = [