changeset 3970:4c3361e2bf55

cli (file/send): add `--encrypt` argument to request encryption: rel 378
author Goffi <goffi@goffi.org>
date Mon, 31 Oct 2022 04:09:38 +0100
parents 8e7d5796fb23
children 9b1d74a6b48c
files sat/plugins/plugin_misc_file.py sat_frontends/jp/cmd_file.py sat_frontends/jp/cmd_roster.py
diffstat 3 files changed, 24 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_file.py	Mon Oct 31 04:09:34 2022 +0100
+++ b/sat/plugins/plugin_misc_file.py	Mon Oct 31 04:09:38 2022 +0100
@@ -29,7 +29,7 @@
 from sat.tools import xml_tools
 from sat.tools import stream
 from sat.tools import utils
-from sat.tools.common import utils as common_utils
+from sat.tools.common import data_format, utils as common_utils
 
 
 log = getLogger(__name__)
@@ -72,7 +72,7 @@
         host.bridge.addMethod(
             "fileSend",
             ".plugin",
-            in_sign="ssssa{ss}s",
+            in_sign="ssssss",
             out_sign="a{ss}",
             method=self._fileSend,
             async_=True,
@@ -86,11 +86,19 @@
             type_=C.MENU_SINGLE,
         )
 
-    def _fileSend(self, peer_jid_s, filepath, name="", file_desc="", extra=None,
-                  profile=C.PROF_KEY_NONE):
+    def _fileSend(
+        self,
+        peer_jid_s: str,
+        filepath: str,
+        name: str,
+        file_desc: str,
+        extra_s: str,
+        profile: str = C.PROF_KEY_NONE
+    ) -> defer.Deferred:
         client = self.host.getClient(profile)
         return defer.ensureDeferred(self.fileSend(
-            client, jid.JID(peer_jid_s), filepath, name or None, file_desc or None, extra
+            client, jid.JID(peer_jid_s), filepath, name or None, file_desc or None,
+            data_format.deserialise(extra_s)
         ))
 
     async def fileSend(
--- a/sat_frontends/jp/cmd_file.py	Mon Oct 31 04:09:34 2022 +0100
+++ b/sat_frontends/jp/cmd_file.py	Mon Oct 31 04:09:38 2022 +0100
@@ -75,6 +75,12 @@
             default="",
             help=("name to use (DEFAULT: use source file name)"),
         )
+        self.parser.add_argument(
+            "-e",
+            "--encrypt",
+            action="store_true",
+            help=_("end-to-end encrypt the file transfer")
+        )
 
     async def onProgressStarted(self, metadata):
         self.disp(_("File copy started"), 2)
@@ -123,6 +129,8 @@
             extra["path"] = self.args.path
         if self.args.namespace:
             extra["namespace"] = self.args.namespace
+        if self.args.encrypt:
+            extra["encrypted"] = True
 
         if self.args.bz2:
             with tempfile.NamedTemporaryFile("wb", delete=False) as buf:
@@ -147,7 +155,7 @@
                         buf.name,
                         self.args.name or archive_name,
                         "",
-                        extra,
+                        data_format.serialise(extra),
                         self.profile,
                     )
                 except Exception as e:
@@ -164,7 +172,7 @@
                         path,
                         self.args.name,
                         "",
-                        extra,
+                        data_format.serialise(extra),
                         self.profile,
                     )
                 except Exception as e:
--- a/sat_frontends/jp/cmd_roster.py	Mon Oct 31 04:09:34 2022 +0100
+++ b/sat_frontends/jp/cmd_roster.py	Mon Oct 31 04:09:38 2022 +0100
@@ -139,7 +139,7 @@
 
     async def start(self):
         if not self.args.force:
-            message = _("Are you sure to delete {entity} fril your roster?").format(
+            message = _("Are you sure to delete {entity} from your roster?").format(
                 entity=self.args.jid
             )
             await self.host.confirmOrQuit(message, _("entity deletion cancelled"))