cli (pubsub/set,edit) add --sign argument:

`signature` subcommands have also been moved just before `secret` subcommands.

rel 381
This commit is contained in:
Goffi 2022-10-30 01:06:58 +02:00
commit 2f94daec1a

View file

@ -1229,6 +1229,12 @@ class Set(base.CommandBase):
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")
)
self.parser.add_argument(
"item",
nargs="?",
@ -1243,6 +1249,8 @@ class Set(base.CommandBase):
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 @@ class Edit(base.CommandBase, common.BaseEdit):
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 @@ 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__(
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 Attachments(base.CommandBase):
)
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 @@ class Pubsub(base.CommandBase):
Subscriptions,
Affiliations,
Reference,
Signature,
Search,
Transform,
Attachments,
Signature,
Secret,
Hook,
Uri,