Skip to content

Commit 47e3a7e

Browse files
committed
fix(emulator): add anonymous credentials for emulator based on env
1 parent 59a22b3 commit 47e3a7e

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
run: |
3131
npm install -g firebase-tools
3232
firebase emulators:exec --only database --project fake-project-id 'pytest integration/test_db.py'
33+
firebase emulators:exec --only storage --project fake-project-id 'pytest integration/test_storage.py --cert tests/data/service_account.json'
3334
3435
lint:
3536
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ First, install the Firebase CLI, then run:
218218

219219
```
220220
firebase emulators:exec --only database --project fake-project-id 'pytest integration/test_db.py'
221+
firebase emulators:exec --only storage --project fake-project-id 'pytest integration/test_storage.py --cert tests/data/service_account.json'
221222
```
222223

223224
### Test Coverage

firebase_admin/storage.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
# pylint: disable=import-error,no-name-in-module
2222
try:
2323
from google.cloud import storage
24+
from google.cloud.storage._helpers import STORAGE_EMULATOR_ENV_VAR
2425
except ImportError:
2526
raise ImportError('Failed to import the Cloud Storage library for Python. Make sure '
2627
'to install the "google-cloud-storage" module.')
2728

28-
from firebase_admin import _utils
29+
import os
2930

31+
from firebase_admin import _utils
3032

3133
_STORAGE_ATTRIBUTE = '_storage'
3234

@@ -61,7 +63,10 @@ def __init__(self, credentials, project, default_bucket):
6163

6264
@classmethod
6365
def from_app(cls, app):
64-
credentials = app.credential.get_credential()
66+
if os.getenv(STORAGE_EMULATOR_ENV_VAR) is not None:
67+
credentials = _utils.EmulatorAdminCredentials()
68+
else:
69+
credentials = app.credential.get_credential()
6570
default_bucket = app.options.get('storageBucket')
6671
# Specifying project ID is not required, but providing it when available
6772
# significantly speeds up the initialization of the storage client.

0 commit comments

Comments
 (0)