Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(emulator): add anonymous credentials for emulator based on env
  • Loading branch information
Spirans committed Aug 23, 2023
commit 47e3a7e65ae741889d82cacf721e8e698e8b155f
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
run: |
npm install -g firebase-tools
firebase emulators:exec --only database --project fake-project-id 'pytest integration/test_db.py'
firebase emulators:exec --only storage --project fake-project-id 'pytest integration/test_storage.py --cert tests/data/service_account.json'

lint:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ First, install the Firebase CLI, then run:

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

### Test Coverage
Expand Down
9 changes: 7 additions & 2 deletions firebase_admin/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
# pylint: disable=import-error,no-name-in-module
try:
from google.cloud import storage
from google.cloud.storage._helpers import STORAGE_EMULATOR_ENV_VAR
except ImportError:
raise ImportError('Failed to import the Cloud Storage library for Python. Make sure '
'to install the "google-cloud-storage" module.')

from firebase_admin import _utils
import os

from firebase_admin import _utils

_STORAGE_ATTRIBUTE = '_storage'

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

@classmethod
def from_app(cls, app):
credentials = app.credential.get_credential()
if os.getenv(STORAGE_EMULATOR_ENV_VAR) is not None:
credentials = _utils.EmulatorAdminCredentials()
else:
credentials = app.credential.get_credential()
default_bucket = app.options.get('storageBucket')
# Specifying project ID is not required, but providing it when available
# significantly speeds up the initialization of the storage client.
Expand Down