changeset 2663:32b5f68a23b4

jp (message): new encryption/algorithms command to retrieve available encryptions algorithms.
author Goffi <goffi@goffi.org>
date Sat, 11 Aug 2018 18:24:55 +0200
parents 0bef44f8e8ca
children e35a265ec174
files sat_frontends/jp/cmd_message.py
diffstat 1 files changed, 53 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_message.py	Sat Aug 11 18:24:55 2018 +0200
+++ b/sat_frontends/jp/cmd_message.py	Sat Aug 11 18:24:55 2018 +0200
@@ -18,10 +18,11 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from sat_frontends.jp import base
+from sat_frontends.jp.constants import Const as C
 import sys
 from sat.core.i18n import _
-from sat.core.constants import Const as C
 from sat.tools.utils import clean_ustr
+from functools import partial
 
 __commands__ = ["Message"]
 
@@ -39,7 +40,8 @@
             "--separate",
             action="store_true",
             help=_(
-                u"separate xmpp messages: send one message per line instead of one message alone."
+                u"separate xmpp messages: send one message per line instead of one "
+                u"message alone."
             ),
         )
         self.parser.add_argument(
@@ -149,8 +151,56 @@
             )
 
 
+class EncryptionAlgorithms(base.CommandBase):
+
+    def __init__(self, host):
+        extra_outputs = {"default": self.default_output}
+        super(EncryptionAlgorithms, self).__init__(
+            host, "algorithms",
+            use_output=C.OUTPUT_LIST_DICT,
+            extra_outputs=extra_outputs,
+            use_profile=False,
+            help=_("show available encryption algorithms"))
+        self.need_loop = True
+
+    def add_parser_options(self):
+        pass
+
+    def encryptionPluginsGetCb(self, plugins):
+        self.output(plugins)
+        self.host.quit()
+
+    def default_output(self, plugins):
+        if not plugins:
+            self.disp(_(u"No encryption plugin registered!"))
+            self.host.quit(C.EXIT_NOT_FOUND)
+        else:
+            self.disp(_(u"Following encryption algorithms are available: {algos}").format(
+                algos=', '.join([p['name'] for p in plugins])))
+            self.host.quit()
+
+    def start(self):
+        self.host.bridge.encryptionPluginsGet(
+            callback=self.encryptionPluginsGetCb,
+            errback=partial(
+                self.errback,
+                msg=_(u"can't retrieve plugins: {}"),
+                exit_code=C.EXIT_BRIDGE_ERRBACK,
+            ),
+        )
+
+
+class Encryption(base.CommandBase):
+    subcommands = (EncryptionAlgorithms,)
+
+    def __init__(self, host):
+        super(Encryption, self).__init__(
+            host, "encryption", use_profile=False, help=_("encryption sessions handling")
+        )
+
+
 class Message(base.CommandBase):
-    subcommands = (Send,)
+    subcommands = (Send, Encryption)
 
     def __init__(self, host):
         super(Message, self).__init__(