Mercurial > libervia-backend
comparison sat_frontends/jp/cmd_pubsub.py @ 3965:2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
`signature` subcommands have also been moved just before `secret` subcommands.
rel 381
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 30 Oct 2022 01:06:58 +0200 |
parents | 0f858aa0b92c |
children | 570254d5a798 |
comparison
equal
deleted
inserted
replaced
3964:0f858aa0b92c | 3965:2695dafc5c4d |
---|---|
1228 "--encrypt", | 1228 "--encrypt", |
1229 action="store_true", | 1229 action="store_true", |
1230 help=_("end-to-end encrypt the blog item") | 1230 help=_("end-to-end encrypt the blog item") |
1231 ) | 1231 ) |
1232 self.parser.add_argument( | 1232 self.parser.add_argument( |
1233 "-X", | |
1234 "--sign", | |
1235 action="store_true", | |
1236 help=_("cryptographically sign the blog post") | |
1237 ) | |
1238 self.parser.add_argument( | |
1233 "item", | 1239 "item", |
1234 nargs="?", | 1240 nargs="?", |
1235 default="", | 1241 default="", |
1236 help=_("id, URL of the item to update, keyword, or nothing for new item"), | 1242 help=_("id, URL of the item to update, keyword, or nothing for new item"), |
1237 ) | 1243 ) |
1241 element = xml_tools.getPayload(self, element) | 1247 element = xml_tools.getPayload(self, element) |
1242 payload = etree.tostring(element, encoding="unicode") | 1248 payload = etree.tostring(element, encoding="unicode") |
1243 extra = {} | 1249 extra = {} |
1244 if self.args.encrypt: | 1250 if self.args.encrypt: |
1245 extra["encrypted"] = True | 1251 extra["encrypted"] = True |
1252 if self.args.sign: | |
1253 extra["signed"] = True | |
1246 publish_options = NodeCreate.get_config_options(self.args) | 1254 publish_options = NodeCreate.get_config_options(self.args) |
1247 if publish_options: | 1255 if publish_options: |
1248 extra["publish_options"] = publish_options | 1256 extra["publish_options"] = publish_options |
1249 | 1257 |
1250 try: | 1258 try: |
1393 "-e", | 1401 "-e", |
1394 "--encrypt", | 1402 "--encrypt", |
1395 action="store_true", | 1403 action="store_true", |
1396 help=_("end-to-end encrypt the blog item") | 1404 help=_("end-to-end encrypt the blog item") |
1397 ) | 1405 ) |
1406 self.parser.add_argument( | |
1407 "-X", | |
1408 "--sign", | |
1409 action="store_true", | |
1410 help=_("cryptographically sign the blog post") | |
1411 ) | |
1398 | 1412 |
1399 async def publish(self, content): | 1413 async def publish(self, content): |
1400 extra = {} | 1414 extra = {} |
1401 if self.args.encrypt: | 1415 if self.args.encrypt: |
1402 extra["encrypted"] = True | 1416 extra["encrypted"] = True |
1417 if self.args.sign: | |
1418 extra["signed"] = True | |
1403 published_id = await self.host.bridge.psItemSend( | 1419 published_id = await self.host.bridge.psItemSend( |
1404 self.pubsub_service, | 1420 self.pubsub_service, |
1405 self.pubsub_node, | 1421 self.pubsub_node, |
1406 content, | 1422 content, |
1407 self.pubsub_item or "", | 1423 self.pubsub_item or "", |
1677 except Exception as e: | 1693 except Exception as e: |
1678 self.disp(f"can't send reference: {e}", error=True) | 1694 self.disp(f"can't send reference: {e}", error=True) |
1679 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 1695 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
1680 else: | 1696 else: |
1681 self.host.quit() | 1697 self.host.quit() |
1682 | |
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 | |
1720 class SignatureCheck(base.CommandBase): | |
1721 def __init__(self, host): | |
1722 super().__init__( | |
1723 host, | |
1724 "check", | |
1725 use_output=C.OUTPUT_DICT, | |
1726 use_pubsub=True, | |
1727 pubsub_flags={C.SERVICE, C.NODE, C.SINGLE_ITEM}, | |
1728 help=_("check the validity of pubsub signature"), | |
1729 ) | |
1730 | |
1731 def add_parser_options(self): | |
1732 self.parser.add_argument( | |
1733 "signature", | |
1734 metavar="JSON", | |
1735 help=_("signature data") | |
1736 ) | |
1737 | |
1738 async def start(self): | |
1739 try: | |
1740 ret_s = await self.host.bridge.psSignatureCheck( | |
1741 self.args.service, | |
1742 self.args.node, | |
1743 self.args.item, | |
1744 self.args.signature, | |
1745 self.profile, | |
1746 ) | |
1747 except Exception as e: | |
1748 self.disp(f"can't check signature: {e}", error=True) | |
1749 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1750 else: | |
1751 await self.output(data_format.deserialise((ret_s))) | |
1752 self.host.quit() | |
1753 | |
1754 | |
1755 class Signature(base.CommandBase): | |
1756 subcommands = ( | |
1757 SignatureSign, | |
1758 SignatureCheck, | |
1759 ) | |
1760 | |
1761 def __init__(self, host): | |
1762 super().__init__( | |
1763 host, "signature", use_profile=False, help=_("item signature") | |
1764 ) | |
1765 | 1698 |
1766 | 1699 |
1767 class Search(base.CommandBase): | 1700 class Search(base.CommandBase): |
1768 """This command do a search without using MAM | 1701 """This command do a search without using MAM |
1769 | 1702 |
2660 use_profile=False, | 2593 use_profile=False, |
2661 help=_("set or retrieve items attachments"), | 2594 help=_("set or retrieve items attachments"), |
2662 ) | 2595 ) |
2663 | 2596 |
2664 | 2597 |
2598 class SignatureSign(base.CommandBase): | |
2599 def __init__(self, host): | |
2600 super().__init__( | |
2601 host, | |
2602 "sign", | |
2603 use_pubsub=True, | |
2604 pubsub_flags={C.NODE, C.SINGLE_ITEM}, | |
2605 help=_("sign an item"), | |
2606 ) | |
2607 | |
2608 def add_parser_options(self): | |
2609 pass | |
2610 | |
2611 async def start(self): | |
2612 attachments_data = { | |
2613 "service": self.args.service, | |
2614 "node": self.args.node, | |
2615 "id": self.args.item, | |
2616 "extra": { | |
2617 # we set None to use profile's bare JID | |
2618 "signature": {"signer": None} | |
2619 } | |
2620 } | |
2621 try: | |
2622 await self.host.bridge.psAttachmentsSet( | |
2623 data_format.serialise(attachments_data), | |
2624 self.profile, | |
2625 ) | |
2626 except Exception as e: | |
2627 self.disp(f"can't sign the item: {e}", error=True) | |
2628 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2629 else: | |
2630 self.disp(f"item {self.args.item!r} has been signed") | |
2631 self.host.quit(C.EXIT_OK) | |
2632 | |
2633 | |
2634 class SignatureCheck(base.CommandBase): | |
2635 def __init__(self, host): | |
2636 super().__init__( | |
2637 host, | |
2638 "check", | |
2639 use_output=C.OUTPUT_DICT, | |
2640 use_pubsub=True, | |
2641 pubsub_flags={C.SERVICE, C.NODE, C.SINGLE_ITEM}, | |
2642 help=_("check the validity of pubsub signature"), | |
2643 ) | |
2644 | |
2645 def add_parser_options(self): | |
2646 self.parser.add_argument( | |
2647 "signature", | |
2648 metavar="JSON", | |
2649 help=_("signature data") | |
2650 ) | |
2651 | |
2652 async def start(self): | |
2653 try: | |
2654 ret_s = await self.host.bridge.psSignatureCheck( | |
2655 self.args.service, | |
2656 self.args.node, | |
2657 self.args.item, | |
2658 self.args.signature, | |
2659 self.profile, | |
2660 ) | |
2661 except Exception as e: | |
2662 self.disp(f"can't check signature: {e}", error=True) | |
2663 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2664 else: | |
2665 await self.output(data_format.deserialise((ret_s))) | |
2666 self.host.quit() | |
2667 | |
2668 | |
2669 class Signature(base.CommandBase): | |
2670 subcommands = ( | |
2671 SignatureSign, | |
2672 SignatureCheck, | |
2673 ) | |
2674 | |
2675 def __init__(self, host): | |
2676 super().__init__( | |
2677 host, "signature", use_profile=False, help=_("items signatures") | |
2678 ) | |
2679 | |
2680 | |
2665 class SecretShare(base.CommandBase): | 2681 class SecretShare(base.CommandBase): |
2666 def __init__(self, host): | 2682 def __init__(self, host): |
2667 super().__init__( | 2683 super().__init__( |
2668 host, | 2684 host, |
2669 "share", | 2685 "share", |
2979 Subscribe, | 2995 Subscribe, |
2980 Unsubscribe, | 2996 Unsubscribe, |
2981 Subscriptions, | 2997 Subscriptions, |
2982 Affiliations, | 2998 Affiliations, |
2983 Reference, | 2999 Reference, |
2984 Signature, | |
2985 Search, | 3000 Search, |
2986 Transform, | 3001 Transform, |
2987 Attachments, | 3002 Attachments, |
3003 Signature, | |
2988 Secret, | 3004 Secret, |
2989 Hook, | 3005 Hook, |
2990 Uri, | 3006 Uri, |
2991 Node, | 3007 Node, |
2992 Cache, | 3008 Cache, |