@@ -52,6 +52,7 @@ def request_registration(
52
52
user_type : Optional [str ] = None ,
53
53
_print : Callable [[str ], None ] = print ,
54
54
exit : Callable [[int ], None ] = sys .exit ,
55
+ exists_ok : bool = False ,
55
56
) -> None :
56
57
url = "%s/_synapse/admin/v1/register" % (server_location .rstrip ("/" ),)
57
58
@@ -97,6 +98,10 @@ def request_registration(
97
98
r = requests .post (url , json = data )
98
99
99
100
if r .status_code != 200 :
101
+ response = r .json ()
102
+ if exists_ok and response ["errcode" ] == "M_USER_IN_USE" :
103
+ _print ("User already exists. Skipping." )
104
+ return
100
105
_print ("ERROR! Received %d %s" % (r .status_code , r .reason ))
101
106
if 400 <= r .status_code < 500 :
102
107
try :
@@ -115,6 +120,7 @@ def register_new_user(
115
120
shared_secret : str ,
116
121
admin : Optional [bool ],
117
122
user_type : Optional [str ],
123
+ exists_ok : bool = False ,
118
124
) -> None :
119
125
if not user :
120
126
try :
@@ -154,7 +160,13 @@ def register_new_user(
154
160
admin = False
155
161
156
162
request_registration (
157
- user , password , server_location , shared_secret , bool (admin ), user_type
163
+ user ,
164
+ password ,
165
+ server_location ,
166
+ shared_secret ,
167
+ bool (admin ),
168
+ user_type ,
169
+ exists_ok = exists_ok ,
158
170
)
159
171
160
172
@@ -173,6 +185,11 @@ def main() -> None:
173
185
default = None ,
174
186
help = "Local part of the new user. Will prompt if omitted." ,
175
187
)
188
+ parser .add_argument (
189
+ "--exists-ok" ,
190
+ action = "store_true" ,
191
+ help = "Do not fail if user already exists." ,
192
+ )
176
193
password_group = parser .add_mutually_exclusive_group ()
177
194
password_group .add_argument (
178
195
"-p" ,
@@ -192,6 +209,7 @@ def main() -> None:
192
209
default = None ,
193
210
help = "User type as specified in synapse.api.constants.UserTypes" ,
194
211
)
212
+
195
213
admin_group = parser .add_mutually_exclusive_group ()
196
214
admin_group .add_argument (
197
215
"-a" ,
@@ -281,7 +299,7 @@ def main() -> None:
281
299
if args .admin or args .no_admin :
282
300
admin = args .admin
283
301
284
- register_new_user (args .user , password , server_url , secret , admin , args .user_type )
302
+ register_new_user (args .user , password , server_url , secret , admin , args .user_type , exists_ok = args . exists_ok )
285
303
286
304
287
305
def _read_file (file_path : Any , config_path : str ) -> str :
0 commit comments