apache-polaris 1.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- apache_polaris/__init__.py +19 -0
- apache_polaris/cli/__init__.py +18 -0
- apache_polaris/cli/api_client_builder.py +191 -0
- apache_polaris/cli/command/__init__.py +242 -0
- apache_polaris/cli/command/catalog_roles.py +128 -0
- apache_polaris/cli/command/catalogs.py +491 -0
- apache_polaris/cli/command/namespaces.py +90 -0
- apache_polaris/cli/command/policies.py +226 -0
- apache_polaris/cli/command/principal_roles.py +124 -0
- apache_polaris/cli/command/principals.py +197 -0
- apache_polaris/cli/command/privileges.py +150 -0
- apache_polaris/cli/command/profiles.py +172 -0
- apache_polaris/cli/command/setup.py +1386 -0
- apache_polaris/cli/command/utils.py +52 -0
- apache_polaris/cli/constants.py +437 -0
- apache_polaris/cli/options/__init__.py +18 -0
- apache_polaris/cli/options/option_tree.py +916 -0
- apache_polaris/cli/options/parser.py +255 -0
- apache_polaris/cli/polaris_cli.py +126 -0
- apache_polaris/sdk/__init__.py +19 -0
- apache_polaris/sdk/catalog/.keep +0 -0
- apache_polaris/sdk/catalog/__init__.py +184 -0
- apache_polaris/sdk/catalog/api/.keep +0 -0
- apache_polaris/sdk/catalog/api/__init__.py +26 -0
- apache_polaris/sdk/catalog/api/catalog_api.py +8211 -0
- apache_polaris/sdk/catalog/api/configuration_api.py +340 -0
- apache_polaris/sdk/catalog/api/generic_table_api.py +1335 -0
- apache_polaris/sdk/catalog/api/iceberg_catalog_api.py +9215 -0
- apache_polaris/sdk/catalog/api/iceberg_configuration_api.py +340 -0
- apache_polaris/sdk/catalog/api/iceberg_o_auth2_api.py +466 -0
- apache_polaris/sdk/catalog/api/o_auth2_api.py +480 -0
- apache_polaris/sdk/catalog/api/policy_api.py +2758 -0
- apache_polaris/sdk/catalog/api_client.py +816 -0
- apache_polaris/sdk/catalog/api_response.py +40 -0
- apache_polaris/sdk/catalog/configuration.py +644 -0
- apache_polaris/sdk/catalog/exceptions.py +235 -0
- apache_polaris/sdk/catalog/models/.keep +0 -0
- apache_polaris/sdk/catalog/models/__init__.py +169 -0
- apache_polaris/sdk/catalog/models/add_encryption_key_update.py +109 -0
- apache_polaris/sdk/catalog/models/add_partition_spec_update.py +109 -0
- apache_polaris/sdk/catalog/models/add_schema_update.py +110 -0
- apache_polaris/sdk/catalog/models/add_snapshot_update.py +109 -0
- apache_polaris/sdk/catalog/models/add_sort_order_update.py +109 -0
- apache_polaris/sdk/catalog/models/add_view_version_update.py +109 -0
- apache_polaris/sdk/catalog/models/and_or_expression.py +119 -0
- apache_polaris/sdk/catalog/models/applicable_policy.py +128 -0
- apache_polaris/sdk/catalog/models/assert_create.py +107 -0
- apache_polaris/sdk/catalog/models/assert_current_schema_id.py +108 -0
- apache_polaris/sdk/catalog/models/assert_default_sort_order_id.py +108 -0
- apache_polaris/sdk/catalog/models/assert_default_spec_id.py +108 -0
- apache_polaris/sdk/catalog/models/assert_last_assigned_field_id.py +108 -0
- apache_polaris/sdk/catalog/models/assert_last_assigned_partition_id.py +108 -0
- apache_polaris/sdk/catalog/models/assert_ref_snapshot_id.py +109 -0
- apache_polaris/sdk/catalog/models/assert_table_uuid.py +108 -0
- apache_polaris/sdk/catalog/models/assert_view_uuid.py +115 -0
- apache_polaris/sdk/catalog/models/assign_uuid_update.py +108 -0
- apache_polaris/sdk/catalog/models/async_planning_result.py +109 -0
- apache_polaris/sdk/catalog/models/attach_policy_request.py +112 -0
- apache_polaris/sdk/catalog/models/base_update.py +198 -0
- apache_polaris/sdk/catalog/models/blob_metadata.py +114 -0
- apache_polaris/sdk/catalog/models/catalog_config.py +110 -0
- apache_polaris/sdk/catalog/models/commit_report.py +129 -0
- apache_polaris/sdk/catalog/models/commit_table_request.py +130 -0
- apache_polaris/sdk/catalog/models/commit_table_response.py +112 -0
- apache_polaris/sdk/catalog/models/commit_transaction_request.py +114 -0
- apache_polaris/sdk/catalog/models/commit_view_request.py +130 -0
- apache_polaris/sdk/catalog/models/completed_planning_result.py +129 -0
- apache_polaris/sdk/catalog/models/completed_planning_with_id_result.py +131 -0
- apache_polaris/sdk/catalog/models/content_file.py +150 -0
- apache_polaris/sdk/catalog/models/count_map.py +108 -0
- apache_polaris/sdk/catalog/models/counter_result.py +108 -0
- apache_polaris/sdk/catalog/models/create_generic_table_request.py +114 -0
- apache_polaris/sdk/catalog/models/create_namespace_request.py +108 -0
- apache_polaris/sdk/catalog/models/create_namespace_response.py +108 -0
- apache_polaris/sdk/catalog/models/create_policy_request.py +120 -0
- apache_polaris/sdk/catalog/models/create_table_request.py +130 -0
- apache_polaris/sdk/catalog/models/create_view_request.py +122 -0
- apache_polaris/sdk/catalog/models/data_file.py +134 -0
- apache_polaris/sdk/catalog/models/delete_file.py +159 -0
- apache_polaris/sdk/catalog/models/detach_policy_request.py +110 -0
- apache_polaris/sdk/catalog/models/empty_planning_result.py +113 -0
- apache_polaris/sdk/catalog/models/encrypted_key.py +112 -0
- apache_polaris/sdk/catalog/models/equality_delete_file.py +126 -0
- apache_polaris/sdk/catalog/models/error_model.py +113 -0
- apache_polaris/sdk/catalog/models/expression.py +228 -0
- apache_polaris/sdk/catalog/models/failed_planning_result.py +113 -0
- apache_polaris/sdk/catalog/models/false_expression.py +106 -0
- apache_polaris/sdk/catalog/models/fetch_planning_result.py +173 -0
- apache_polaris/sdk/catalog/models/fetch_scan_tasks_request.py +106 -0
- apache_polaris/sdk/catalog/models/fetch_scan_tasks_result.py +126 -0
- apache_polaris/sdk/catalog/models/file_format.py +58 -0
- apache_polaris/sdk/catalog/models/file_scan_task.py +118 -0
- apache_polaris/sdk/catalog/models/generic_table.py +114 -0
- apache_polaris/sdk/catalog/models/get_applicable_policies_response.py +121 -0
- apache_polaris/sdk/catalog/models/get_namespace_response.py +108 -0
- apache_polaris/sdk/catalog/models/iceberg_error_response.py +110 -0
- apache_polaris/sdk/catalog/models/iceberg_error_response1.py +110 -0
- apache_polaris/sdk/catalog/models/list_generic_tables_response.py +121 -0
- apache_polaris/sdk/catalog/models/list_namespaces_response.py +108 -0
- apache_polaris/sdk/catalog/models/list_policies_response.py +121 -0
- apache_polaris/sdk/catalog/models/list_tables_response.py +116 -0
- apache_polaris/sdk/catalog/models/list_type.py +125 -0
- apache_polaris/sdk/catalog/models/literal_expression.py +114 -0
- apache_polaris/sdk/catalog/models/load_credentials_response.py +114 -0
- apache_polaris/sdk/catalog/models/load_generic_table_response.py +120 -0
- apache_polaris/sdk/catalog/models/load_policy_response.py +110 -0
- apache_polaris/sdk/catalog/models/load_table_result.py +124 -0
- apache_polaris/sdk/catalog/models/load_view_result.py +114 -0
- apache_polaris/sdk/catalog/models/map_type.py +132 -0
- apache_polaris/sdk/catalog/models/metadata_log_inner.py +108 -0
- apache_polaris/sdk/catalog/models/metric_result.py +153 -0
- apache_polaris/sdk/catalog/models/model_schema.py +129 -0
- apache_polaris/sdk/catalog/models/not_expression.py +114 -0
- apache_polaris/sdk/catalog/models/notification_request.py +113 -0
- apache_polaris/sdk/catalog/models/notification_type.py +59 -0
- apache_polaris/sdk/catalog/models/null_order.py +56 -0
- apache_polaris/sdk/catalog/models/o_auth_error.py +117 -0
- apache_polaris/sdk/catalog/models/o_auth_token_response.py +124 -0
- apache_polaris/sdk/catalog/models/partition_field.py +112 -0
- apache_polaris/sdk/catalog/models/partition_spec.py +118 -0
- apache_polaris/sdk/catalog/models/partition_statistics_file.py +110 -0
- apache_polaris/sdk/catalog/models/plan_status.py +58 -0
- apache_polaris/sdk/catalog/models/plan_table_scan_request.py +124 -0
- apache_polaris/sdk/catalog/models/plan_table_scan_result.py +187 -0
- apache_polaris/sdk/catalog/models/policy.py +124 -0
- apache_polaris/sdk/catalog/models/policy_attachment_target.py +115 -0
- apache_polaris/sdk/catalog/models/policy_identifier.py +108 -0
- apache_polaris/sdk/catalog/models/position_delete_file.py +127 -0
- apache_polaris/sdk/catalog/models/primitive_type_value.py +402 -0
- apache_polaris/sdk/catalog/models/register_table_request.py +110 -0
- apache_polaris/sdk/catalog/models/remove_encryption_key_update.py +108 -0
- apache_polaris/sdk/catalog/models/remove_partition_specs_update.py +108 -0
- apache_polaris/sdk/catalog/models/remove_partition_statistics_update.py +108 -0
- apache_polaris/sdk/catalog/models/remove_properties_update.py +108 -0
- apache_polaris/sdk/catalog/models/remove_schemas_update.py +108 -0
- apache_polaris/sdk/catalog/models/remove_snapshot_ref_update.py +108 -0
- apache_polaris/sdk/catalog/models/remove_snapshots_update.py +108 -0
- apache_polaris/sdk/catalog/models/remove_statistics_update.py +108 -0
- apache_polaris/sdk/catalog/models/rename_table_request.py +115 -0
- apache_polaris/sdk/catalog/models/report_metrics_request.py +153 -0
- apache_polaris/sdk/catalog/models/scan_report.py +137 -0
- apache_polaris/sdk/catalog/models/scan_tasks.py +126 -0
- apache_polaris/sdk/catalog/models/set_current_schema_update.py +108 -0
- apache_polaris/sdk/catalog/models/set_current_view_version_update.py +108 -0
- apache_polaris/sdk/catalog/models/set_default_sort_order_update.py +108 -0
- apache_polaris/sdk/catalog/models/set_default_spec_update.py +108 -0
- apache_polaris/sdk/catalog/models/set_expression.py +114 -0
- apache_polaris/sdk/catalog/models/set_location_update.py +108 -0
- apache_polaris/sdk/catalog/models/set_partition_statistics_update.py +109 -0
- apache_polaris/sdk/catalog/models/set_properties_update.py +108 -0
- apache_polaris/sdk/catalog/models/set_snapshot_ref_update.py +125 -0
- apache_polaris/sdk/catalog/models/set_statistics_update.py +110 -0
- apache_polaris/sdk/catalog/models/snapshot.py +124 -0
- apache_polaris/sdk/catalog/models/snapshot_log_inner.py +108 -0
- apache_polaris/sdk/catalog/models/snapshot_reference.py +121 -0
- apache_polaris/sdk/catalog/models/snapshot_summary.py +126 -0
- apache_polaris/sdk/catalog/models/sort_direction.py +56 -0
- apache_polaris/sdk/catalog/models/sort_field.py +114 -0
- apache_polaris/sdk/catalog/models/sort_order.py +118 -0
- apache_polaris/sdk/catalog/models/sql_view_representation.py +110 -0
- apache_polaris/sdk/catalog/models/statistics_file.py +122 -0
- apache_polaris/sdk/catalog/models/storage_access_config.py +108 -0
- apache_polaris/sdk/catalog/models/storage_credential.py +108 -0
- apache_polaris/sdk/catalog/models/struct_field.py +131 -0
- apache_polaris/sdk/catalog/models/struct_type.py +125 -0
- apache_polaris/sdk/catalog/models/table_identifier.py +108 -0
- apache_polaris/sdk/catalog/models/table_metadata.py +236 -0
- apache_polaris/sdk/catalog/models/table_requirement.py +147 -0
- apache_polaris/sdk/catalog/models/table_update.py +441 -0
- apache_polaris/sdk/catalog/models/table_update_notification.py +118 -0
- apache_polaris/sdk/catalog/models/term.py +159 -0
- apache_polaris/sdk/catalog/models/timer_result.py +110 -0
- apache_polaris/sdk/catalog/models/token_type.py +60 -0
- apache_polaris/sdk/catalog/models/transform_term.py +117 -0
- apache_polaris/sdk/catalog/models/true_expression.py +106 -0
- apache_polaris/sdk/catalog/models/type.py +189 -0
- apache_polaris/sdk/catalog/models/unary_expression.py +114 -0
- apache_polaris/sdk/catalog/models/update_namespace_properties_request.py +108 -0
- apache_polaris/sdk/catalog/models/update_namespace_properties_response.py +110 -0
- apache_polaris/sdk/catalog/models/update_policy_request.py +110 -0
- apache_polaris/sdk/catalog/models/upgrade_format_version_update.py +108 -0
- apache_polaris/sdk/catalog/models/value_map.py +116 -0
- apache_polaris/sdk/catalog/models/view_history_entry.py +108 -0
- apache_polaris/sdk/catalog/models/view_metadata.py +145 -0
- apache_polaris/sdk/catalog/models/view_representation.py +142 -0
- apache_polaris/sdk/catalog/models/view_requirement.py +145 -0
- apache_polaris/sdk/catalog/models/view_update.py +246 -0
- apache_polaris/sdk/catalog/models/view_version.py +126 -0
- apache_polaris/sdk/catalog/rest.py +277 -0
- apache_polaris/sdk/management/.keep +0 -0
- apache_polaris/sdk/management/__init__.py +106 -0
- apache_polaris/sdk/management/api/.keep +0 -0
- apache_polaris/sdk/management/api/__init__.py +24 -0
- apache_polaris/sdk/management/api/polaris_default_api.py +9283 -0
- apache_polaris/sdk/management/api_client.py +816 -0
- apache_polaris/sdk/management/api_response.py +40 -0
- apache_polaris/sdk/management/configuration.py +610 -0
- apache_polaris/sdk/management/exceptions.py +235 -0
- apache_polaris/sdk/management/models/.keep +0 -0
- apache_polaris/sdk/management/models/__init__.py +89 -0
- apache_polaris/sdk/management/models/add_grant_request.py +110 -0
- apache_polaris/sdk/management/models/authentication_parameters.py +142 -0
- apache_polaris/sdk/management/models/aws_iam_service_identity_info.py +107 -0
- apache_polaris/sdk/management/models/aws_storage_config_info.py +132 -0
- apache_polaris/sdk/management/models/azure_storage_config_info.py +116 -0
- apache_polaris/sdk/management/models/bearer_authentication_parameters.py +107 -0
- apache_polaris/sdk/management/models/catalog.py +158 -0
- apache_polaris/sdk/management/models/catalog_grant.py +109 -0
- apache_polaris/sdk/management/models/catalog_privilege.py +105 -0
- apache_polaris/sdk/management/models/catalog_properties.py +119 -0
- apache_polaris/sdk/management/models/catalog_role.py +122 -0
- apache_polaris/sdk/management/models/catalog_roles.py +114 -0
- apache_polaris/sdk/management/models/catalogs.py +114 -0
- apache_polaris/sdk/management/models/connection_config_info.py +150 -0
- apache_polaris/sdk/management/models/create_catalog_request.py +110 -0
- apache_polaris/sdk/management/models/create_catalog_role_request.py +110 -0
- apache_polaris/sdk/management/models/create_principal_request.py +112 -0
- apache_polaris/sdk/management/models/create_principal_role_request.py +110 -0
- apache_polaris/sdk/management/models/external_catalog.py +126 -0
- apache_polaris/sdk/management/models/file_storage_config_info.py +108 -0
- apache_polaris/sdk/management/models/gcp_storage_config_info.py +110 -0
- apache_polaris/sdk/management/models/grant_catalog_role_request.py +110 -0
- apache_polaris/sdk/management/models/grant_principal_role_request.py +110 -0
- apache_polaris/sdk/management/models/grant_resource.py +145 -0
- apache_polaris/sdk/management/models/grant_resources.py +114 -0
- apache_polaris/sdk/management/models/hadoop_connection_config_info.py +118 -0
- apache_polaris/sdk/management/models/hive_connection_config_info.py +118 -0
- apache_polaris/sdk/management/models/iceberg_rest_connection_config_info.py +118 -0
- apache_polaris/sdk/management/models/implicit_authentication_parameters.py +106 -0
- apache_polaris/sdk/management/models/namespace_grant.py +111 -0
- apache_polaris/sdk/management/models/namespace_privilege.py +103 -0
- apache_polaris/sdk/management/models/o_auth_client_credentials_parameters.py +110 -0
- apache_polaris/sdk/management/models/polaris_catalog.py +120 -0
- apache_polaris/sdk/management/models/policy_grant.py +113 -0
- apache_polaris/sdk/management/models/policy_privilege.py +62 -0
- apache_polaris/sdk/management/models/principal.py +124 -0
- apache_polaris/sdk/management/models/principal_role.py +124 -0
- apache_polaris/sdk/management/models/principal_roles.py +114 -0
- apache_polaris/sdk/management/models/principal_with_credentials.py +116 -0
- apache_polaris/sdk/management/models/principal_with_credentials_credentials.py +108 -0
- apache_polaris/sdk/management/models/principals.py +114 -0
- apache_polaris/sdk/management/models/reset_principal_request.py +108 -0
- apache_polaris/sdk/management/models/revoke_grant_request.py +110 -0
- apache_polaris/sdk/management/models/service_identity_info.py +133 -0
- apache_polaris/sdk/management/models/sig_v4_authentication_parameters.py +111 -0
- apache_polaris/sdk/management/models/storage_config_info.py +144 -0
- apache_polaris/sdk/management/models/table_grant.py +114 -0
- apache_polaris/sdk/management/models/table_privilege.py +82 -0
- apache_polaris/sdk/management/models/update_catalog_request.py +114 -0
- apache_polaris/sdk/management/models/update_catalog_role_request.py +108 -0
- apache_polaris/sdk/management/models/update_principal_request.py +108 -0
- apache_polaris/sdk/management/models/update_principal_role_request.py +108 -0
- apache_polaris/sdk/management/models/view_grant.py +114 -0
- apache_polaris/sdk/management/models/view_privilege.py +60 -0
- apache_polaris/sdk/management/rest.py +277 -0
- apache_polaris-1.4.0.dist-info/METADATA +68 -0
- apache_polaris-1.4.0.dist-info/RECORD +261 -0
- apache_polaris-1.4.0.dist-info/WHEEL +4 -0
- apache_polaris-1.4.0.dist-info/entry_points.txt +2 -0
- apache_polaris-1.4.0.dist-info/licenses/LICENSE +203 -0
- apache_polaris-1.4.0.dist-info/licenses/NOTICE +9 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
|
4
|
+
# distributed with this work for additional information
|
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
|
7
|
+
# "License"); you may not use this file except in compliance
|
|
8
|
+
# with the License. You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
|
13
|
+
# software distributed under the License is distributed on an
|
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
# KIND, either express or implied. See the License for the
|
|
16
|
+
# specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
#
|
|
19
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
|
4
|
+
# distributed with this work for additional information
|
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
|
7
|
+
# "License"); you may not use this file except in compliance
|
|
8
|
+
# with the License. You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
|
13
|
+
# software distributed under the License is distributed on an
|
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
# KIND, either express or implied. See the License for the
|
|
16
|
+
# specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
#
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
|
4
|
+
# distributed with this work for additional information
|
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
|
7
|
+
# "License"); you may not use this file except in compliance
|
|
8
|
+
# with the License. You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
|
13
|
+
# software distributed under the License is distributed on an
|
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
# KIND, either express or implied. See the License for the
|
|
16
|
+
# specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
#
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
from argparse import Namespace
|
|
22
|
+
from functools import cached_property
|
|
23
|
+
from typing import Optional, Dict, Any
|
|
24
|
+
|
|
25
|
+
from apache_polaris.cli.constants import (
|
|
26
|
+
CONFIG_FILE,
|
|
27
|
+
CLIENT_PROFILE_ENV,
|
|
28
|
+
CLIENT_ID_ENV,
|
|
29
|
+
CLIENT_SECRET_ENV,
|
|
30
|
+
REALM_ENV,
|
|
31
|
+
HEADER_ENV,
|
|
32
|
+
Arguments,
|
|
33
|
+
DEFAULT_HOSTNAME,
|
|
34
|
+
DEFAULT_PORT,
|
|
35
|
+
)
|
|
36
|
+
from apache_polaris.cli.options.option_tree import Argument
|
|
37
|
+
from apache_polaris.sdk.management import ApiClient, Configuration
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _load_profiles() -> Dict[str, Dict[str, Any]]:
|
|
41
|
+
if not os.path.exists(CONFIG_FILE):
|
|
42
|
+
return {}
|
|
43
|
+
with open(CONFIG_FILE, "r") as f:
|
|
44
|
+
return json.load(f)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class BuilderConfig:
|
|
48
|
+
def __init__(self, options: Namespace):
|
|
49
|
+
self.options = options
|
|
50
|
+
self.proxy = options.proxy
|
|
51
|
+
self.access_token = options.access_token
|
|
52
|
+
|
|
53
|
+
@cached_property
|
|
54
|
+
def profile(self) -> Dict[str, Any]:
|
|
55
|
+
profile: Dict[str, Any] = {}
|
|
56
|
+
client_profile = self.options.profile or os.getenv(CLIENT_PROFILE_ENV)
|
|
57
|
+
if client_profile:
|
|
58
|
+
profiles = _load_profiles()
|
|
59
|
+
loaded_profile = profiles.get(client_profile)
|
|
60
|
+
if loaded_profile is None:
|
|
61
|
+
raise Exception(f"Polaris profile {client_profile} not found")
|
|
62
|
+
profile = loaded_profile
|
|
63
|
+
return profile
|
|
64
|
+
|
|
65
|
+
@cached_property
|
|
66
|
+
def base_url(self) -> str:
|
|
67
|
+
if self.options.base_url:
|
|
68
|
+
if self.options.host is not None or self.options.port is not None:
|
|
69
|
+
raise Exception(
|
|
70
|
+
f"Please provide either {Argument.to_flag_name(Arguments.BASE_URL)} or"
|
|
71
|
+
f" {Argument.to_flag_name(Arguments.HOST)} &"
|
|
72
|
+
f" {Argument.to_flag_name(Arguments.PORT)}, but not both"
|
|
73
|
+
)
|
|
74
|
+
return self.options.base_url
|
|
75
|
+
|
|
76
|
+
host = self.options.host or self.profile.get(Arguments.HOST) or DEFAULT_HOSTNAME
|
|
77
|
+
port = self.options.port or self.profile.get(Arguments.PORT) or DEFAULT_PORT
|
|
78
|
+
return f"http://{host}:{port}"
|
|
79
|
+
|
|
80
|
+
@cached_property
|
|
81
|
+
def management_url(self) -> str:
|
|
82
|
+
return f"{self.base_url}/api/management/v1"
|
|
83
|
+
|
|
84
|
+
@cached_property
|
|
85
|
+
def catalog_url(self) -> str:
|
|
86
|
+
return f"{self.base_url}/api/catalog/v1"
|
|
87
|
+
|
|
88
|
+
@cached_property
|
|
89
|
+
def client_id(self) -> Optional[str]:
|
|
90
|
+
return (
|
|
91
|
+
self.options.client_id
|
|
92
|
+
or os.getenv(CLIENT_ID_ENV)
|
|
93
|
+
or self.profile.get(Arguments.CLIENT_ID)
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
@cached_property
|
|
97
|
+
def client_secret(self) -> Optional[str]:
|
|
98
|
+
return (
|
|
99
|
+
self.options.client_secret
|
|
100
|
+
or os.getenv(CLIENT_SECRET_ENV)
|
|
101
|
+
or self.profile.get(Arguments.CLIENT_SECRET)
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
@cached_property
|
|
105
|
+
def realm(self) -> Optional[str]:
|
|
106
|
+
realms = (
|
|
107
|
+
self.options.realm
|
|
108
|
+
or os.getenv(REALM_ENV)
|
|
109
|
+
or self.profile.get(Arguments.REALM)
|
|
110
|
+
)
|
|
111
|
+
return realms
|
|
112
|
+
|
|
113
|
+
@cached_property
|
|
114
|
+
def header(self) -> Optional[str]:
|
|
115
|
+
return (
|
|
116
|
+
self.options.header
|
|
117
|
+
or os.getenv(HEADER_ENV)
|
|
118
|
+
or self.profile.get(Arguments.HEADER)
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class ApiClientBuilder:
|
|
123
|
+
def __init__(self, options: Namespace, *, direct_authentication: bool = False):
|
|
124
|
+
self.conf = BuilderConfig(options)
|
|
125
|
+
self.direct_auth_enabled = direct_authentication
|
|
126
|
+
|
|
127
|
+
def _get_token(self) -> str:
|
|
128
|
+
header_params = {"Content-Type": "application/x-www-form-urlencoded"}
|
|
129
|
+
if self.conf.header and self.conf.realm:
|
|
130
|
+
header_params[self.conf.header] = self.conf.realm
|
|
131
|
+
|
|
132
|
+
conf = Configuration(host=self.conf.management_url)
|
|
133
|
+
conf.proxy = self.conf.proxy
|
|
134
|
+
api_client = ApiClient(conf)
|
|
135
|
+
response = api_client.call_api(
|
|
136
|
+
"POST",
|
|
137
|
+
f"{self.conf.catalog_url}/oauth/tokens",
|
|
138
|
+
header_params=header_params,
|
|
139
|
+
post_params={
|
|
140
|
+
"grant_type": "client_credentials",
|
|
141
|
+
"client_id": self.conf.client_id,
|
|
142
|
+
"client_secret": self.conf.client_secret,
|
|
143
|
+
"scope": "PRINCIPAL_ROLE:ALL",
|
|
144
|
+
},
|
|
145
|
+
).response.data
|
|
146
|
+
if "access_token" not in json.loads(response):
|
|
147
|
+
raise Exception("Failed to get access token")
|
|
148
|
+
return json.loads(response)["access_token"]
|
|
149
|
+
|
|
150
|
+
def _build(self) -> ApiClient:
|
|
151
|
+
has_access_token = self.conf.access_token is not None
|
|
152
|
+
has_client_secret = (
|
|
153
|
+
self.conf.client_id is not None and self.conf.client_secret is not None
|
|
154
|
+
)
|
|
155
|
+
if has_access_token and (self.conf.client_id or self.conf.client_secret):
|
|
156
|
+
raise Exception(
|
|
157
|
+
f"Please provide credentials via either {Argument.to_flag_name(Arguments.CLIENT_ID)} &"
|
|
158
|
+
f" {Argument.to_flag_name(Arguments.CLIENT_SECRET)} or"
|
|
159
|
+
f" {Argument.to_flag_name(Arguments.ACCESS_TOKEN)}, but not both"
|
|
160
|
+
)
|
|
161
|
+
if not has_access_token and not has_client_secret:
|
|
162
|
+
raise Exception(
|
|
163
|
+
f"Please provide credentials via either {Argument.to_flag_name(Arguments.CLIENT_ID)} &"
|
|
164
|
+
f" {Argument.to_flag_name(Arguments.CLIENT_SECRET)} or"
|
|
165
|
+
f" {Argument.to_flag_name(Arguments.ACCESS_TOKEN)}."
|
|
166
|
+
f" Alternatively, you may set the environment variables {CLIENT_ID_ENV} &"
|
|
167
|
+
f" {CLIENT_SECRET_ENV}."
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
config = Configuration(host=self.conf.management_url)
|
|
171
|
+
config.proxy = self.conf.proxy
|
|
172
|
+
if has_access_token:
|
|
173
|
+
config.access_token = self.conf.access_token
|
|
174
|
+
elif has_client_secret:
|
|
175
|
+
config.username = self.conf.client_id
|
|
176
|
+
config.password = self.conf.client_secret
|
|
177
|
+
|
|
178
|
+
if not has_access_token and not self.direct_auth_enabled:
|
|
179
|
+
config.username = None
|
|
180
|
+
config.password = None
|
|
181
|
+
config.access_token = self._get_token()
|
|
182
|
+
|
|
183
|
+
client_params = {}
|
|
184
|
+
if self.conf.realm and self.conf.header:
|
|
185
|
+
client_params["header_name"] = self.conf.header
|
|
186
|
+
client_params["header_value"] = self.conf.realm
|
|
187
|
+
|
|
188
|
+
return ApiClient(config, **client_params)
|
|
189
|
+
|
|
190
|
+
def get_api_client(self) -> ApiClient:
|
|
191
|
+
return self._build()
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
|
4
|
+
# distributed with this work for additional information
|
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
|
7
|
+
# "License"); you may not use this file except in compliance
|
|
8
|
+
# with the License. You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
|
13
|
+
# software distributed under the License is distributed on an
|
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
# KIND, either express or implied. See the License for the
|
|
16
|
+
# specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
#
|
|
19
|
+
import argparse
|
|
20
|
+
from abc import ABC
|
|
21
|
+
from typing import Callable, Optional, Any
|
|
22
|
+
|
|
23
|
+
from apache_polaris.cli.constants import Commands, Arguments
|
|
24
|
+
from apache_polaris.cli.options.parser import Parser
|
|
25
|
+
from apache_polaris.sdk.management import PolarisDefaultApi
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Command(ABC):
|
|
29
|
+
"""
|
|
30
|
+
An abstract base class for commands. Implementations are expected to override the class methods `validate` and
|
|
31
|
+
`execute`. The static method `Command.from_options` can be used to parse a argparse Namespace into the appropriate
|
|
32
|
+
Command implementation if one exists.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def from_options(options: argparse.Namespace) -> "Command":
|
|
37
|
+
def options_get(key: str, f: Callable[[Any], Any] = lambda x: x) -> Any:
|
|
38
|
+
return f(getattr(options, key)) if hasattr(options, key) else None
|
|
39
|
+
|
|
40
|
+
properties = Parser.parse_properties(options_get(Arguments.PROPERTY))
|
|
41
|
+
set_properties = Parser.parse_properties(options_get(Arguments.SET_PROPERTY))
|
|
42
|
+
remove_properties = options_get(Arguments.REMOVE_PROPERTY)
|
|
43
|
+
catalog_client_scopes = options_get(Arguments.CATALOG_CLIENT_SCOPE)
|
|
44
|
+
parameters = Parser.parse_properties(options_get(Arguments.PARAMETERS))
|
|
45
|
+
|
|
46
|
+
command: Optional[Command] = None
|
|
47
|
+
if options.command == Commands.CATALOGS:
|
|
48
|
+
from apache_polaris.cli.command.catalogs import CatalogsCommand
|
|
49
|
+
|
|
50
|
+
command = CatalogsCommand(
|
|
51
|
+
options_get(f"{Commands.CATALOGS}_subcommand"),
|
|
52
|
+
catalog_type=options_get(Arguments.TYPE),
|
|
53
|
+
default_base_location=options_get(Arguments.DEFAULT_BASE_LOCATION),
|
|
54
|
+
storage_type=options_get(Arguments.STORAGE_TYPE),
|
|
55
|
+
allowed_locations=options_get(Arguments.ALLOWED_LOCATION),
|
|
56
|
+
role_arn=options_get(Arguments.ROLE_ARN),
|
|
57
|
+
external_id=options_get(Arguments.EXTERNAL_ID),
|
|
58
|
+
user_arn=options_get(Arguments.USER_ARN),
|
|
59
|
+
region=options_get(Arguments.REGION),
|
|
60
|
+
tenant_id=options_get(Arguments.TENANT_ID),
|
|
61
|
+
multi_tenant_app_name=options_get(Arguments.MULTI_TENANT_APP_NAME),
|
|
62
|
+
hierarchical=options_get(Arguments.HIERARCHICAL),
|
|
63
|
+
consent_url=options_get(Arguments.CONSENT_URL),
|
|
64
|
+
service_account=options_get(Arguments.SERVICE_ACCOUNT),
|
|
65
|
+
catalog_name=options_get(Arguments.CATALOG),
|
|
66
|
+
properties={} if properties is None else properties,
|
|
67
|
+
set_properties={} if set_properties is None else set_properties,
|
|
68
|
+
hadoop_warehouse=options_get(Arguments.HADOOP_WAREHOUSE),
|
|
69
|
+
hive_warehouse=options_get(Arguments.HIVE_WAREHOUSE),
|
|
70
|
+
iceberg_remote_catalog_name=options_get(
|
|
71
|
+
Arguments.ICEBERG_REMOTE_CATALOG_NAME
|
|
72
|
+
),
|
|
73
|
+
remove_properties=[]
|
|
74
|
+
if remove_properties is None
|
|
75
|
+
else remove_properties,
|
|
76
|
+
endpoint=options_get(Arguments.ENDPOINT),
|
|
77
|
+
endpoint_internal=options_get(Arguments.ENDPOINT_INTERNAL),
|
|
78
|
+
sts_endpoint=options_get(Arguments.STS_ENDPOINT),
|
|
79
|
+
sts_unavailable=options_get(Arguments.STS_UNAVAILABLE),
|
|
80
|
+
kms_unavailable=options_get(Arguments.KMS_UNAVAILABLE),
|
|
81
|
+
path_style_access=options_get(Arguments.PATH_STYLE_ACCESS),
|
|
82
|
+
current_kms_key=options_get(Arguments.KMS_KEY_CURRENT),
|
|
83
|
+
allowed_kms_keys=options_get(Arguments.KMS_KEY_ALLOWED),
|
|
84
|
+
catalog_connection_type=options_get(Arguments.CATALOG_CONNECTION_TYPE),
|
|
85
|
+
catalog_authentication_type=options_get(
|
|
86
|
+
Arguments.CATALOG_AUTHENTICATION_TYPE
|
|
87
|
+
),
|
|
88
|
+
catalog_service_identity_type=options_get(
|
|
89
|
+
Arguments.CATALOG_SERVICE_IDENTITY_TYPE
|
|
90
|
+
),
|
|
91
|
+
catalog_service_identity_iam_arn=options_get(
|
|
92
|
+
Arguments.CATALOG_SERVICE_IDENTITY_IAM_ARN
|
|
93
|
+
),
|
|
94
|
+
catalog_uri=options_get(Arguments.CATALOG_URI),
|
|
95
|
+
catalog_token_uri=options_get(Arguments.CATALOG_TOKEN_URI),
|
|
96
|
+
catalog_client_id=options_get(Arguments.CATALOG_CLIENT_ID),
|
|
97
|
+
catalog_client_secret=options_get(Arguments.CATALOG_CLIENT_SECRET),
|
|
98
|
+
catalog_client_scopes=[]
|
|
99
|
+
if catalog_client_scopes is None
|
|
100
|
+
else catalog_client_scopes,
|
|
101
|
+
catalog_bearer_token=options_get(Arguments.CATALOG_BEARER_TOKEN),
|
|
102
|
+
catalog_role_arn=options_get(Arguments.CATALOG_ROLE_ARN),
|
|
103
|
+
catalog_role_session_name=options_get(
|
|
104
|
+
Arguments.CATALOG_ROLE_SESSION_NAME
|
|
105
|
+
),
|
|
106
|
+
catalog_external_id=options_get(Arguments.CATALOG_EXTERNAL_ID),
|
|
107
|
+
catalog_signing_region=options_get(Arguments.CATALOG_SIGNING_REGION),
|
|
108
|
+
catalog_signing_name=options_get(Arguments.CATALOG_SIGNING_NAME),
|
|
109
|
+
)
|
|
110
|
+
elif options.command == Commands.PRINCIPALS:
|
|
111
|
+
from apache_polaris.cli.command.principals import PrincipalsCommand
|
|
112
|
+
|
|
113
|
+
command = PrincipalsCommand(
|
|
114
|
+
options_get(f"{Commands.PRINCIPALS}_subcommand"),
|
|
115
|
+
type=options_get(Arguments.TYPE),
|
|
116
|
+
principal_name=options_get(Arguments.PRINCIPAL),
|
|
117
|
+
client_id=options_get(Arguments.CLIENT_ID),
|
|
118
|
+
principal_role=options_get(Arguments.PRINCIPAL_ROLE),
|
|
119
|
+
properties={} if properties is None else properties,
|
|
120
|
+
set_properties={} if set_properties is None else set_properties,
|
|
121
|
+
remove_properties=[]
|
|
122
|
+
if remove_properties is None
|
|
123
|
+
else remove_properties,
|
|
124
|
+
new_client_id=options_get(Arguments.NEW_CLIENT_ID),
|
|
125
|
+
new_client_secret=options_get(Arguments.NEW_CLIENT_SECRET),
|
|
126
|
+
)
|
|
127
|
+
elif options.command == Commands.PRINCIPAL_ROLES:
|
|
128
|
+
from apache_polaris.cli.command.principal_roles import PrincipalRolesCommand
|
|
129
|
+
|
|
130
|
+
command = PrincipalRolesCommand(
|
|
131
|
+
options_get(f"{Commands.PRINCIPAL_ROLES}_subcommand"),
|
|
132
|
+
principal_role_name=options_get(Arguments.PRINCIPAL_ROLE),
|
|
133
|
+
principal_name=options_get(Arguments.PRINCIPAL),
|
|
134
|
+
catalog_name=options_get(Arguments.CATALOG),
|
|
135
|
+
catalog_role_name=options_get(Arguments.CATALOG_ROLE),
|
|
136
|
+
properties={} if properties is None else properties,
|
|
137
|
+
set_properties={} if set_properties is None else set_properties,
|
|
138
|
+
remove_properties=[]
|
|
139
|
+
if remove_properties is None
|
|
140
|
+
else remove_properties,
|
|
141
|
+
)
|
|
142
|
+
elif options.command == Commands.CATALOG_ROLES:
|
|
143
|
+
from apache_polaris.cli.command.catalog_roles import CatalogRolesCommand
|
|
144
|
+
|
|
145
|
+
command = CatalogRolesCommand(
|
|
146
|
+
options_get(f"{Commands.CATALOG_ROLES}_subcommand"),
|
|
147
|
+
catalog_name=options_get(Arguments.CATALOG),
|
|
148
|
+
catalog_role_name=options_get(Arguments.CATALOG_ROLE),
|
|
149
|
+
principal_role_name=options_get(Arguments.PRINCIPAL_ROLE),
|
|
150
|
+
properties={} if properties is None else properties,
|
|
151
|
+
set_properties={} if set_properties is None else set_properties,
|
|
152
|
+
remove_properties=[]
|
|
153
|
+
if remove_properties is None
|
|
154
|
+
else remove_properties,
|
|
155
|
+
)
|
|
156
|
+
elif options.command == Commands.PRIVILEGES:
|
|
157
|
+
from apache_polaris.cli.command.privileges import PrivilegesCommand
|
|
158
|
+
|
|
159
|
+
subcommand = options_get(f"{Commands.PRIVILEGES}_subcommand")
|
|
160
|
+
command = PrivilegesCommand(
|
|
161
|
+
subcommand,
|
|
162
|
+
action=options_get(f"{subcommand}_subcommand"),
|
|
163
|
+
catalog_name=options_get(Arguments.CATALOG),
|
|
164
|
+
catalog_role_name=options_get(Arguments.CATALOG_ROLE),
|
|
165
|
+
namespace=options_get(
|
|
166
|
+
Arguments.NAMESPACE, lambda s: s.split(".") if s else None
|
|
167
|
+
),
|
|
168
|
+
view=options_get(Arguments.VIEW),
|
|
169
|
+
table=options_get(Arguments.TABLE),
|
|
170
|
+
privilege=options_get(Arguments.PRIVILEGE),
|
|
171
|
+
cascade=options_get(Arguments.CASCADE),
|
|
172
|
+
)
|
|
173
|
+
elif options.command == Commands.NAMESPACES:
|
|
174
|
+
from apache_polaris.cli.command.namespaces import NamespacesCommand
|
|
175
|
+
|
|
176
|
+
subcommand = options_get(f"{Commands.NAMESPACES}_subcommand")
|
|
177
|
+
command = NamespacesCommand(
|
|
178
|
+
subcommand,
|
|
179
|
+
catalog=options_get(Arguments.CATALOG),
|
|
180
|
+
namespace=options_get(Arguments.NAMESPACE, lambda s: s.split(".")),
|
|
181
|
+
parent=options_get(
|
|
182
|
+
Arguments.PARENT, lambda s: s.split(".") if s else None
|
|
183
|
+
),
|
|
184
|
+
location=options_get(Arguments.LOCATION),
|
|
185
|
+
properties=properties,
|
|
186
|
+
)
|
|
187
|
+
elif options.command == Commands.PROFILES:
|
|
188
|
+
from apache_polaris.cli.command.profiles import ProfilesCommand
|
|
189
|
+
|
|
190
|
+
subcommand = options_get(f"{Commands.PROFILES}_subcommand")
|
|
191
|
+
command = ProfilesCommand(
|
|
192
|
+
subcommand, profile_name=options_get(Arguments.PROFILE)
|
|
193
|
+
)
|
|
194
|
+
elif options.command == Commands.POLICIES:
|
|
195
|
+
from apache_polaris.cli.command.policies import PoliciesCommand
|
|
196
|
+
|
|
197
|
+
subcommand = options_get(f"{Commands.POLICIES}_subcommand")
|
|
198
|
+
command = PoliciesCommand(
|
|
199
|
+
subcommand,
|
|
200
|
+
catalog_name=options_get(Arguments.CATALOG),
|
|
201
|
+
namespace=options_get(Arguments.NAMESPACE),
|
|
202
|
+
policy_name=options_get(Arguments.POLICY),
|
|
203
|
+
policy_file=options_get(Arguments.POLICY_FILE),
|
|
204
|
+
policy_type=options_get(Arguments.POLICY_TYPE),
|
|
205
|
+
policy_description=options_get(Arguments.POLICY_DESCRIPTION),
|
|
206
|
+
target_name=options_get(Arguments.TARGET_NAME),
|
|
207
|
+
parameters={} if parameters is None else parameters,
|
|
208
|
+
detach_all=options_get(Arguments.DETACH_ALL),
|
|
209
|
+
applicable=options_get(Arguments.APPLICABLE),
|
|
210
|
+
attachment_type=options_get(Arguments.ATTACHMENT_TYPE),
|
|
211
|
+
attachment_path=options_get(Arguments.ATTACHMENT_PATH),
|
|
212
|
+
)
|
|
213
|
+
elif options.command == Commands.SETUP:
|
|
214
|
+
from apache_polaris.cli.command.setup import SetupCommand
|
|
215
|
+
|
|
216
|
+
subcommand = options_get(f"{Commands.SETUP}_subcommand")
|
|
217
|
+
command = SetupCommand(
|
|
218
|
+
subcommand,
|
|
219
|
+
setup_config=options_get(Arguments.SETUP_CONFIG),
|
|
220
|
+
dry_run=options_get(Arguments.DRY_RUN),
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
if command is not None:
|
|
224
|
+
command.validate()
|
|
225
|
+
return command
|
|
226
|
+
else:
|
|
227
|
+
raise Exception(
|
|
228
|
+
"Please specify a command or run ./polaris --help to view the available commands"
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
def execute(self, api: PolarisDefaultApi) -> None:
|
|
232
|
+
"""
|
|
233
|
+
Execute a given command and, where applicable, print the response as JSON.
|
|
234
|
+
"""
|
|
235
|
+
raise Exception("`execute` called on abstract `Command`")
|
|
236
|
+
|
|
237
|
+
def validate(self) -> None:
|
|
238
|
+
"""
|
|
239
|
+
Used to validate a command. Should always be called before `execute`. The arg parser will catch many issues
|
|
240
|
+
with options, but this is used to apply additional constraints that the arg parser can't currently handle.
|
|
241
|
+
"""
|
|
242
|
+
raise Exception("`validate` called on abstract `Command`")
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
|
4
|
+
# distributed with this work for additional information
|
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
|
7
|
+
# "License"); you may not use this file except in compliance
|
|
8
|
+
# with the License. You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
|
13
|
+
# software distributed under the License is distributed on an
|
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
# KIND, either express or implied. See the License for the
|
|
16
|
+
# specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
#
|
|
19
|
+
from dataclasses import dataclass
|
|
20
|
+
from typing import Dict, Optional, List
|
|
21
|
+
|
|
22
|
+
from pydantic import StrictStr
|
|
23
|
+
|
|
24
|
+
from apache_polaris.cli.command import Command
|
|
25
|
+
from apache_polaris.cli.constants import Subcommands, Arguments
|
|
26
|
+
from apache_polaris.cli.options.option_tree import Argument
|
|
27
|
+
from apache_polaris.sdk.management import (
|
|
28
|
+
PolarisDefaultApi,
|
|
29
|
+
CreateCatalogRoleRequest,
|
|
30
|
+
CatalogRole,
|
|
31
|
+
UpdateCatalogRoleRequest,
|
|
32
|
+
GrantCatalogRoleRequest,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass
|
|
37
|
+
class CatalogRolesCommand(Command):
|
|
38
|
+
"""
|
|
39
|
+
A Command implementation to represent `polaris catalog-roles`. The instance attributes correspond to parameters
|
|
40
|
+
that can be provided to various subcommands, except `catalog_roles_subcommand` which represents the subcommand
|
|
41
|
+
itself.
|
|
42
|
+
|
|
43
|
+
Example commands:
|
|
44
|
+
* ./polaris catalog-roles create --catalog bronze_catalog cat_role
|
|
45
|
+
* ./polaris catalog-roles list --catalog bronze_catalog --principal-role data-analyst
|
|
46
|
+
* ./polaris catalog-roles grant --catalog bronze_catalog --principal-role data-engineer etl_role
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
catalog_roles_subcommand: str
|
|
50
|
+
catalog_name: str
|
|
51
|
+
catalog_role_name: str
|
|
52
|
+
principal_role_name: str
|
|
53
|
+
properties: Optional[Dict[str, StrictStr]]
|
|
54
|
+
set_properties: Dict[str, StrictStr]
|
|
55
|
+
remove_properties: List[str]
|
|
56
|
+
|
|
57
|
+
def validate(self) -> None:
|
|
58
|
+
if not self.catalog_name:
|
|
59
|
+
raise Exception(
|
|
60
|
+
f"Missing required argument: {Argument.to_flag_name(Arguments.CATALOG)}"
|
|
61
|
+
)
|
|
62
|
+
if self.catalog_roles_subcommand in {Subcommands.GRANT, Subcommands.REVOKE}:
|
|
63
|
+
if not self.principal_role_name:
|
|
64
|
+
raise Exception(
|
|
65
|
+
f"Missing required argument: {Argument.to_flag_name(Arguments.PRINCIPAL_ROLE)}"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def execute(self, api: PolarisDefaultApi) -> None:
|
|
69
|
+
if self.catalog_roles_subcommand == Subcommands.CREATE:
|
|
70
|
+
request = CreateCatalogRoleRequest(
|
|
71
|
+
catalog_role=CatalogRole(
|
|
72
|
+
name=self.catalog_role_name, properties=self.properties
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
api.create_catalog_role(self.catalog_name, request)
|
|
76
|
+
elif self.catalog_roles_subcommand == Subcommands.DELETE:
|
|
77
|
+
api.delete_catalog_role(self.catalog_name, self.catalog_role_name)
|
|
78
|
+
elif self.catalog_roles_subcommand == Subcommands.GET:
|
|
79
|
+
print(
|
|
80
|
+
api.get_catalog_role(
|
|
81
|
+
self.catalog_name, self.catalog_role_name
|
|
82
|
+
).to_json()
|
|
83
|
+
)
|
|
84
|
+
elif self.catalog_roles_subcommand == Subcommands.LIST:
|
|
85
|
+
if self.principal_role_name:
|
|
86
|
+
for catalog_role in api.list_catalog_roles_for_principal_role(
|
|
87
|
+
self.principal_role_name, self.catalog_name
|
|
88
|
+
).roles:
|
|
89
|
+
print(catalog_role.to_json())
|
|
90
|
+
else:
|
|
91
|
+
for catalog_role in api.list_catalog_roles(self.catalog_name).roles:
|
|
92
|
+
print(catalog_role.to_json())
|
|
93
|
+
elif self.catalog_roles_subcommand == Subcommands.UPDATE:
|
|
94
|
+
catalog_role = api.get_catalog_role(
|
|
95
|
+
self.catalog_name, self.catalog_role_name
|
|
96
|
+
)
|
|
97
|
+
new_properties = catalog_role.properties or {}
|
|
98
|
+
|
|
99
|
+
# Add or update all entries specified in set_properties
|
|
100
|
+
if self.set_properties:
|
|
101
|
+
new_properties = {**new_properties, **self.set_properties}
|
|
102
|
+
|
|
103
|
+
# Remove all keys specified in remove_properties
|
|
104
|
+
if self.remove_properties:
|
|
105
|
+
for to_remove in self.remove_properties:
|
|
106
|
+
new_properties.pop(to_remove, None)
|
|
107
|
+
|
|
108
|
+
request = UpdateCatalogRoleRequest(
|
|
109
|
+
current_entity_version=catalog_role.entity_version,
|
|
110
|
+
properties=new_properties,
|
|
111
|
+
)
|
|
112
|
+
api.update_catalog_role(self.catalog_name, self.catalog_role_name, request)
|
|
113
|
+
elif self.catalog_roles_subcommand == Subcommands.GRANT:
|
|
114
|
+
request = GrantCatalogRoleRequest(
|
|
115
|
+
catalog_role=CatalogRole(name=self.catalog_role_name),
|
|
116
|
+
properties=self.properties,
|
|
117
|
+
)
|
|
118
|
+
api.assign_catalog_role_to_principal_role(
|
|
119
|
+
self.principal_role_name, self.catalog_name, request
|
|
120
|
+
)
|
|
121
|
+
elif self.catalog_roles_subcommand == Subcommands.REVOKE:
|
|
122
|
+
api.revoke_catalog_role_from_principal_role(
|
|
123
|
+
self.principal_role_name, self.catalog_name, self.catalog_role_name
|
|
124
|
+
)
|
|
125
|
+
else:
|
|
126
|
+
raise Exception(
|
|
127
|
+
f"{self.catalog_roles_subcommand} is not supported in the CLI"
|
|
128
|
+
)
|