Mercurial > libervia-backend
annotate libervia/cli/cmd_account.py @ 4318:27bb22eace65
tests (unit/email gateway): add test for XEP-0131 handling:
rel 451
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 Sep 2024 15:59:48 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
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 | 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 | 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 | 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 | 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 | 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 | 75 async def start(self): |
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 | 78 self.args.jid, |
79 self.args.password, | |
80 self.args.email, | |
81 self.args.host, | |
82 self.args.port, | |
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 | 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 | 100 self.disp(_("XMPP account created"), 1) |
101 | |
102 if self.args.profile is None: | |
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 | 105 self.disp(_("creating profile"), 2) |
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 | 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 | 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 | 128 |
129 self.disp(_("profile created"), 1) | |
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 | 132 self.args.password, |
133 self.args.profile, | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
134 ) |
3040 | 135 except Exception as e: |
136 self.disp(f"can't start profile session: {e}", error=True) | |
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 | 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 | 141 "JabberID", |
142 self.args.jid, | |
143 "Connection", | |
144 profile_key=self.args.profile, | |
145 ) | |
146 except Exception as e: | |
147 self.disp(f"can't set JabberID parameter: {e}", error=True) | |
148 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
149 | |
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 | 152 "Password", |
153 self.args.password, | |
154 "Connection", | |
155 profile_key=self.args.profile, | |
156 ) | |
157 except Exception as e: | |
158 self.disp(f"can't set Password parameter: {e}", error=True) | |
159 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
160 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
161 self.disp( |
3040 | 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 | 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 | 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 | 178 async def start(self): |
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 | 181 self.args.password, |
182 self.args.profile, | |
183 ) | |
184 except Exception as e: | |
185 self.disp(f"can't change XMPP password: {e}", error=True) | |
186 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
187 else: | |
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 | 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 | 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 | 205 async def start(self): |
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 | 208 "JabberID", |
209 "Connection", | |
210 profile_key=self.profile, | |
211 ) | |
212 except Exception as e: | |
213 self.disp(f"can't get JID of the profile: {e}", error=True) | |
214 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
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 | 219 f"You are about to delete the XMPP account with jid {jid_!r}\n" |
220 f"This is the XMPP account of profile {self.profile!r}\n" | |
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 | 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 | 227 except Exception as e: |
228 self.disp(f"can't delete XMPP account with jid {jid_!r}: {e}", error=True) | |
229 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
230 | |
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 | 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 ) |