25
25
26
26
import firebase_admin
27
27
from firebase_admin import auth
28
- from firebase_admin import multi_factor_config_mgt
29
28
from firebase_admin import _auth_utils
30
29
from firebase_admin import _http_client
31
30
from firebase_admin import _utils
31
+ from firebase_admin .multi_factor_config_mgt import MultiFactorConfig
32
+ from firebase_admin .multi_factor_config_mgt import MultiFactorServerConfig
32
33
33
34
34
35
_TENANT_MGT_ATTRIBUTE = '_tenant_mgt'
@@ -93,7 +94,7 @@ def get_tenant(tenant_id, app=None):
93
94
94
95
def create_tenant (
95
96
display_name , allow_password_sign_up = None , enable_email_link_sign_in = None ,
96
- multi_factor_config : multi_factor_config_mgt . MultiFactorConfig = None , app = None ):
97
+ multi_factor_config : MultiFactorConfig = None , app = None ):
97
98
"""Creates a new tenant from the given options.
98
99
99
100
Args:
@@ -122,7 +123,7 @@ def create_tenant(
122
123
123
124
def update_tenant (
124
125
tenant_id , display_name = None , allow_password_sign_up = None , enable_email_link_sign_in = None ,
125
- multi_factor_config : multi_factor_config_mgt . MultiFactorConfig = None , app = None ):
126
+ multi_factor_config : MultiFactorConfig = None , app = None ):
126
127
"""Updates an existing tenant with the given options.
127
128
128
129
Args:
@@ -189,6 +190,7 @@ def list_tenants(page_token=None, max_results=_MAX_LIST_TENANTS_RESULTS, app=Non
189
190
FirebaseError: If an error occurs while retrieving the user accounts.
190
191
"""
191
192
tenant_mgt_service = _get_tenant_mgt_service (app )
193
+
192
194
def download (page_token , max_results ):
193
195
return tenant_mgt_service .list_tenants (page_token , max_results )
194
196
return ListTenantsPage (download , page_token , max_results )
@@ -211,7 +213,8 @@ class Tenant:
211
213
212
214
def __init__ (self , data ):
213
215
if not isinstance (data , dict ):
214
- raise ValueError ('Invalid data argument in Tenant constructor: {0}' .format (data ))
216
+ raise ValueError (
217
+ 'Invalid data argument in Tenant constructor: {0}' .format (data ))
215
218
if not 'name' in data :
216
219
raise ValueError ('Tenant response missing required keys.' )
217
220
@@ -238,7 +241,7 @@ def enable_email_link_sign_in(self):
238
241
def multi_factor_config (self ):
239
242
data = self ._data .get ('mfaConfig' , None )
240
243
if data is not None :
241
- return multi_factor_config_mgt . MultiFactorServerConfig (data )
244
+ return MultiFactorServerConfig (data )
242
245
return None
243
246
244
247
@@ -250,7 +253,8 @@ class _TenantManagementService:
250
253
def __init__ (self , app ):
251
254
credential = app .credential .get_credential ()
252
255
version_header = 'Python/Admin/{0}' .format (firebase_admin .__version__ )
253
- base_url = '{0}/projects/{1}' .format (self .TENANT_MGT_URL , app .project_id )
256
+ base_url = '{0}/projects/{1}' .format (
257
+ self .TENANT_MGT_URL , app .project_id )
254
258
self .app = app
255
259
self .client = _http_client .JsonHttpClient (
256
260
credential = credential , base_url = base_url , headers = {'X-Client-Version' : version_header })
@@ -269,7 +273,7 @@ def auth_for_tenant(self, tenant_id):
269
273
270
274
client = auth .Client (self .app , tenant_id = tenant_id )
271
275
self .tenant_clients [tenant_id ] = client
272
- return client
276
+ return client
273
277
274
278
def get_tenant (self , tenant_id ):
275
279
"""Gets the tenant corresponding to the given ``tenant_id``."""
@@ -286,7 +290,7 @@ def get_tenant(self, tenant_id):
286
290
287
291
def create_tenant (
288
292
self , display_name , allow_password_sign_up = None , enable_email_link_sign_in = None ,
289
- multi_factor_config : multi_factor_config_mgt . MultiFactorConfig = None ):
293
+ multi_factor_config : MultiFactorConfig = None ):
290
294
"""Creates a new tenant from the given parameters."""
291
295
292
296
payload = {'displayName' : _validate_display_name (display_name )}
@@ -297,7 +301,7 @@ def create_tenant(
297
301
payload ['enableEmailLinkSignin' ] = _auth_utils .validate_boolean (
298
302
enable_email_link_sign_in , 'enableEmailLinkSignin' )
299
303
if multi_factor_config is not None :
300
- if not isinstance (multi_factor_config , multi_factor_config_mgt . MultiFactorConfig ):
304
+ if not isinstance (multi_factor_config , MultiFactorConfig ):
301
305
raise ValueError (
302
306
'multi_factor_config must be of type MultiFactorConfig.' )
303
307
payload ['mfaConfig' ] = multi_factor_config .build_server_request ()
@@ -311,7 +315,7 @@ def create_tenant(
311
315
def update_tenant (
312
316
self , tenant_id , display_name = None , allow_password_sign_up = None ,
313
317
enable_email_link_sign_in = None ,
314
- multi_factor_config : multi_factor_config_mgt . MultiFactorConfig = None ):
318
+ multi_factor_config : MultiFactorConfig = None ):
315
319
"""Updates the specified tenant with the given parameters."""
316
320
if not isinstance (tenant_id , str ) or not tenant_id :
317
321
raise ValueError ('Tenant ID must be a non-empty string.' )
@@ -326,12 +330,14 @@ def update_tenant(
326
330
payload ['enableEmailLinkSignin' ] = _auth_utils .validate_boolean (
327
331
enable_email_link_sign_in , 'enableEmailLinkSignin' )
328
332
if multi_factor_config is not None :
329
- if not isinstance (multi_factor_config , multi_factor_config_mgt .MultiFactorConfig ):
330
- raise ValueError ('multi_factor_config must be of type MultiFactorConfig.' )
333
+ if not isinstance (multi_factor_config , MultiFactorConfig ):
334
+ raise ValueError (
335
+ 'multi_factor_config must be of type MultiFactorConfig.' )
331
336
payload ['mfaConfig' ] = multi_factor_config .build_server_request ()
332
337
333
338
if not payload :
334
- raise ValueError ('At least one parameter must be specified for update.' )
339
+ raise ValueError (
340
+ 'At least one parameter must be specified for update.' )
335
341
336
342
url = '/tenants/{0}' .format (tenant_id )
337
343
update_mask = ',' .join (_auth_utils .build_update_mask (payload ))
0 commit comments