cli (pubsub/signature): add sign command:

this command can be used to sign any pubsub item.

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

View file

@ -1681,6 +1681,42 @@ 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__(
@ -1718,6 +1754,7 @@ class SignatureCheck(base.CommandBase):
class Signature(base.CommandBase):
subcommands = (
SignatureSign,
SignatureCheck,
)
@ -2574,7 +2611,7 @@ class AttachmentSet(base.CommandBase):
)
async def start(self):
mb_data = {
attachments_data = {
"service": self.args.service,
"node": self.args.node,
"id": self.args.item,
@ -2584,10 +2621,10 @@ class AttachmentSet(base.CommandBase):
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 @@ class AttachmentSet(base.CommandBase):
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: