Skip to content

Commit 9659f28

Browse files
authored
Client generation can handle the mtlsRootUrl (#288)
1 parent bf02613 commit 9659f28

9 files changed

Lines changed: 34 additions & 5 deletions

File tree

apitools/gen/service_registry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ def WriteFile(self, printer):
218218
printer()
219219
printer('MESSAGES_MODULE = messages')
220220
printer('BASE_URL = {0!r}'.format(client_info.base_url))
221+
printer('MTLS_BASE_URL = {0!r}'.format(client_info.mtls_base_url))
221222
printer()
222223
printer('_PACKAGE = {0!r}'.format(client_info.package))
223224
printer('_SCOPES = {0!r}'.format(

apitools/gen/util.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,21 @@ def NormalizeVersion(version):
174174
return version.replace('.', '_')
175175

176176

177-
def _ComputePaths(package, version, discovery_doc):
178-
full_path = urllib_parse.urljoin(
179-
discovery_doc['rootUrl'], discovery_doc['servicePath'])
177+
def _ComputePaths(package, version, root_url, service_path):
178+
"""Compute the base url and base path.
179+
180+
Attributes:
181+
package: name field of the discovery, i.e. 'storage' for storage service.
182+
version: version of the service, i.e. 'v1'.
183+
root_url: root url of the service, i.e. 'https://www.googleapis.com/'.
184+
service_path: path of the service under the rool url, i.e. 'storage/v1/'.
185+
186+
Returns:
187+
base url: string, base url of the service,
188+
'https://www.googleapis.com/storage/v1/' for the storage service.
189+
base path: string, common prefix of service endpoints after the base url.
190+
"""
191+
full_path = urllib_parse.urljoin(root_url, service_path)
180192
api_path_component = '/'.join((package, version, ''))
181193
if api_path_component not in full_path:
182194
return full_path, ''
@@ -187,7 +199,7 @@ def _ComputePaths(package, version, discovery_doc):
187199
class ClientInfo(collections.namedtuple('ClientInfo', (
188200
'package', 'scopes', 'version', 'client_id', 'client_secret',
189201
'user_agent', 'client_class_name', 'url_version', 'api_key',
190-
'base_url', 'base_path'))):
202+
'base_url', 'base_path', 'mtls_base_url'))):
191203

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

@@ -201,7 +213,15 @@ def Create(cls, discovery_doc,
201213
package = discovery_doc['name']
202214
url_version = discovery_doc['version']
203215
base_url, base_path = _ComputePaths(package, url_version,
204-
discovery_doc)
216+
discovery_doc['rootUrl'],
217+
discovery_doc['servicePath'])
218+
219+
mtls_root_url = discovery_doc.get('mtlsRootUrl', '')
220+
mtls_base_url = ''
221+
if mtls_root_url:
222+
mtls_base_url, _ = _ComputePaths(package, url_version,
223+
mtls_root_url,
224+
discovery_doc['servicePath'])
205225

206226
client_info = {
207227
'package': package,
@@ -214,6 +234,7 @@ def Create(cls, discovery_doc,
214234
'api_key': api_key,
215235
'base_url': base_url,
216236
'base_path': base_path,
237+
'mtls_base_url': mtls_base_url,
217238
}
218239
client_class_name = '%s%s' % (
219240
names.ClassName(client_info['package']),

samples/bigquery_sample/bigquery_v2/bigquery_v2_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class BigqueryV2(base_api.BaseApiClient):
99

1010
MESSAGES_MODULE = messages
1111
BASE_URL = u'https://www.googleapis.com/bigquery/v2/'
12+
MTLS_BASE_URL = u''
1213

1314
_PACKAGE = u'bigquery'
1415
_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']

samples/dns_sample/dns_v1/dns_v1_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class DnsV1(base_api.BaseApiClient):
99

1010
MESSAGES_MODULE = messages
1111
BASE_URL = u'https://www.googleapis.com/dns/v1/'
12+
MTLS_BASE_URL = u''
1213

1314
_PACKAGE = u'dns'
1415
_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']

samples/fusiontables_sample/fusiontables_v1/fusiontables_v1_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class FusiontablesV1(base_api.BaseApiClient):
99

1010
MESSAGES_MODULE = messages
1111
BASE_URL = u'https://www.googleapis.com/fusiontables/v1/'
12+
MTLS_BASE_URL = u''
1213

1314
_PACKAGE = u'fusiontables'
1415
_SCOPES = [u'https://www.googleapis.com/auth/fusiontables', u'https://www.googleapis.com/auth/fusiontables.readonly']

samples/iam_sample/iam_v1/iam_v1_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class IamV1(base_api.BaseApiClient):
99

1010
MESSAGES_MODULE = messages
1111
BASE_URL = u'https://iam.googleapis.com/'
12+
MTLS_BASE_URL = u''
1213

1314
_PACKAGE = u'iam'
1415
_SCOPES = [u'https://www.googleapis.com/auth/cloud-platform']

samples/servicemanagement_sample/servicemanagement_v1/servicemanagement_v1_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ServicemanagementV1(base_api.BaseApiClient):
99

1010
MESSAGES_MODULE = messages
1111
BASE_URL = u'https://servicemanagement.googleapis.com/'
12+
MTLS_BASE_URL = u''
1213

1314
_PACKAGE = u'servicemanagement'
1415
_SCOPES = [u'https://www.googleapis.com/auth/cloud-platform', u'https://www.googleapis.com/auth/service.management']

samples/storage_sample/storage_v1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"baseUrl": "https://www.googleapis.com/storage/v1/",
2222
"basePath": "/storage/v1/",
2323
"rootUrl": "https://www.googleapis.com/",
24+
"mtlsRootUrl": "https://www.mtls.googleapis.com/",
2425
"servicePath": "storage/v1/",
2526
"batchPath": "batch/storage/v1",
2627
"parameters": {

samples/storage_sample/storage_v1/storage_v1_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class StorageV1(base_api.BaseApiClient):
99

1010
MESSAGES_MODULE = messages
1111
BASE_URL = u'https://www.googleapis.com/storage/v1/'
12+
MTLS_BASE_URL = u'https://www.mtls.googleapis.com/storage/v1/'
1213

1314
_PACKAGE = u'storage'
1415
_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']

0 commit comments

Comments
 (0)