diff --git a/sat_frontends/jp/cmd_pubsub.py b/sat_frontends/jp/cmd_pubsub.py index 07e60a8e..ceec74e6 100644 --- a/sat_frontends/jp/cmd_pubsub.py +++ b/sat_frontends/jp/cmd_pubsub.py @@ -1681,6 +1681,42 @@ class Reference(base.CommandBase): self.host.quit() +class SignatureSign(base.CommandBase): + def __init__(self, host): + super().__init__( + host, + "sign", + use_pubsub=True, + pubsub_flags={C.NODE, C.SINGLE_ITEM}, + help=_("sign an item"), + ) + + def add_parser_options(self): + pass + + async def start(self): + attachments_data = { + "service": self.args.service, + "node": self.args.node, + "id": self.args.item, + "extra": { + # we set None to use profile's bare JID + "signature": {"signer": None} + } + } + try: + await self.host.bridge.psAttachmentsSet( + data_format.serialise(attachments_data), + self.profile, + ) + except Exception as e: + self.disp(f"can't sign the item: {e}", error=True) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) + else: + self.disp(f"item {self.args.item!r} has been signed") + self.host.quit(C.EXIT_OK) + + class SignatureCheck(base.CommandBase): def __init__(self, host): super().__init__( @@ -1718,6 +1754,7 @@ class SignatureCheck(base.CommandBase): class Signature(base.CommandBase): subcommands = ( + SignatureSign, SignatureCheck, ) @@ -2574,7 +2611,7 @@ class AttachmentSet(base.CommandBase): ) async def start(self): - mb_data = { + attachments_data = { "service": self.args.service, "node": self.args.node, "id": self.args.item, @@ -2584,10 +2621,10 @@ class AttachmentSet(base.CommandBase): if self.args.noticed != "keep": if self.args.noticed is None: self.args.noticed = C.BOOL_TRUE - mb_data["extra"]["noticed"] = C.bool(self.args.noticed) + attachments_data["extra"]["noticed"] = C.bool(self.args.noticed) if self.args.reactions or self.args.reactions_remove: - reactions = mb_data["extra"]["reactions"] = { + reactions = attachments_data["extra"]["reactions"] = { "operation": operation } if self.args.replace: @@ -2597,12 +2634,12 @@ class AttachmentSet(base.CommandBase): reactions["remove"] = self.args.reactions_remove - if not mb_data["extra"]: + if not attachments_data["extra"]: self.parser.error(_("At leat one attachment must be specified.")) try: await self.host.bridge.psAttachmentsSet( - data_format.serialise(mb_data), + data_format.serialise(attachments_data), self.profile, ) except Exception as e: