Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(emulator): add support for storage emulator #717

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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