def _MatchCollection(resource_spec, attribute): """Gets the collection for an attribute in a resource.""" resource_collection_info = resource_spec._collection_info # pylint: disable=protected-access resource_collection = registry.APICollection(resource_collection_info) if resource_collection is None: return None if attribute == resource_spec.attributes[-1]: return resource_collection.name attribute_idx = resource_spec.attributes.index(attribute) api_name = resource_collection_info.api_name resource_collections = registry.GetAPICollections( api_name, resource_collection_info.api_version) params = resource_collection.detailed_params[:attribute_idx + 1] for c in resource_collections: if c.detailed_params == params: return c.name
def get_collection_names(api_name, api_versions): """Gets collection names for all collections in each specified version. Args: api_name: Name of the API to return collection names for. api_versions: Desired api versions to return collections for. Returns: collection_names: Names of every registered apitools collection. """ collection_names = set() for version in api_versions: resource_collections = [ registry.APICollection(c) for c in apis_internal._GetApiCollections(api_name, version) # pylint:disable=protected-access ] for resource_collection in resource_collections: collection_names.add(resource_collection.name) return collection_names
def get_collection_to_apis_dict(self, api_name, api_versions): """Gets collection names for all collections in all versions of an api. Args: api_name: Name of the api to be added. api_versions: All registered versions of the api. Returns: collction_names: Names of every registered apitools collection. """ collection_to_apis_dict = {} for version in api_versions: resource_collections = [ registry.APICollection(c) for c in apis_internal._GetApiCollections(api_name, version) # pylint:disable=protected-access ] for resource_collection in resource_collections: if resource_collection.name in collection_to_apis_dict: collection_to_apis_dict[resource_collection.name].append(version) else: collection_to_apis_dict[resource_collection.name] = [version] return collection_to_apis_dict