aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChaoren <chaorenkindle@gmail.com>2020-02-13 11:26:54 -0500
committerGitHub <noreply@github.com>2020-02-13 11:26:54 -0500
commit9659f282c58138900db6b4dcbfd9d3bb2096717a (patch)
tree0b2d3b2a426302ac7bfdb69c04db7b31ccbb0ebe
parentbf0261315f5d4eded86b80303b4f363657d43994 (diff)
downloadapitools-9659f282c58138900db6b4dcbfd9d3bb2096717a.tar.gz
Client generation can handle the mtlsRootUrl (#288)
-rw-r--r--apitools/gen/service_registry.py1
-rw-r--r--apitools/gen/util.py31
-rw-r--r--samples/bigquery_sample/bigquery_v2/bigquery_v2_client.py1
-rw-r--r--samples/dns_sample/dns_v1/dns_v1_client.py1
-rw-r--r--samples/fusiontables_sample/fusiontables_v1/fusiontables_v1_client.py1
-rw-r--r--samples/iam_sample/iam_v1/iam_v1_client.py1
-rw-r--r--samples/servicemanagement_sample/servicemanagement_v1/servicemanagement_v1_client.py1
-rw-r--r--samples/storage_sample/storage_v1.json1
-rw-r--r--samples/storage_sample/storage_v1/storage_v1_client.py1
9 files changed, 34 insertions, 5 deletions
diff --git a/apitools/gen/service_registry.py b/apitools/gen/service_registry.py
index e47b050..b79f0d1 100644
--- a/apitools/gen/service_registry.py
+++ b/apitools/gen/service_registry.py
@@ -218,6 +218,7 @@ class ServiceRegistry(object):
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 78a32f6..2dbf25e 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 @@ class ClientInfo(collections.namedtuple('ClientInfo', (
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 @@ class ClientInfo(collections.namedtuple('ClientInfo', (
'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 e6cf9c8..90552da 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 ce3aff6..0666460 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 f80fb3e..b7b6c43 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 9f333ef..ed9112e 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 a72936e..25823db 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 2636bda..cfd2748 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 38ceab9..4a8414a 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']