Skip to content

Commit

Permalink
Add region keyword argument to login.
Browse files Browse the repository at this point in the history
This allows users to specify what AWS region they want to work with.
  • Loading branch information
NullHypothesis committed Jun 10, 2024
1 parent 95a523e commit 52252f1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/tiledb/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .array import register_array
from .array import share_array
from .array import unshare_array
from .client import AwsRegion
from .client import Config
from .client import Ctx
from .client import list_arrays
Expand Down Expand Up @@ -89,4 +90,5 @@
"last_udf_task",
"task",
"TileDBCloudError",
"AwsRegion",
)
30 changes: 30 additions & 0 deletions src/tiledb/cloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ def Ctx(config=None):
return tiledb.Ctx(Config(config))


class AwsRegion(enum.Enum):
"""
The AWS cloud regions that are currently supported.
US_EAST_1 = North America, United States (Virginia)
US_WEST_1 = North America, United States (California)
EU_WEST_1 = Europe, Ireland
EU_WEST_2 = Europe, London
AP_SOUTHEAST_1 = Asia, Singapore
"""

US_EAST_1 = "us-east-1.aws."
US_WEST_1 = "us-west-1.aws."
EU_WEST_1 = "eu-west-1.aws."
EU_WEST_2 = "eu-west-2.aws."
AP_SOUTHEAST_1 = "ap-southeast-1.aws."


def login(
token=None,
username=None,
Expand All @@ -71,6 +89,7 @@ def login(
verify_ssl=None,
no_session=False,
threads=None,
region=None,
):
"""
Login to cloud service
Expand All @@ -83,10 +102,21 @@ def login(
:param no_session: don't create a session token on login,
store instead username/password
:param threads: number of threads to enable for concurrent requests
:param region: the AWS region to run code in
:return:
"""
if host is None:
host = config.default_host
if region is not None:
if region not in AwsRegion:
raise Exception("Invalid cloud region provided")
# Overwrite the host using the given region.
orig_url = urllib3.util.parse_url(host)
region_url = urllib3.util.Url(
scheme=orig_url.scheme,
host=region.value + orig_url.host,
)
host = region_url.url

if (token is None or token == "") and (
(username is None or username == "") and (password is None or password == "")
Expand Down

0 comments on commit 52252f1

Please sign in to comment.