comparison sat_frontends/jp/cmd_pubsub.py @ 3964:0f858aa0b92c

cli (pubsub/signature): add `sign` command: this command can be used to sign any pubsub item. rel 381
author Goffi <goffi@goffi.org>
date Sun, 30 Oct 2022 01:06:58 +0200
parents da0e772881c3
children 2695dafc5c4d
comparison
equal deleted inserted replaced
3963:d105ead599b6 3964:0f858aa0b92c
1679 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 1679 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
1680 else: 1680 else:
1681 self.host.quit() 1681 self.host.quit()
1682 1682
1683 1683
1684 class SignatureSign(base.CommandBase):
1685 def __init__(self, host):
1686 super().__init__(
1687 host,
1688 "sign",
1689 use_pubsub=True,
1690 pubsub_flags={C.NODE, C.SINGLE_ITEM},
1691 help=_("sign an item"),
1692 )
1693
1694 def add_parser_options(self):
1695 pass
1696
1697 async def start(self):
1698 attachments_data = {
1699 "service": self.args.service,
1700 "node": self.args.node,
1701 "id": self.args.item,
1702 "extra": {
1703 # we set None to use profile's bare JID
1704 "signature": {"signer": None}
1705 }
1706 }
1707 try:
1708 await self.host.bridge.psAttachmentsSet(
1709 data_format.serialise(attachments_data),
1710 self.profile,
1711 )
1712 except Exception as e:
1713 self.disp(f"can't sign the item: {e}", error=True)
1714 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
1715 else:
1716 self.disp(f"item {self.args.item!r} has been signed")
1717 self.host.quit(C.EXIT_OK)
1718
1719
1684 class SignatureCheck(base.CommandBase): 1720 class SignatureCheck(base.CommandBase):
1685 def __init__(self, host): 1721 def __init__(self, host):
1686 super().__init__( 1722 super().__init__(
1687 host, 1723 host,
1688 "check", 1724 "check",
1716 self.host.quit() 1752 self.host.quit()
1717 1753
1718 1754
1719 class Signature(base.CommandBase): 1755 class Signature(base.CommandBase):
1720 subcommands = ( 1756 subcommands = (
1757 SignatureSign,
1721 SignatureCheck, 1758 SignatureCheck,
1722 ) 1759 )
1723 1760
1724 def __init__(self, host): 1761 def __init__(self, host):
1725 super().__init__( 1762 super().__init__(
2572 action="append", 2609 action="append",
2573 help=_("emojis to remove from reactions to an item") 2610 help=_("emojis to remove from reactions to an item")
2574 ) 2611 )
2575 2612
2576 async def start(self): 2613 async def start(self):
2577 mb_data = { 2614 attachments_data = {
2578 "service": self.args.service, 2615 "service": self.args.service,
2579 "node": self.args.node, 2616 "node": self.args.node,
2580 "id": self.args.item, 2617 "id": self.args.item,
2581 "extra": {} 2618 "extra": {}
2582 } 2619 }
2583 operation = "replace" if self.args.replace else "update" 2620 operation = "replace" if self.args.replace else "update"
2584 if self.args.noticed != "keep": 2621 if self.args.noticed != "keep":
2585 if self.args.noticed is None: 2622 if self.args.noticed is None:
2586 self.args.noticed = C.BOOL_TRUE 2623 self.args.noticed = C.BOOL_TRUE
2587 mb_data["extra"]["noticed"] = C.bool(self.args.noticed) 2624 attachments_data["extra"]["noticed"] = C.bool(self.args.noticed)
2588 2625
2589 if self.args.reactions or self.args.reactions_remove: 2626 if self.args.reactions or self.args.reactions_remove:
2590 reactions = mb_data["extra"]["reactions"] = { 2627 reactions = attachments_data["extra"]["reactions"] = {
2591 "operation": operation 2628 "operation": operation
2592 } 2629 }
2593 if self.args.replace: 2630 if self.args.replace:
2594 reactions["reactions"] = self.args.reactions 2631 reactions["reactions"] = self.args.reactions
2595 else: 2632 else:
2596 reactions["add"] = self.args.reactions 2633 reactions["add"] = self.args.reactions
2597 reactions["remove"] = self.args.reactions_remove 2634 reactions["remove"] = self.args.reactions_remove
2598 2635
2599 2636
2600 if not mb_data["extra"]: 2637 if not attachments_data["extra"]:
2601 self.parser.error(_("At leat one attachment must be specified.")) 2638 self.parser.error(_("At leat one attachment must be specified."))
2602 2639
2603 try: 2640 try:
2604 await self.host.bridge.psAttachmentsSet( 2641 await self.host.bridge.psAttachmentsSet(
2605 data_format.serialise(mb_data), 2642 data_format.serialise(attachments_data),
2606 self.profile, 2643 self.profile,
2607 ) 2644 )
2608 except Exception as e: 2645 except Exception as e:
2609 self.disp(f"can't attach data to item: {e}", error=True) 2646 self.disp(f"can't attach data to item: {e}", error=True)
2610 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 2647 self.host.quit(C.EXIT_BRIDGE_ERRBACK)