annotate libervia/cli/cmd_account.py @ 4222:1c30d574df2b

plugin XEP-0313: fix value used in `msg_from` when `from` is not explicitely specified.
author Goffi <goffi@goffi.org>
date Tue, 05 Mar 2024 17:31:56 +0100
parents 47401850dec6
children 0d7bb4df2343
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):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
46 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
47 "jid", help=_("jid to create")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
50 "password", help=_("password of the account")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
52 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 "-p",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 "--profile",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 help=_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
56 "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
57 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 "-e",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 "--email",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 default="",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
63 help=_("email (usage depends of XMPP server)"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 "-H",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 "--host",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 default="",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
69 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
70 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 "-P",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 "--port",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 type=int,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
75 default=0,
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
76 help=_("server port (default: {port})").format(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
77 port=C.XMPP_C2S_PORT
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
78 ),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
80
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
81 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
82 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
83 await self.host.bridge.in_band_account_new(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
84 self.args.jid,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
85 self.args.password,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
86 self.args.email,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
87 self.args.host,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
88 self.args.port,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
89 )
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
90
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
91 except BridgeException as e:
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
92 if e.condition == 'conflict':
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
93 self.disp(
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
94 f"The account {self.args.jid} already exists",
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
95 error=True
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
96 )
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
97 self.host.quit(C.EXIT_CONFLICT)
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
98 else:
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
99 self.disp(
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
100 f"can't create account on {self.args.host or 'localhost'!r} with jid "
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
101 f"{self.args.jid!r} using In-Band Registration: {e}", error=True)
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
102 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
103 except Exception as e:
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
104 self.disp(f"Internal error: {e}", error=True)
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
105 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
106
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
107 self.disp(_("XMPP account created"), 1)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
108
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
109 if self.args.profile is None:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
110 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
111
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
112
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
113 self.disp(_("creating profile"), 2)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
114 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
115 await self.host.bridge.profile_create(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 self.args.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 self.args.password,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
118 "",
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
119 )
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
120 except BridgeException as e:
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
121 if e.condition == 'conflict':
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
122 self.disp(
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
123 f"The profile {self.args.profile} already exists",
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
124 error=True
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
125 )
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
126 self.host.quit(C.EXIT_CONFLICT)
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
127 else:
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
128 self.disp(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
129 _("Can't create profile {profile} to associate with jid "
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
130 "{jid}: {e}").format(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
131 profile=self.args.profile,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
132 jid=self.args.jid,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
133 e=e
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
134 ),
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
135 error=True,
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
136 )
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
137 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
138 except Exception as e:
3435
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
139 self.disp(f"Internal error: {e}", error=True)
df775db4c49b jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
140 self.host.quit(C.EXIT_INTERNAL_ERROR)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
141
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
142 self.disp(_("profile created"), 1)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
143 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
144 await self.host.bridge.profile_start_session(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
145 self.args.password,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
146 self.args.profile,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
147 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
148 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
149 self.disp(f"can't start profile session: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
150 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
151
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
152 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
153 await self.host.bridge.param_set(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
154 "JabberID",
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
155 self.args.jid,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
156 "Connection",
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
157 profile_key=self.args.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
158 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
159 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
160 self.disp(f"can't set JabberID parameter: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
161 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
162
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
163 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
164 await self.host.bridge.param_set(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
165 "Password",
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
166 self.args.password,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
167 "Connection",
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
168 profile_key=self.args.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
169 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
170 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
171 self.disp(f"can't set Password parameter: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
172 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
173
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
174 self.disp(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
175 f"profile {self.args.profile} successfully created and associated to the new "
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
176 f"account", 1)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
177 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
178
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
179
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
180 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
181 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
182 super(AccountModify, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
183 host, "modify", help=_("change password for XMPP account")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
184 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
185
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
186 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
187 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
188 "password", help=_("new XMPP password")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
189 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
190
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
191 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
192 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
193 await self.host.bridge.in_band_password_change(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
194 self.args.password,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
195 self.args.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
196 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
197 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
198 self.disp(f"can't change XMPP password: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
199 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
200 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
201 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
202
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
203
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
204 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
205 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
206 super(AccountDelete, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
207 host, "delete", help=_("delete a XMPP account")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
208 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
209
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
210 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
211 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
212 "-f",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
213 "--force",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
214 action="store_true",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
215 help=_("delete account without confirmation"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
216 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
217
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
218 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
219 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
220 jid_str = await self.host.bridge.param_get_a_async(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
221 "JabberID",
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
222 "Connection",
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
223 profile_key=self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
224 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
225 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
226 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
227 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
228
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
229 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
230 if not self.args.force:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
231 message = (
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
232 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
233 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
234 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
235 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
236 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
237
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
238 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
239 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
240 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
241 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
242 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
243
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
244 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
245
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
246
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
247 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
248 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
249
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
250 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
251 super(Account, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
252 host, "account", use_profile=False, help=("XMPP account management")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
253 )