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

Client generation can handle the mtlsRootUrl #288

Merged
merged 1 commit into from
Feb 13, 2020
Merged
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
Client generation can handle the mtlsRootUrl
  • Loading branch information
liuchaoren committed Feb 12, 2020
commit e0017dccaede054642e4f3da5fcbae716922dfd0
1 change: 1 addition & 0 deletions apitools/gen/service_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def WriteFile(self, printer):
printer()
printer('MESSAGES_MODULE = messages')
printer('BASE_URL = {0!r}'.format(client_info.base_url))
printer('MTLS_BASE_URL = {0!r}'.format(client_info.mtls_base_url))
printer()
printer('_PACKAGE = {0!r}'.format(client_info.package))
printer('_SCOPES = {0!r}'.format(
Expand Down
31 changes: 26 additions & 5 deletions apitools/gen/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,21 @@ def NormalizeVersion(version):
return version.replace('.', '_')


def _ComputePaths(package, version, discovery_doc):
full_path = urllib_parse.urljoin(
discovery_doc['rootUrl'], discovery_doc['servicePath'])
def _ComputePaths(package, version, root_url, service_path):
liuchaoren marked this conversation as resolved.
Show resolved Hide resolved
"""Compute the base url and base path.

Attributes:
package: name field of the discovery, i.e. 'storage' for storage service.
version: version of the service, i.e. 'v1'.
root_url: root url of the service, i.e. 'https://www.googleapis.com/'.
service_path: path of the service under the rool url, i.e. 'storage/v1/'.

Returns:
base url: string, base url of the service,
'https://www.googleapis.com/storage/v1/' for the storage service.
base path: string, common prefix of service endpoints after the base url.
"""
full_path = urllib_parse.urljoin(root_url, service_path)
api_path_component = '/'.join((package, version, ''))
if api_path_component not in full_path:
return full_path, ''
Expand All @@ -187,7 +199,7 @@ def _ComputePaths(package, version, discovery_doc):
class ClientInfo(collections.namedtuple('ClientInfo', (
'package', 'scopes', 'version', 'client_id', 'client_secret',
'user_agent', 'client_class_name', 'url_version', 'api_key',
'base_url', 'base_path'))):
'base_url', 'base_path', 'mtls_base_url'))):

"""Container for client-related info and names."""

Expand All @@ -201,7 +213,15 @@ def Create(cls, discovery_doc,
package = discovery_doc['name']
url_version = discovery_doc['version']
base_url, base_path = _ComputePaths(package, url_version,
discovery_doc)
discovery_doc['rootUrl'],
discovery_doc['servicePath'])

mtls_root_url = discovery_doc.get('mtlsRootUrl', '')
mtls_base_url = ''
if mtls_root_url:
mtls_base_url, _ = _ComputePaths(package, url_version,
mtls_root_url,
discovery_doc['servicePath'])

client_info = {
'package': package,
Expand All @@ -214,6 +234,7 @@ def Create(cls, discovery_doc,
'api_key': api_key,
'base_url': base_url,
'base_path': base_path,
'mtls_base_url': mtls_base_url,
}
client_class_name = '%s%s' % (
names.ClassName(client_info['package']),
Expand Down
1 change: 1 addition & 0 deletions samples/bigquery_sample/bigquery_v2/bigquery_v2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class BigqueryV2(base_api.BaseApiClient):

MESSAGES_MODULE = messages
BASE_URL = u'https://www.googleapis.com/bigquery/v2/'
MTLS_BASE_URL = u''

_PACKAGE = u'bigquery'
_SCOPES = [u'https://www.googleapis.com/auth/bigquery', u'https://www.googleapis.com/auth/bigquery.insertdata', u'https://www.googleapis.com/auth/cloud-platform', u'https://www.googleapis.com/auth/cloud-platform.read-only', u'https://www.googleapis.com/auth/devstorage.full_control', u'https://www.googleapis.com/auth/devstorage.read_only', u'https://www.googleapis.com/auth/devstorage.read_write']
Expand Down
1 change: 1 addition & 0 deletions samples/dns_sample/dns_v1/dns_v1_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class DnsV1(base_api.BaseApiClient):

MESSAGES_MODULE = messages
BASE_URL = u'https://www.googleapis.com/dns/v1/'
MTLS_BASE_URL = u''

_PACKAGE = u'dns'
_SCOPES = [u'https://www.googleapis.com/auth/cloud-platform', u'https://www.googleapis.com/auth/cloud-platform.read-only', u'https://www.googleapis.com/auth/ndev.clouddns.readonly', u'https://www.googleapis.com/auth/ndev.clouddns.readwrite']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class FusiontablesV1(base_api.BaseApiClient):

MESSAGES_MODULE = messages
BASE_URL = u'https://www.googleapis.com/fusiontables/v1/'
MTLS_BASE_URL = u''

_PACKAGE = u'fusiontables'
_SCOPES = [u'https://www.googleapis.com/auth/fusiontables', u'https://www.googleapis.com/auth/fusiontables.readonly']
Expand Down
1 change: 1 addition & 0 deletions samples/iam_sample/iam_v1/iam_v1_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class IamV1(base_api.BaseApiClient):

MESSAGES_MODULE = messages
BASE_URL = u'https://iam.googleapis.com/'
MTLS_BASE_URL = u''

_PACKAGE = u'iam'
_SCOPES = [u'https://www.googleapis.com/auth/cloud-platform']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ServicemanagementV1(base_api.BaseApiClient):

MESSAGES_MODULE = messages
BASE_URL = u'https://servicemanagement.googleapis.com/'
MTLS_BASE_URL = u''

_PACKAGE = u'servicemanagement'
_SCOPES = [u'https://www.googleapis.com/auth/cloud-platform', u'https://www.googleapis.com/auth/service.management']
Expand Down
1 change: 1 addition & 0 deletions samples/storage_sample/storage_v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"baseUrl": "https://www.googleapis.com/storage/v1/",
"basePath": "/storage/v1/",
"rootUrl": "https://www.googleapis.com/",
"mtlsRootUrl": "https://www.mtls.googleapis.com/",
"servicePath": "storage/v1/",
"batchPath": "batch/storage/v1",
"parameters": {
Expand Down
1 change: 1 addition & 0 deletions samples/storage_sample/storage_v1/storage_v1_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class StorageV1(base_api.BaseApiClient):

MESSAGES_MODULE = messages
BASE_URL = u'https://www.googleapis.com/storage/v1/'
MTLS_BASE_URL = u'https://www.mtls.googleapis.com/storage/v1/'

_PACKAGE = u'storage'
_SCOPES = [u'https://www.googleapis.com/auth/cloud-platform', u'https://www.googleapis.com/auth/cloud-platform.read-only', u'https://www.googleapis.com/auth/devstorage.full_control', u'https://www.googleapis.com/auth/devstorage.read_only', u'https://www.googleapis.com/auth/devstorage.read_write']
Expand Down