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