in client/python/cli/command/catalogs.py [0:0]
def execute(self, api: PolarisDefaultApi) -> None:
if self.catalogs_subcommand == Subcommands.CREATE:
config = self._build_storage_config_info()
if self.catalog_type == CatalogType.EXTERNAL.value:
request = CreateCatalogRequest(
catalog=ExternalCatalog(
type=self.catalog_type.upper(),
name=self.catalog_name,
storage_config_info=config,
remote_url=self.remote_url,
properties=CatalogProperties(
default_base_location=self.default_base_location,
additional_properties=self.properties
)
)
)
else:
request = CreateCatalogRequest(
catalog=PolarisCatalog(
type=self.catalog_type.upper(),
name=self.catalog_name,
storage_config_info=config,
properties=CatalogProperties(
default_base_location=self.default_base_location,
additional_properties=self.properties
)
)
)
api.create_catalog(request)
elif self.catalogs_subcommand == Subcommands.DELETE:
api.delete_catalog(self.catalog_name)
elif self.catalogs_subcommand == Subcommands.GET:
print(api.get_catalog(self.catalog_name).to_json())
elif self.catalogs_subcommand == Subcommands.LIST:
for catalog in api.list_catalogs().catalogs:
print(catalog.to_json())
elif self.catalogs_subcommand == Subcommands.UPDATE:
catalog = api.get_catalog(self.catalog_name)
if self.default_base_location or self.set_properties or self.remove_properties:
new_default_base_location = self.default_base_location or catalog.properties.default_base_location
new_additional_properties = catalog.properties.additional_properties or {}
# Add or update all entries specified in set_properties
if self.set_properties:
new_additional_properties = {**new_additional_properties, **self.set_properties}
# Remove all keys specified in remove_properties
if self.remove_properties:
for to_remove in self.remove_properties:
new_additional_properties.pop(to_remove, None)
catalog.properties = CatalogProperties(
default_base_location=new_default_base_location,
additional_properties=new_additional_properties
)
if (self._has_aws_storage_info() or self._has_azure_storage_info() or
self._has_gcs_storage_info() or self.allowed_locations):
# We must first reconstitute local storage-config related settings from the existing
# catalog to properly construct the complete updated storage-config
updated_storage_info = catalog.storage_config_info
# In order to apply mutations client-side, we can't just use the base
# _build_storage_config_info helper; instead, each allowed updatable field defined
# in option_tree.py should be applied individually against the existing
# storage_config_info here.
if self.allowed_locations:
updated_storage_info.allowed_locations.extend(self.allowed_locations)
if self.region:
# Note: We have to lowercase the returned value because the server enum
# is uppercase but we defined the StorageType enums as lowercase.
storage_type = updated_storage_info.storage_type
if storage_type.lower() != StorageType.S3.value:
raise Exception(
f'--region requires S3 storage_type, got: {storage_type}')
updated_storage_info.region = self.region
request = UpdateCatalogRequest(
current_entity_version=catalog.entity_version,
properties=catalog.properties.to_dict(),
storage_config_info=updated_storage_info
)
else:
request = UpdateCatalogRequest(
current_entity_version=catalog.entity_version,
properties=catalog.properties.to_dict()
)
api.update_catalog(self.catalog_name, request)
else:
raise Exception(f'{self.catalogs_subcommand} is not supported in the CLI')