This is an automated email from the ASF dual-hosted git repository.

yzheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git


The following commit(s) were added to refs/heads/main by this push:
     new 20817e14 Add support for setting region for AWS via CLI (#881)
20817e14 is described below

commit 20817e14e8448114226e76ab8163de35ba0fd6d2
Author: MonkeyCanCode <[email protected]>
AuthorDate: Tue Feb 4 19:33:32 2025 -0600

    Add support for setting region for AWS via CLI (#881)
    
    * Add support for setting region for AWS via CLI
    
    * Add support for setting region for AWS via CLI
    
    * move test case
---
 regtests/client/python/cli/command/__init__.py               |  1 +
 regtests/client/python/cli/command/catalogs.py               |  8 +++++---
 regtests/client/python/cli/constants.py                      |  2 ++
 regtests/client/python/cli/options/option_tree.py            |  1 +
 .../polaris/management/models/aws_storage_config_info.py     |  5 ++++-
 regtests/client/python/test/test_cli_parsing.py              | 12 ++++++++++++
 6 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/regtests/client/python/cli/command/__init__.py 
b/regtests/client/python/cli/command/__init__.py
index 9f877eba..76b4a98a 100644
--- a/regtests/client/python/cli/command/__init__.py
+++ b/regtests/client/python/cli/command/__init__.py
@@ -54,6 +54,7 @@ class Command(ABC):
                 role_arn=options_get(Arguments.ROLE_ARN),
                 external_id=options_get(Arguments.EXTERNAL_ID),
                 user_arn=options_get(Arguments.USER_ARN),
+                region=options_get(Arguments.REGION),
                 tenant_id=options_get(Arguments.TENANT_ID),
                 
multi_tenant_app_name=options_get(Arguments.MULTI_TENANT_APP_NAME),
                 consent_url=options_get(Arguments.CONSENT_URL),
diff --git a/regtests/client/python/cli/command/catalogs.py 
b/regtests/client/python/cli/command/catalogs.py
index ceef7855..9ed14609 100644
--- a/regtests/client/python/cli/command/catalogs.py
+++ b/regtests/client/python/cli/command/catalogs.py
@@ -51,6 +51,7 @@ class CatalogsCommand(Command):
     role_arn: str
     external_id: str
     user_arn: str
+    region: str
     tenant_id: str
     multi_tenant_app_name: str
     consent_url: str
@@ -81,6 +82,7 @@ class CatalogsCommand(Command):
             if self._has_azure_storage_info() or self._has_gcs_storage_info():
                 raise Exception(f"Storage type 's3' supports the storage 
credentials"
                                 f" 
{Argument.to_flag_name(Arguments.ROLE_ARN)},"
+                                f" {Argument.to_flag_name(Arguments.REGION)},"
                                 f" 
{Argument.to_flag_name(Arguments.EXTERNAL_ID)}, and"
                                 f" 
{Argument.to_flag_name(Arguments.USER_ARN)}")
         elif self.storage_type == StorageType.AZURE.value:
@@ -101,7 +103,7 @@ class CatalogsCommand(Command):
                 raise Exception("Storage type 'file' does not support any 
storage credentials")
 
     def _has_aws_storage_info(self):
-        return self.role_arn or self.external_id or self.user_arn
+        return self.role_arn or self.external_id or self.user_arn or 
self.region
 
     def _has_azure_storage_info(self):
         return self.tenant_id or self.multi_tenant_app_name or self.consent_url
@@ -117,7 +119,8 @@ class CatalogsCommand(Command):
                 allowed_locations=self.allowed_locations,
                 role_arn=self.role_arn,
                 external_id=self.external_id,
-                user_arn=self.user_arn
+                user_arn=self.user_arn,
+                region=self.region
             )
         elif self.storage_type == StorageType.AZURE.value:
             config = AzureStorageConfigInfo(
@@ -212,4 +215,3 @@ class CatalogsCommand(Command):
             api.update_catalog(self.catalog_name, request)
         else:
             raise Exception(f'{self.catalogs_subcommand} is not supported in 
the CLI')
-
diff --git a/regtests/client/python/cli/constants.py 
b/regtests/client/python/cli/constants.py
index 42bcbf96..353d0dc3 100644
--- a/regtests/client/python/cli/constants.py
+++ b/regtests/client/python/cli/constants.py
@@ -131,6 +131,7 @@ class Arguments:
     BASE_URL = 'base_url'
     PARENT = 'parent'
     LOCATION = 'location'
+    REGION = 'region'
 
 
 class Hints:
@@ -164,6 +165,7 @@ class Hints:
 
             ROLE_ARN = '(Required for S3) A role ARN to use when connecting to 
S3'
             EXTERNAL_ID = '(Only for S3) The external ID to use when 
connecting to S3'
+            REGION = '(Only for S3) The region to use when connecting to S3'
             USER_ARN = '(Only for S3) A user ARN to use when connecting to S3'
 
             TENANT_ID = '(Required for Azure) A tenant ID to use when 
connecting to Azure Storage'
diff --git a/regtests/client/python/cli/options/option_tree.py 
b/regtests/client/python/cli/options/option_tree.py
index f19d2340..dfbd642e 100644
--- a/regtests/client/python/cli/options/option_tree.py
+++ b/regtests/client/python/cli/options/option_tree.py
@@ -87,6 +87,7 @@ class OptionTree:
                     Argument(Arguments.ALLOWED_LOCATION, str, 
Hints.Catalogs.Create.ALLOWED_LOCATION,
                              allow_repeats=True),
                     Argument(Arguments.ROLE_ARN, str, 
Hints.Catalogs.Create.ROLE_ARN),
+                    Argument(Arguments.REGION, str, 
Hints.Catalogs.Create.REGION),
                     Argument(Arguments.EXTERNAL_ID, str, 
Hints.Catalogs.Create.EXTERNAL_ID),
                     Argument(Arguments.TENANT_ID, str, 
Hints.Catalogs.Create.TENANT_ID),
                     Argument(Arguments.MULTI_TENANT_APP_NAME, str, 
Hints.Catalogs.Create.MULTI_TENANT_APP_NAME),
diff --git 
a/regtests/client/python/polaris/management/models/aws_storage_config_info.py 
b/regtests/client/python/polaris/management/models/aws_storage_config_info.py
index 63e479f0..a29724ff 100644
--- 
a/regtests/client/python/polaris/management/models/aws_storage_config_info.py
+++ 
b/regtests/client/python/polaris/management/models/aws_storage_config_info.py
@@ -52,6 +52,8 @@ class AwsStorageConfigInfo(StorageConfigInfo):
                                              alias="externalId")
     user_arn: Optional[StrictStr] = Field(default=None, description="the aws 
user arn used to assume the aws role",
                                           alias="userArn")
+    region: Optional[StrictStr] = Field(default=None, description="the aws 
region where data is stored",
+                                          alias="region")
     __properties: ClassVar[List[str]] = ["storageType", "allowedLocations"]
 
     model_config = ConfigDict(
@@ -110,6 +112,7 @@ class AwsStorageConfigInfo(StorageConfigInfo):
             "allowedLocations": obj.get("allowedLocations"),
             "roleArn": obj.get("roleArn"),
             "externalId": obj.get("externalId"),
-            "userArn": obj.get("userArn")
+            "userArn": obj.get("userArn"),
+            "region": obj.get("region")
         })
         return _obj
diff --git a/regtests/client/python/test/test_cli_parsing.py 
b/regtests/client/python/test/test_cli_parsing.py
index 27c6b9e1..41e87afe 100644
--- a/regtests/client/python/test/test_cli_parsing.py
+++ b/regtests/client/python/test/test_cli_parsing.py
@@ -230,6 +230,18 @@ class TestCliParsing(unittest.TestCase):
                 (0, 'catalog.properties.default_base_location'): 'x',
                 (0, 'catalog.storage_config_info.allowed_locations'): ['a', 
'b'],
             })
+        check_arguments(
+            mock_execute([
+                'catalogs', 'create', 'my-catalog', '--storage-type', 's3',
+                '--allowed-location', 'a', '--role-arn', 'ra', '--region', 
'us-west-2',
+                '--external-id', 'ei', '--default-base-location', 'x']),
+            'create_catalog', {
+                (0, 'catalog.name'): 'my-catalog',
+                (0, 'catalog.storage_config_info.storage_type'): 'S3',
+                (0, 'catalog.properties.default_base_location'): 'x',
+                (0, 'catalog.storage_config_info.allowed_locations'): ['a'],
+                (0, 'catalog.storage_config_info.region'): 'us-west-2',
+            })
         check_arguments(
             mock_execute([
                 'catalogs', 'create', 'my-catalog', '--storage-type', 'gcs',

Reply via email to