api: remove 'addr' param from message dispatcher
Now that jsoncomm is using a connection oriented protocol, the `addr` parameter is not needed[*] and can thus be removed from the `BaseAPI._message` message dispatcher. Adapt all usages of it, including the tests. [*] sendmsg ignores the destination parameter for connection oriented sockets.
This commit is contained in:
parent
abbdf06ba5
commit
8388a64ffa
4 changed files with 13 additions and 13 deletions
|
|
@ -51,7 +51,7 @@ class BaseAPI(abc.ABC):
|
|||
"""The name of the API endpoint"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def _message(self, msg: Dict, fds: jsoncomm.FdSet, sock: jsoncomm.Socket, addr: str):
|
||||
def _message(self, msg: Dict, fds: jsoncomm.FdSet, sock: jsoncomm.Socket):
|
||||
"""Called for a new incoming message
|
||||
|
||||
The file descriptor set `fds` will be closed after the call.
|
||||
|
|
@ -68,12 +68,12 @@ class BaseAPI(abc.ABC):
|
|||
|
||||
def _dispatch(self, sock: jsoncomm.Socket):
|
||||
"""Called when data is available on the socket"""
|
||||
msg, fds, addr = sock.recv()
|
||||
msg, fds, _ = sock.recv()
|
||||
if msg is None:
|
||||
# Peer closed the connection
|
||||
self.event_loop.remove_reader(sock)
|
||||
return
|
||||
self._message(msg, fds, sock, addr)
|
||||
self._message(msg, fds, sock)
|
||||
fds.close()
|
||||
|
||||
def _accept(self, server):
|
||||
|
|
@ -162,7 +162,7 @@ class API(BaseAPI):
|
|||
self._output_data.write(data)
|
||||
self.monitor.log(data)
|
||||
|
||||
def _setup_stdio(self, server, addr):
|
||||
def _setup_stdio(self, server):
|
||||
with self._prepare_input() as stdin, \
|
||||
self._prepare_output() as stdout:
|
||||
msg = {}
|
||||
|
|
@ -174,11 +174,11 @@ class API(BaseAPI):
|
|||
fds.append(stdout.fileno())
|
||||
msg['stderr'] = 2
|
||||
|
||||
server.send(msg, fds=fds, destination=addr)
|
||||
server.send(msg, fds=fds)
|
||||
|
||||
def _message(self, msg, fds, sock, addr):
|
||||
def _message(self, msg, fds, sock):
|
||||
if msg["method"] == 'setup-stdio':
|
||||
self._setup_stdio(sock, addr)
|
||||
self._setup_stdio(sock)
|
||||
|
||||
def _cleanup(self):
|
||||
if self._output_pipe:
|
||||
|
|
|
|||
|
|
@ -70,14 +70,14 @@ class LoopServer(api.BaseAPI):
|
|||
self.devs.append(lo)
|
||||
return lo.devname
|
||||
|
||||
def _message(self, msg, fds, sock, addr):
|
||||
def _message(self, msg, fds, sock):
|
||||
fd = fds[msg["fd"]]
|
||||
dir_fd = fds[msg["dir_fd"]]
|
||||
offset = msg.get("offset")
|
||||
sizelimit = msg.get("sizelimit")
|
||||
|
||||
devname = self._create_device(fd, dir_fd, offset, sizelimit)
|
||||
sock.send({"devname": devname}, destination=addr)
|
||||
sock.send({"devname": devname})
|
||||
|
||||
def _cleanup(self):
|
||||
for lo in self.devs:
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ class SourcesServer(api.BaseAPI):
|
|||
except ValueError:
|
||||
return {"error": f"source returned malformed json: {r.stdout}"}
|
||||
|
||||
def _message(self, msg, fds, sock, addr):
|
||||
def _message(self, msg, fds, sock):
|
||||
reply = self._run_source(msg["source"], msg["checksums"])
|
||||
sock.send(reply, destination=addr)
|
||||
sock.send(reply)
|
||||
|
||||
|
||||
def get(source, checksums, api_path="/run/osbuild/api/sources"):
|
||||
|
|
|
|||
|
|
@ -23,12 +23,12 @@ class APITester(osbuild.api.BaseAPI):
|
|||
|
||||
endpoint = "test-api"
|
||||
|
||||
def _message(self, msg, _fds, sock, addr):
|
||||
def _message(self, msg, _fds, sock):
|
||||
self.messages += 1
|
||||
|
||||
if msg["method"] == "echo":
|
||||
msg["method"] = "reply"
|
||||
sock.send(msg, destination=addr)
|
||||
sock.send(msg)
|
||||
|
||||
def _cleanup(self):
|
||||
self.clean = True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue