def collect_apis(): """Collect names and current versions of all the Google APIs.""" context = ExecutionContext() agent = GcpAgent.make_agent(api='discovery', version='v1') apis = agent.list_resource(context, 'apis') catalog = {} for entry in apis: preferred = entry.get('preferred', True) if not preferred: continue catalog[entry['name']] = entry['version'] return catalog
def make_agent(self, api, version, default_scope, default_variables=None): """Construct an agent to talk to a Google API. Args: api: [string] The API name containing the resources. version: [string] The API version. default_scope: [string] The oauth scope to use if options.credentials_path """ credentials = self.__options.credentials_path or None default_variables = default_variables or self.__default_variables scope_list = [default_scope] if credentials else None return GcpAgent.make_agent( api=api, version=version, scopes=scope_list, credentials_path=credentials, default_variables=default_variables)
def _gcp_agent_singleton(**kwargs): """Manage singleton of agents to particular apis. This treates the agent instances as singletons based on their configuration. The reason for this is simply to reduce logging noise on the creation. This is possible since agents are stateless. Args: kargs: [kwargs] Arguments to GcpAgent.make_agent """ # pylint: disable=global-statement global __AGENT_CACHE key = str(kwargs) if key not in __AGENT_CACHE: __AGENT_CACHE[key] = GcpAgent.make_agent(**kwargs) return __AGENT_CACHE[key]
def collect_apis(): """Collect names and current versions of all the Google APIs.""" if ApiInvestigator.__api_version_map: return ApiInvestigator.__api_version_map context = ExecutionContext() agent = GcpAgent.make_agent(api='discovery', version='v1') apis = agent.list_resource(context, 'apis') catalog = {} for entry in apis: preferred = entry.get('preferred', True) if not preferred: continue catalog[entry['name']] = entry['version'] ApiInvestigator.__api_version_map = catalog return catalog