changeset 3959:da0e772881c3

cli (pubsub): new `signature` subcommands: A first `check` command can be used to check signature using the signature JSON data. More commands should follow to check or sign items. rel 381
author Goffi <goffi@goffi.org>
date Fri, 28 Oct 2022 18:47:17 +0200
parents e2a5f2f5e57b
children 4836b81c5f31
files sat_frontends/jp/cmd_pubsub.py
diffstat 1 files changed, 47 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_pubsub.py	Fri Oct 28 18:47:17 2022 +0200
+++ b/sat_frontends/jp/cmd_pubsub.py	Fri Oct 28 18:47:17 2022 +0200
@@ -1681,6 +1681,52 @@
             self.host.quit()
 
 
+class SignatureCheck(base.CommandBase):
+    def __init__(self, host):
+        super().__init__(
+            host,
+            "check",
+            use_output=C.OUTPUT_DICT,
+            use_pubsub=True,
+            pubsub_flags={C.SERVICE, C.NODE, C.SINGLE_ITEM},
+            help=_("check the validity of pubsub signature"),
+        )
+
+    def add_parser_options(self):
+        self.parser.add_argument(
+            "signature",
+            metavar="JSON",
+            help=_("signature data")
+        )
+
+    async def start(self):
+        try:
+            ret_s = await self.host.bridge.psSignatureCheck(
+                self.args.service,
+                self.args.node,
+                self.args.item,
+                self.args.signature,
+                self.profile,
+            )
+        except Exception as e:
+            self.disp(f"can't check signature: {e}", error=True)
+            self.host.quit(C.EXIT_BRIDGE_ERRBACK)
+        else:
+            await self.output(data_format.deserialise((ret_s)))
+            self.host.quit()
+
+
+class Signature(base.CommandBase):
+    subcommands = (
+        SignatureCheck,
+    )
+
+    def __init__(self, host):
+        super().__init__(
+            host, "signature", use_profile=False, help=_("item signature")
+        )
+
+
 class Search(base.CommandBase):
     """This command do a search without using MAM
 
@@ -2898,6 +2944,7 @@
         Subscriptions,
         Affiliations,
         Reference,
+        Signature,
         Search,
         Transform,
         Attachments,