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: avoid authentication when use emulator #328
Changes from all commits
b5ea0b2
e436dad
6915bb4
2390499
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import datetime | ||
import functools | ||
import json | ||
import os | ||
import warnings | ||
import google.api_core.client_options | ||
|
||
|
@@ -33,6 +34,7 @@ | |
from google.cloud.exceptions import NotFound | ||
from google.cloud.storage._helpers import _get_storage_host | ||
from google.cloud.storage._helpers import _bucket_bound_hostname_url | ||
from google.cloud.storage._helpers import STORAGE_EMULATOR_ENV_VAR | ||
from google.cloud.storage._http import Connection | ||
from google.cloud.storage._signing import ( | ||
get_expiration_seconds_v4, | ||
|
@@ -119,6 +121,16 @@ def __init__( | |
if project is _marker: | ||
project = None | ||
|
||
if os.getenv(STORAGE_EMULATOR_ENV_VAR) is not None: | ||
credentials = AnonymousCredentials() | ||
if project in [_marker, None]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is project validation necessary given the super class will fall back to the expected environment variables? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, when we are passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think i can remove this condition after merge of cloud-core-51 PR |
||
project = os.getenv("GCLOUD_PROJECT") | ||
if project is None: | ||
raise ValueError( | ||
"To use the GCS emulator, pass 'project' as an argument " | ||
"or set GCLOUD_PROJECT environment variable" | ||
) | ||
|
||
super(Client, self).__init__( | ||
project=project, | ||
credentials=credentials, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to infer this from endpoint value in client_options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry didn't get the point, few questions regarding that
what if client_options didn't pass
which value use to compare with kw_args["api_endpoint"]? _DEFAULT_STORAGE_HOST which is
https://storage.googleapis.com
?Right now first we call the super class of client with credentials and then iterate the
client_options
and_get_storage_host()
for an api_endpoint, should we need to change that order?