Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 173
feat: avoid authentication when use emulator#328
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
b5ea0b2e436dad6915bb42390499File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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]: | ||
Contributor 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? ContributorAuthor 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 ContributorAuthor 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_optionsand_get_storage_host()for an api_endpoint, should we need to change that order?