import os from googleapiclient.discovery import build import httplib2 httplib2.debuglevel = 4 def get_cert_files(): return (os.environ.get('GOOGLE_API_CLIENT_CERTIFICATE'), os.environ.get('GOOGLE_API_CLIENT_PRIVATE_KEY'), None) def getClientOptions(): client_options = {} if os.environ.get('GOOGLE_API_CLIENT_CERTIFICATE') and \ os.environ.get('GOOGLE_API_CLIENT_PRIVATE_KEY'): client_options['client_encrypted_cert_source'] = get_cert_files return client_options def print_result(request_id, response, exception): if exception is not None: # Seems to happen for fuschia which is no longer valid pass else: versions = response['versions'] if versions: name = versions[0].get('name') if name: product, _, platform, _, channel, _, version = name.split('/') print(f'The latest {channel} version of {product} on {platform} is {version}') # Force some environment variables os.environ['GOOGLE_API_USE_CLIENT_CERTIFICATE'] = 'true' os.environ['GOOGLE_API_USE_MTLS_ENDPOINT'] = 'always' os.environ['GOOGLE_API_CLIENT_CERTIFICATE'] = 'client1.pem' os.environ['GOOGLE_API_CLIENT_PRIVATE_KEY'] = 'client1.key' product = 'chrome' channel = 'stable' httpc = httplib2.Http() client_options = getClientOptions() srv = build('versionhistory', 'v1', http=httpc, client_options=client_options, ) results = srv.platforms().list(parent=product).execute() platforms = [p['platformType'].lower() for p in results['platforms']] vbatch = srv.new_batch_http_request(callback=print_result) for platform in platforms: parent = f'{product}/platforms/{platform}/channels/{channel}' vbatch.add(srv.platforms().channels().versions().list(parent=parent, pageSize=1)) vbatch.execute()