Skip to content

Commit

Permalink
fix(storage): accept the official format for $STORAGE_EMULATOR_HOST (
Browse files Browse the repository at this point in the history
…#632)

In order for this library to be compatible with the official python Google Cloud
Storage library, it needs to accept the same value for configuring the
`STORAGE_EMULATOR_HOST` environment variable. This will allow users to
rely on both libraries in a single project.

---------

Co-authored-by: Kevin James <kevin@talkiq.com>
  • Loading branch information
guneemwelloeux and TheKevJames committed Sep 13, 2023
1 parent 81b926a commit 90f92d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion storage/gcloud/aio/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
```shell
docker run -d -p 4443:4443 -v $PWD/my-sample-data:/data fsouza/fake-gcs-server
export STORAGE_EMULATOR_HOST='0.0.0.0:4443'
export STORAGE_EMULATOR_HOST='http://0.0.0.0:4443'
```
Any `gcloud-aio-storage` requests made with that environment variable set will
Expand Down
7 changes: 6 additions & 1 deletion storage/gcloud/aio/storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import mimetypes
import os
import warnings
from typing import Any
from typing import AnyStr
from typing import Dict
Expand Down Expand Up @@ -51,7 +52,11 @@ def init_api_root(api_root: Optional[str]) -> Tuple[bool, str]:

host = os.environ.get('STORAGE_EMULATOR_HOST')
if host:
return True, f'http://{host}'
if not host.startswith('http'):
warnings.warn('STORAGE_EMULATOR_HOST must include http:// prefix',
DeprecationWarning)
host = f'http://{host}'
return True, host

return False, 'https://www.googleapis.com'

Expand Down

0 comments on commit 90f92d3

Please sign in to comment.