Support FIREBASE_TENANT_EMULATOR_HOST in TenantManagementService#962
Support FIREBASE_TENANT_EMULATOR_HOST in TenantManagementService#962KetanHegde wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces support for the Firebase Tenant Emulator by checking the FIREBASE_TENANT_EMULATOR_HOST environment variable and configuring the tenant management service to use the emulator host and credentials when available. The tests have also been updated to run in both emulated and non-emulated modes. Feedback on this PR suggests falling back to the standard FIREBASE_AUTH_EMULATOR_HOST if the tenant-specific emulator host is not set, ensuring a smoother developer experience when running the local Auth emulator.
| def get_tenant_emulator_host(): | ||
| emulator_host = os.getenv(TENANT_EMULATOR_HOST_ENV_VAR, '') | ||
| if emulator_host and '//' in emulator_host: | ||
| raise ValueError( | ||
| f'Invalid {TENANT_EMULATOR_HOST_ENV_VAR}: "{emulator_host}". ' | ||
| 'It must follow format "host:port".') | ||
| return emulator_host |
There was a problem hiding this comment.
Currently, if FIREBASE_AUTH_EMULATOR_HOST is set but FIREBASE_TENANT_EMULATOR_HOST is not, _TenantManagementService will still attempt to connect to production. Since tenant management is part of the Firebase Auth service, it is highly recommended to fall back to FIREBASE_AUTH_EMULATOR_HOST when FIREBASE_TENANT_EMULATOR_HOST is not explicitly configured. This ensures a seamless developer experience when running the local Auth emulator without requiring redundant environment variables.
| def get_tenant_emulator_host(): | |
| emulator_host = os.getenv(TENANT_EMULATOR_HOST_ENV_VAR, '') | |
| if emulator_host and '//' in emulator_host: | |
| raise ValueError( | |
| f'Invalid {TENANT_EMULATOR_HOST_ENV_VAR}: "{emulator_host}". ' | |
| 'It must follow format "host:port".') | |
| return emulator_host | |
| def get_tenant_emulator_host(): | |
| emulator_host = os.getenv(TENANT_EMULATOR_HOST_ENV_VAR, '') | |
| if not emulator_host: | |
| emulator_host = get_emulator_host() | |
| if emulator_host and '//' in emulator_host: | |
| raise ValueError( | |
| f'Invalid {TENANT_EMULATOR_HOST_ENV_VAR}: "{emulator_host}". ' | |
| 'It must follow format "host:port".') | |
| return emulator_host |
Summary
This PR adds support for running
TenantManagementServiceagainst the Firebase Authentication Emulator using a new environment variable,FIREBASE_TENANT_EMULATOR_HOST.When this environment variable is set,
_TenantManagementServiceuses the emulator endpoint instead of the production Identity Toolkit endpoint and initializes the client withEmulatorAdminCredentials.Changes
FIREBASE_TENANT_EMULATOR_HOSTget_tenant_emulator_host()helper_TenantManagementServiceto use the emulator endpoint when configuredTesting
Executed:
Result:
Also verified with:
The remaining pylint warnings are pre-existing in the test module.
Implements #910