Mercurial > libervia-backend
changeset 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 (2022-10-29) |
parents | 0f858aa0b92c |
children | 9f85369294f3 |
files | sat_frontends/jp/cmd_pubsub.py |
diffstat | 1 files changed, 100 insertions(+), 84 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ -1230,6 +1230,12 @@ help=_("end-to-end encrypt the blog item") ) self.parser.add_argument( + "-X", + "--sign", + action="store_true", + help=_("cryptographically sign the blog post") + ) + self.parser.add_argument( "item", nargs="?", default="", @@ -1243,6 +1249,8 @@ extra = {} if self.args.encrypt: extra["encrypted"] = True + if self.args.sign: + extra["signed"] = True publish_options = NodeCreate.get_config_options(self.args) if publish_options: extra["publish_options"] = publish_options @@ -1395,11 +1403,19 @@ action="store_true", help=_("end-to-end encrypt the blog item") ) + self.parser.add_argument( + "-X", + "--sign", + action="store_true", + help=_("cryptographically sign the blog post") + ) async def publish(self, content): extra = {} if self.args.encrypt: extra["encrypted"] = True + if self.args.sign: + extra["signed"] = True published_id = await self.host.bridge.psItemSend( self.pubsub_service, self.pubsub_node, @@ -1681,89 +1697,6 @@ 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__( - 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 = ( - SignatureSign, - 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 @@ -2662,6 +2595,89 @@ ) +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__( + 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 = ( + SignatureSign, + SignatureCheck, + ) + + def __init__(self, host): + super().__init__( + host, "signature", use_profile=False, help=_("items signatures") + ) + + class SecretShare(base.CommandBase): def __init__(self, host): super().__init__( @@ -2981,10 +2997,10 @@ Subscriptions, Affiliations, Reference, - Signature, Search, Transform, Attachments, + Signature, Secret, Hook, Uri,