# HG changeset patch # User Goffi # Date 1667084818 -7200 # Node ID 0f858aa0b92c9feacc7b9fdbc1c1e302219492bf # Parent d105ead599b60ff063891c7bd76e45d9ac472bc1 cli (pubsub/signature): add `sign` command: this command can be used to sign any pubsub item. rel 381 diff -r d105ead599b6 -r 0f858aa0b92c sat_frontends/jp/cmd_pubsub.py --- a/sat_frontends/jp/cmd_pubsub.py Sun Oct 30 01:06:58 2022 +0200 +++ b/sat_frontends/jp/cmd_pubsub.py Sun Oct 30 01:06:58 2022 +0200 @@ -1681,6 +1681,42 @@ 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 Signature(base.CommandBase): subcommands = ( + SignatureSign, SignatureCheck, ) @@ -2574,7 +2611,7 @@ ) async def start(self): - mb_data = { + attachments_data = { "service": self.args.service, "node": self.args.node, "id": self.args.item, @@ -2584,10 +2621,10 @@ 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 @@ 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: