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

API Core: Add client_options documentation. #8834

Merged
merged 3 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add client options to storage client.
  • Loading branch information
busunkim96 committed Jul 30, 2019
commit b3a6acd90790d0e759aeea216f746fc233ed646d
4 changes: 1 addition & 3 deletions storage/google/cloud/storage/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ class Connection(_http.JSONConnection):
"""

def __init__(self, client, client_info=None):
Connection.API_BASE_URL = client.api_endpoint
super(Connection, self).__init__(client, client_info)

self._client_info.gapic_version = __version__
self._client_info.client_library_version = __version__

API_BASE_URL = _http.API_BASE_URL
"""The base of the API call URL."""

API_VERSION = "v1"
"""The version of the API, used in building the API call's URL."""

Expand Down
10 changes: 6 additions & 4 deletions storage/google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
from google.cloud.storage.acl import ObjectACL


_API_ACCESS_ENDPOINT = "https://storage.googleapis.com"
_DEFAULT_CONTENT_TYPE = u"application/octet-stream"
_DOWNLOAD_URL_TEMPLATE = (
u"https://www.googleapis.com/download/storage/v1{path}?alt=media"
Expand Down Expand Up @@ -296,15 +295,15 @@ def public_url(self):
:returns: The public URL for this blob.
"""
return "{storage_base_url}/{bucket_name}/{quoted_name}".format(
storage_base_url=_API_ACCESS_ENDPOINT,
storage_base_url=self.bucket.client.api_endpoint,
bucket_name=self.bucket.name,
quoted_name=_quote(self.name, safe=b"/~"),
)

def generate_signed_url(
self,
expiration=None,
api_access_endpoint=_API_ACCESS_ENDPOINT,
api_access_endpoint=None,
method="GET",
content_md5=None,
content_type=None,
Expand Down Expand Up @@ -342,7 +341,8 @@ def generate_signed_url(
:param expiration: Point in time when the signed URL should expire.

:type api_access_endpoint: str
:param api_access_endpoint: Optional URI base.
:param api_access_endpoint: Optional URI base. If not passed, falls back
to the api_endpoint of the client.

:type method: str
:param method: The HTTP verb that will be used when requesting the URL.
Expand Down Expand Up @@ -423,6 +423,8 @@ def generate_signed_url(

if credentials is None:
client = self._require_client(client)
if api_access_endpoint is None:
api_access_endpoint = client.api_endpoint
credentials = client._credentials

if version == "v2":
Expand Down
8 changes: 5 additions & 3 deletions storage/google/cloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"valid before the bucket is created. Instead, pass the location "
"to `Bucket.create`."
)
_API_ACCESS_ENDPOINT = "https://storage.googleapis.com"


def _blobs_page_start(iterator, page, response):
Expand Down Expand Up @@ -2065,7 +2064,7 @@ def lock_retention_policy(self, client=None):
def generate_signed_url(
self,
expiration=None,
api_access_endpoint=_API_ACCESS_ENDPOINT,
api_access_endpoint=None,
method="GET",
headers=None,
query_parameters=None,
Expand Down Expand Up @@ -2098,7 +2097,8 @@ def generate_signed_url(
:param expiration: Point in time when the signed URL should expire.

:type api_access_endpoint: str
:param api_access_endpoint: Optional URI base.
:param api_access_endpoint: Optional URI base. If not passed, falls back
to the api_endpoint of the client.

:type method: str
:param method: The HTTP verb that will be used when requesting the URL.
Expand Down Expand Up @@ -2151,6 +2151,8 @@ def generate_signed_url(

if credentials is None:
client = self._require_client(client)
if api_access_endpoint is None:
api_access_endpoint = client.api_endpoint
credentials = client._credentials

if version == "v2":
Expand Down
18 changes: 17 additions & 1 deletion storage/google/cloud/storage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from google.auth.credentials import AnonymousCredentials

import google.api_core.client_options
from google.api_core import page_iterator
from google.cloud._helpers import _LocalStack
from google.cloud.client import ClientWithProject
Expand Down Expand Up @@ -60,16 +61,23 @@ class Client(ClientWithProject):
requests. If ``None``, then default info will be used. Generally,
you only need to set this if you're developing your own library
or partner tool.
:type client_options: Union(Dict, :class:`~google.api_core.client_options.ClientOptions`)
:param client_options:
Client options used to set user options on the client. API Endpoint
should be set through client_options.
"""

API_ENDPOINT = "https://storage.googleapis.com"

SCOPE = (
"https://www.googleapis.com/auth/devstorage.full_control",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/devstorage.read_write",
)
"""The scopes required for authenticating as a Cloud Storage consumer."""

def __init__(self, project=_marker, credentials=None, _http=None, client_info=None):
def __init__(self, project=_marker, credentials=None, _http=None, client_info=None,
client_options=None):
self._base_connection = None
if project is None:
no_project = True
Expand All @@ -78,6 +86,14 @@ def __init__(self, project=_marker, credentials=None, _http=None, client_info=No
no_project = False
if project is _marker:
project = None

self.api_endpoint = self.API_ENDPOINT
if client_options:
if type(client_options) == dict:
client_options = google.api_core.client_options.from_dict(client_options)
if client_options.api_endpoint:
self.api_endpoint = client_options.api_endpoint

super(Client, self).__init__(
project=project, credentials=credentials, _http=_http
)
Expand Down