cli (pubsub/get): add --no-decrypt flag to disable automatic decryption:

rel 380
This commit is contained in:
Goffi 2022-10-15 20:37:00 +02:00
commit f99544e881
2 changed files with 28 additions and 11 deletions

View file

@ -34,7 +34,7 @@ import tty
import termios
from pathlib import Path
from glob import iglob
from typing import Optional, Set
from typing import Optional, Set, Union
from importlib import import_module
from sat_frontends.tools.jid import JID
from sat.tools import config
@ -979,26 +979,35 @@ class LiberviaCli:
return full_jid.rsplit("/", 1)[0]
class CommandBase(object):
class CommandBase:
def __init__(self, host, name, use_profile=True, use_output=False, extra_outputs=None,
need_connect=None, help=None, **kwargs):
def __init__(
self,
host: LiberviaCli,
name: str,
use_profile: bool = True,
use_output: Union[bool, str] = False,
extra_outputs: Optional[dict] = None,
need_connect: Optional[bool] = None,
help: Optional[str] = None,
**kwargs
):
"""Initialise CommandBase
@param host: Jp instance
@param name(unicode): name of the new command
@param use_profile(bool): if True, add profile selection/connection commands
@param use_output(bool, unicode): if not False, add --output option
@param extra_outputs(dict): list of command specific outputs:
@param name: name of the new command
@param use_profile: if True, add profile selection/connection commands
@param use_output: if not False, add --output option
@param extra_outputs: list of command specific outputs:
key is output name ("default" to use as main output)
value is a callable which will format the output (data will be used as only
argument)
if a key already exists with normal outputs, the extra one will be used
@param need_connect(bool, None): True if profile connection is needed
@param need_connect: True if profile connection is needed
False else (profile session must still be started)
None to set auto value (i.e. True if use_profile is set)
Can't be set if use_profile is False
@param help(unicode): help message to display
@param help: help message to display
@param **kwargs: args passed to ArgumentParser
use_* are handled directly, they can be:
- use_progress(bool): if True, add progress bar activation option

View file

@ -1281,9 +1281,17 @@ class Get(base.CommandBase):
default="",
help=_("subscription id"),
)
self.parser.add_argument(
"--no-decrypt",
action="store_true",
help=_("don't do automatic decryption of e2ee items"),
)
#  TODO: a key(s) argument to select keys to display
async def start(self):
extra = {}
if self.args.no_decrypt:
extra["decrypt"] = False
try:
ps_result = data_format.deserialise(
await self.host.bridge.psItemsGet(
@ -1292,7 +1300,7 @@ class Get(base.CommandBase):
self.args.max,
self.args.items,
self.args.sub_id,
self.getPubsubExtra(),
self.getPubsubExtra(extra),
self.profile,
)
)