api: add 'get-arguments' call and client method
Add a new `get-arguments` API call to fetch the input/arguments. To avoid running into any limitings on maximum package size on the socket, the actual data is written to a temp file and a fd to that passed to the client - very much as in `setup_stdio`. Additionally, new `arguments` method is provided as a client counterpart for the new API call.
This commit is contained in:
parent
d26cffe585
commit
e273dd0084
1 changed files with 21 additions and 0 deletions
|
|
@ -191,11 +191,19 @@ class API(BaseAPI):
|
|||
def _set_metadata(self, message):
|
||||
self.metadata.update(message["metadata"])
|
||||
|
||||
def _get_arguments(self, sock):
|
||||
with self._prepare_input() as data:
|
||||
fds = []
|
||||
fds.append(data.fileno())
|
||||
sock.send({"type": "fd", "fd": 0}, fds=fds)
|
||||
|
||||
def _message(self, msg, fds, sock):
|
||||
if msg["method"] == 'setup-stdio':
|
||||
self._setup_stdio(sock)
|
||||
elif msg["method"] == 'add-metadata':
|
||||
self._set_metadata(msg)
|
||||
elif msg["method"] == 'get-arguments':
|
||||
self._get_arguments(sock)
|
||||
|
||||
def _cleanup(self):
|
||||
if self._output_pipe:
|
||||
|
|
@ -203,6 +211,19 @@ class API(BaseAPI):
|
|||
self._output_pipe = None
|
||||
|
||||
|
||||
def arguments(path="/run/osbuild/api/osbuild"):
|
||||
"""Retrieve the input arguments that were supplied to API"""
|
||||
with jsoncomm.Socket.new_client(path) as client:
|
||||
req = {"method": "get-arguments"}
|
||||
client.send(req)
|
||||
msg, fds, _ = client.recv()
|
||||
assert msg["type"] == "fd"
|
||||
fd = msg["fd"]
|
||||
with os.fdopen(fds.steal(fd), encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
return data
|
||||
|
||||
|
||||
def setup_stdio(path="/run/osbuild/api/osbuild"):
|
||||
"""Replace standard i/o with the ones provided by the API"""
|
||||
with jsoncomm.Socket.new_client(path) as client:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue