Skip to content

Commit

Permalink
Merge 460a7ed into bf02613
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchaoren committed Feb 10, 2020
2 parents bf02613 + 460a7ed commit 10a4259
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 5 deletions.
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
18 changes: 13 additions & 5 deletions apitools/gen/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,8 @@ 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):
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 +186,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 +200,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 +221,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

0 comments on commit 10a4259

Please sign in to comment.