From bc81e687274f68c7e3e757036fb03a1cbe910b32 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Thu, 23 Jul 2020 17:45:58 +0200 Subject: [PATCH] api: each API defines its 'endpoint' name Add a new abstract class property to `BaseAPI` called `endpoint`, meant to be implemented by deriving classes in order to identify the end point name for the API provider. Implement the new property in all existing API providers. --- osbuild/api.py | 9 +++++++++ osbuild/remoteloop.py | 2 ++ osbuild/sources.py | 3 +++ test/mod/test_api.py | 2 ++ 4 files changed, 16 insertions(+) diff --git a/osbuild/api.py b/osbuild/api.py index 99e43ab3..cb48af19 100644 --- a/osbuild/api.py +++ b/osbuild/api.py @@ -36,6 +36,12 @@ class BaseAPI(abc.ABC): self.event_loop = None self.thread = None + @property + @classmethod + @abc.abstractmethod + def endpoint(cls): + """The name of the API endpoint""" + @abc.abstractmethod def _dispatch(self, server): """Called for incoming messages on the socket""" @@ -78,6 +84,9 @@ class BaseAPI(abc.ABC): class API(BaseAPI): """The main OSBuild API""" + + endpoint = "osbuild" + def __init__(self, socket_address, args, monitor): super().__init__(socket_address) self.input = args diff --git a/osbuild/remoteloop.py b/osbuild/remoteloop.py index 742cb25b..e77dfb4d 100644 --- a/osbuild/remoteloop.py +++ b/osbuild/remoteloop.py @@ -35,6 +35,8 @@ class LoopServer(api.BaseAPI): object. """ + endpoint = "remoteloop" + def __init__(self, socket_address): super().__init__(socket_address) self.devs = [] diff --git a/osbuild/sources.py b/osbuild/sources.py index 4934fa80..fe0a4462 100644 --- a/osbuild/sources.py +++ b/osbuild/sources.py @@ -5,6 +5,9 @@ from .util import jsoncomm class SourcesServer(api.BaseAPI): + + endpoint = "sources" + def __init__(self, socket_address, libdir, options, cache, output): super().__init__(socket_address) self.libdir = libdir diff --git a/test/mod/test_api.py b/test/mod/test_api.py index d46e7736..02475351 100644 --- a/test/mod/test_api.py +++ b/test/mod/test_api.py @@ -17,6 +17,8 @@ class APITester(osbuild.api.BaseAPI): self.clean = False self.messages = 0 + endpoint = "test-api" + def _dispatch(self, server): msg, _, addr = server.recv() self.messages += 1