annotate libervia/cli/cmd_account.py @ 4340:ea72364131d5 default tip @

doc (components): Update Email Gateway documentation: A section has been added to explain how attachments are handled. fix 453
author Goffi <goffi@goffi.org>
date Tue, 03 Dec 2024 00:53:18 +0100
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
3
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
4 # Libervia CLI
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3435
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
6
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
11
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
16
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
19
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """This module permits to manage XMPP accounts using in-band registration (XEP-0077)"""
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
21
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
22 from libervia.cli.constants import Const as C
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
23 from libervia.frontends.bridge.bridge_frontend import BridgeException
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
24 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
25 from libervia.backend.core.i18n import _
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
26 from libervia.cli import base
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
27 from libervia.frontends.tools import jid
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
28
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
29
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
30 log = getLogger(__name__)
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
31
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
32 __commands__ = ["Account"]
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
33
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
34
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
35 class AccountCreate(base.CommandBase):
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
36 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
37 super(AccountCreate, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
38 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39 "create",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
40 use_profile=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 use_verbose=True,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
42 help=_("create a XMPP account"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
43 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
44
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
45 def add_parser_options(self):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
46 self.parser.add_argument("jid", help=_("jid to create"))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
47 self.parser.add_argument("password", help=_("password of the account"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 "-p",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50 "--profile",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 help=_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
52 "create a profile to use this account (default: don't create profile)"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 "-e",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 "--email",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 default="",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
59 help=_("email (usage depends of XMPP server)"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 "-H",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 "--host",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 default="",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
65 help=_("server host (IP address or domain, default: use localhost)"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 "-P",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 "--port",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 type=int,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 default=0,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
72 help=_("server port (default: {port})").format(port=C.XMPP_C2S_PORT),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
74
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
75 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
76 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
77 await self.host.bridge.in_band_account_new(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
78 self.args.jid,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
79 self.args.password,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
80 self.args.email,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
81 self.args.host,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
82 self.args.port,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
83 )
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
84
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
85 except BridgeException as e:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
86 if e.condition == "conflict":
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
87 self.disp(f"The account {self.args.jid} already exists", error=True)
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
88 self.host.quit(C.EXIT_CONFLICT)
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
89 else:
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
90 self.disp(
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
91 f"can't create account on {self.args.host or 'localhost'!r} with jid "
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
92 f"{self.args.jid!r} using In-Band Registration: {e}",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
93 error=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
94 )
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
95 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
96 except Exception as e:
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
97 self.disp(f"Internal error: {e}", error=True)
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
98 self.host.quit(C.EXIT_INTERNAL_ERROR)
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
99
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
100 self.disp(_("XMPP account created"), 1)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
101
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
102 if self.args.profile is None:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
103 self.host.quit()
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
104
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
105 self.disp(_("creating profile"), 2)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
106 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
107 await self.host.bridge.profile_create(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
108 self.args.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 self.args.password,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 "",
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
111 )
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
112 except BridgeException as e:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
113 if e.condition == "conflict":
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
114 self.disp(f"The profile {self.args.profile} already exists", error=True)
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
115 self.host.quit(C.EXIT_CONFLICT)
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
116 else:
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
117 self.disp(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
118 _(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
119 "Can't create profile {profile} to associate with jid "
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
120 "{jid}: {e}"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
121 ).format(profile=self.args.profile, jid=self.args.jid, e=e),
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
122 error=True,
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
123 )
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
124 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
125 except Exception as e:
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
126 self.disp(f"Internal error: {e}", error=True)
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
127 self.host.quit(C.EXIT_INTERNAL_ERROR)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
128
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
129 self.disp(_("profile created"), 1)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
130 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
131 await self.host.bridge.profile_start_session(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
132 self.args.password,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
133 self.args.profile,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
135 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
136 self.disp(f"can't start profile session: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
137 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
138
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
139 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
140 await self.host.bridge.param_set(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
141 "JabberID",
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
142 self.args.jid,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
143 "Connection",
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
144 profile_key=self.args.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
145 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
146 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
147 self.disp(f"can't set JabberID parameter: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
148 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
149
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
150 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
151 await self.host.bridge.param_set(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
152 "Password",
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
153 self.args.password,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
154 "Connection",
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
155 profile_key=self.args.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
156 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
157 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
158 self.disp(f"can't set Password parameter: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
159 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
160
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
161 self.disp(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
162 f"profile {self.args.profile} successfully created and associated to the new "
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
163 f"account",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
164 1,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
165 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
166 self.host.quit()
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
167
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
168
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
169 class AccountModify(base.CommandBase):
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
170 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
171 super(AccountModify, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
172 host, "modify", help=_("change password for XMPP account")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
174
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
175 def add_parser_options(self):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
176 self.parser.add_argument("password", help=_("new XMPP password"))
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
177
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
178 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
179 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
180 await self.host.bridge.in_band_password_change(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
181 self.args.password,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
182 self.args.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
183 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
184 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
185 self.disp(f"can't change XMPP password: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
186 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
187 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
188 self.host.quit()
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
189
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
190
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
191 class AccountDelete(base.CommandBase):
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
192 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
193 super(AccountDelete, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
194 host, "delete", help=_("delete a XMPP account")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
195 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
196
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
197 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
198 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
199 "-f",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
200 "--force",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
201 action="store_true",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
202 help=_("delete account without confirmation"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
203 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
204
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
205 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
206 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
207 jid_str = await self.host.bridge.param_get_a_async(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
208 "JabberID",
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
209 "Connection",
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
210 profile_key=self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
211 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
212 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
213 self.disp(f"can't get JID of the profile: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
214 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
215
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
216 jid_ = jid.JID(jid_str)
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
217 if not self.args.force:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
218 message = (
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
219 f"You are about to delete the XMPP account with jid {jid_!r}\n"
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
220 f"This is the XMPP account of profile {self.profile!r}\n"
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
221 f"Are you sure that you want to delete this account?"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
222 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
223 await self.host.confirm_or_quit(message, _("Account deletion cancelled"))
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
224
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
225 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
226 await self.host.bridge.in_band_unregister(jid_.domain, self.args.profile)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
227 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
228 self.disp(f"can't delete XMPP account with jid {jid_!r}: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
229 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
230
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
231 self.host.quit()
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
232
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
233
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
234 class Account(base.CommandBase):
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
235 subcommands = (AccountCreate, AccountModify, AccountDelete)
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
236
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
237 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
238 super(Account, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
239 host, "account", use_profile=False, help=("XMPP account management")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
240 )