defget_real_collection_name(self,collection_name:str,api_version:Optional[str]=None,force_actual_name:bool=False)->str:"""Returns the actual under the hood collection name. Args: collection_name: Name to check. api_version: If None, default is "2019-11-01-preview". force_actual_name: Edge case. If True, will check if the actual name is the name passed in. Useful if there are multiple friendly names. Returns: The actual name of the collection. Raises: If the collection doesn't exist, will raise an error that no collection exists. If multiple friendly names exist, will raise an error listing the multiple friendly names. """ifnotapi_version:api_version=self.collections_api_versioncollections=self.list_collections(only_names=True,api_version=api_version)friendly_names=[(name,collections[name])forname,valueincollections.items()ifcollection_name==value["friendlyName"]]ifcollection_namenotincollectionsandlen(friendly_names)==0:err_msg=("collection_name parameter value error. "f"The collection '{collection_name}' either doesn't exist or your don't have permission to start on it. ""If you're trying to create a child collection, would need to be a collection admin on that collection ""if it exists. Name is case sensitive.")raiseValueError(err_msg)elifcollection_namenotincollectionsandlen(friendly_names)==1:returnfriendly_names[0][0]elifcollection_nameincollectionsandlen(friendly_names)<=1:returncollection_nameifforce_actual_name:foriinrange(len(friendly_names)):iffriendly_names[i][0]==collection_name:returncollection_nameelse:multiple_friendly_names=[]foriteminfriendly_names:parent_name=item[1]["parentCollection"]parent_friendly_name=collections[parent_name]["friendlyName"]friendly_output=f"{item[0]}: [collection info: actual_name: {item[0]}, friendlyName: {item[1]['friendlyName']}, parentCollection: {parent_friendly_name}]"multiple_friendly_names.append(friendly_output)newline="\n"err_msg=(f"Multiple collections exist with the friendly name '{collection_name}'. "f"Please choose and re-enter the first item from one of the options below in place of '{collection_name}': "f"{newline}{newline.join(map(str,multiple_friendly_names))}{newline}"f"If you want to use the collection name '{collection_name}' and it's listed as an option above as "f"a first item (actual_name), add the force_actual_name parameter to True. ""Ex: force_actual_name=True")raiseValueError(err_msg)
Examples
Pass in either an actual or friendly collection name (For more info on what actual and friendly names mean, see: Purview Names Overview). The code will return one of the following:
The actual name of the collection (if it exists)
A friendly error stating that the collection doesn't exist (if there's no collection by that name)
If passing in a friendly name and multiple friendly names exist, an error will return displaying the multiple friendly names in order to choose which to use
For example, if the Purview collections look like this:
To return the actual name of test 1:
print(client.get_real_collection_name("test 1"))
Will output the actual name of the collection. In this example, it would output: mojpnk.