diff --git a/apitools/gen/service_registry.py b/apitools/gen/service_registry.py index e47b0505..b79f0d12 100644 --- a/apitools/gen/service_registry.py +++ b/apitools/gen/service_registry.py @@ -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( diff --git a/apitools/gen/util.py b/apitools/gen/util.py index 78a32f63..2dbf25e0 100644 --- a/apitools/gen/util.py +++ b/apitools/gen/util.py @@ -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): + """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, '' @@ -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.""" @@ -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, @@ -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']), diff --git a/samples/bigquery_sample/bigquery_v2/bigquery_v2_client.py b/samples/bigquery_sample/bigquery_v2/bigquery_v2_client.py index e6cf9c8e..90552dac 100644 --- a/samples/bigquery_sample/bigquery_v2/bigquery_v2_client.py +++ b/samples/bigquery_sample/bigquery_v2/bigquery_v2_client.py @@ -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'] diff --git a/samples/dns_sample/dns_v1/dns_v1_client.py b/samples/dns_sample/dns_v1/dns_v1_client.py index ce3aff6d..06664603 100644 --- a/samples/dns_sample/dns_v1/dns_v1_client.py +++ b/samples/dns_sample/dns_v1/dns_v1_client.py @@ -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'] diff --git a/samples/fusiontables_sample/fusiontables_v1/fusiontables_v1_client.py b/samples/fusiontables_sample/fusiontables_v1/fusiontables_v1_client.py index f80fb3e1..b7b6c43e 100644 --- a/samples/fusiontables_sample/fusiontables_v1/fusiontables_v1_client.py +++ b/samples/fusiontables_sample/fusiontables_v1/fusiontables_v1_client.py @@ -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'] diff --git a/samples/iam_sample/iam_v1/iam_v1_client.py b/samples/iam_sample/iam_v1/iam_v1_client.py index 9f333ef0..ed9112eb 100644 --- a/samples/iam_sample/iam_v1/iam_v1_client.py +++ b/samples/iam_sample/iam_v1/iam_v1_client.py @@ -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'] diff --git a/samples/servicemanagement_sample/servicemanagement_v1/servicemanagement_v1_client.py b/samples/servicemanagement_sample/servicemanagement_v1/servicemanagement_v1_client.py index a72936e5..25823db0 100644 --- a/samples/servicemanagement_sample/servicemanagement_v1/servicemanagement_v1_client.py +++ b/samples/servicemanagement_sample/servicemanagement_v1/servicemanagement_v1_client.py @@ -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'] diff --git a/samples/storage_sample/storage_v1.json b/samples/storage_sample/storage_v1.json index 2636bda1..cfd27489 100644 --- a/samples/storage_sample/storage_v1.json +++ b/samples/storage_sample/storage_v1.json @@ -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": { diff --git a/samples/storage_sample/storage_v1/storage_v1_client.py b/samples/storage_sample/storage_v1/storage_v1_client.py index 38ceab91..4a8414ab 100644 --- a/samples/storage_sample/storage_v1/storage_v1_client.py +++ b/samples/storage_sample/storage_v1/storage_v1_client.py @@ -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']