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.
This commit is contained in:
Christian Kellner 2020-07-23 17:45:58 +02:00 committed by Tom Gundersen
parent 144019a40c
commit bc81e68727
4 changed files with 16 additions and 0 deletions

View file

@ -36,6 +36,12 @@ class BaseAPI(abc.ABC):
self.event_loop = None self.event_loop = None
self.thread = None self.thread = None
@property
@classmethod
@abc.abstractmethod
def endpoint(cls):
"""The name of the API endpoint"""
@abc.abstractmethod @abc.abstractmethod
def _dispatch(self, server): def _dispatch(self, server):
"""Called for incoming messages on the socket""" """Called for incoming messages on the socket"""
@ -78,6 +84,9 @@ class BaseAPI(abc.ABC):
class API(BaseAPI): class API(BaseAPI):
"""The main OSBuild API""" """The main OSBuild API"""
endpoint = "osbuild"
def __init__(self, socket_address, args, monitor): def __init__(self, socket_address, args, monitor):
super().__init__(socket_address) super().__init__(socket_address)
self.input = args self.input = args

View file

@ -35,6 +35,8 @@ class LoopServer(api.BaseAPI):
object. object.
""" """
endpoint = "remoteloop"
def __init__(self, socket_address): def __init__(self, socket_address):
super().__init__(socket_address) super().__init__(socket_address)
self.devs = [] self.devs = []

View file

@ -5,6 +5,9 @@ from .util import jsoncomm
class SourcesServer(api.BaseAPI): class SourcesServer(api.BaseAPI):
endpoint = "sources"
def __init__(self, socket_address, libdir, options, cache, output): def __init__(self, socket_address, libdir, options, cache, output):
super().__init__(socket_address) super().__init__(socket_address)
self.libdir = libdir self.libdir = libdir

View file

@ -17,6 +17,8 @@ class APITester(osbuild.api.BaseAPI):
self.clean = False self.clean = False
self.messages = 0 self.messages = 0
endpoint = "test-api"
def _dispatch(self, server): def _dispatch(self, server):
msg, _, addr = server.recv() msg, _, addr = server.recv()
self.messages += 1 self.messages += 1