api: add support for metadata
Add support for setting metadata via `osbuild.API`. It is meant to be used by modules (stages, assemblers) to pass additional data that belong to the result back to osbuild. For this, a new api method `set-metadata` can be used to set and update a metadata dictionary on the `osbuild.API` class. A client side method `metadata` is provided to do so.
This commit is contained in:
parent
939a83926e
commit
fb3a0c5982
1 changed files with 16 additions and 0 deletions
|
|
@ -137,6 +137,7 @@ class API(BaseAPI):
|
|||
self._output_data = io.StringIO()
|
||||
self._output_pipe = None
|
||||
self.monitor = monitor
|
||||
self.metadata = {}
|
||||
|
||||
@property
|
||||
def output(self):
|
||||
|
|
@ -176,9 +177,14 @@ class API(BaseAPI):
|
|||
|
||||
server.send(msg, fds=fds)
|
||||
|
||||
def _set_metadata(self, message):
|
||||
self.metadata.update(message["metadata"])
|
||||
|
||||
def _message(self, msg, fds, sock):
|
||||
if msg["method"] == 'setup-stdio':
|
||||
self._setup_stdio(sock)
|
||||
elif msg["method"] == 'add-metadata':
|
||||
self._set_metadata(msg)
|
||||
|
||||
def _cleanup(self):
|
||||
if self._output_pipe:
|
||||
|
|
@ -197,3 +203,13 @@ def setup_stdio(path="/run/osbuild/api/osbuild"):
|
|||
source = fds[msg[sio]]
|
||||
os.dup2(source, target.fileno())
|
||||
fds.close()
|
||||
|
||||
|
||||
def metadata(data: Dict, path="/run/osbuild/api/osbuild"):
|
||||
"""Update metadata for the current module"""
|
||||
with jsoncomm.Socket.new_client(path) as client:
|
||||
msg = {
|
||||
"method": "add-metadata",
|
||||
"metadata": data
|
||||
}
|
||||
client.send(msg)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue