@@ -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):
187199class 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' ]),
0 commit comments