Skip to content

Commit

Permalink
Make properties match case of boto3
Browse files Browse the repository at this point in the history
  • Loading branch information
frederickjansen committed Feb 8, 2022
1 parent 29d0c74 commit bb3dd2c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
32 changes: 16 additions & 16 deletions src/b3u/b3u.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ def __init__(self, uri: str):

result = self._make_url_safe(uri)

self.bucket = None
self.key = None
self.name = None
self.Bucket = None
self.Key = None
self.Name = None

if result.scheme == 's3':
if result.hostname is not None and result.hostname != '':
self.bucket = result.hostname
self.Bucket = result.hostname
if result.path is not None and result.path != '':
self.key = result.path.lstrip('/')
self.Key = result.path.lstrip('/')
elif result.scheme == 'ssm':
if result.path is not None and result.path != '':
self.name = result.path
self.Name = result.path

params = {}
result = self._make_url_safe(uri)
Expand Down Expand Up @@ -221,15 +221,15 @@ def for_get(self) -> dict:
Currently, only S3 and SSM are supported.
>>> b3u('s3://abc:xyz@bucket/object.data').for_get()
{'bucket': 'bucket', 'key': 'object.data'}
{'Bucket': 'bucket', 'Key': 'object.data'}
>>> b3u('ssm://ABC:XYZ@/path/to/parameter?region_name=us-east-1').for_get()
{'name': '/path/to/parameter'}
{'Name': '/path/to/parameter'}
"""
if self.service_name == 's3':
return self._package_properties(['bucket', 'key'])
return self._package_properties(['Bucket', 'Key'])
elif self.service_name == 'ssm':
return self._package_properties(['name'])
return self._package_properties(['Name'])

return {}

Expand Down Expand Up @@ -296,15 +296,15 @@ def to_string(self) -> str:
if contains_aws_info:
new_uri += '@'

if self.bucket is not None:
new_uri += self.bucket
if self.Bucket is not None:
new_uri += self.Bucket

# bucket must exist for key to exist
if self.key is not None:
new_uri += '/' + self.key
if self.Key is not None:
new_uri += '/' + self.Key

elif self.name is not None:
new_uri += self.name
elif self.Name is not None:
new_uri += self.Name

# Add in all parameters including custom values
parameters = self._package_properties(
Expand Down
8 changes: 4 additions & 4 deletions tests/b3u_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def test_for_resource():

def test_for_get():
test_object = b3u('s3://abc:xyz@bucket/object.data')
assert test_object.for_get() == {'bucket': 'bucket', 'key': 'object.data'}
assert test_object.for_get() == {'Bucket': 'bucket', 'Key': 'object.data'}

test_object = b3u('ssm://ABC:XYZ@/path/to/parameter?region_name=us-east-1')
assert test_object.for_get() == {'name': '/path/to/parameter'}
assert test_object.for_get() == {'Name': '/path/to/parameter'}

test_object = b3u('foo://abc:xyz@bucket/object.data')
assert test_object.for_get() == {}
Expand All @@ -104,7 +104,7 @@ def test_to_string():

test_obj.region_name = 'us-east-2'
test_obj.aws_access_key_id = 'LMN'
test_obj.bucket = 'new_bucket'
test_obj.Bucket = 'new_bucket'
test_obj.other_param = 'new_value'

assert test_obj.to_string() == 's3://LMN:xyz@new_bucket/object.data?region_name=us-east-2&other_param=new_value'
Expand All @@ -126,5 +126,5 @@ def test_to_string():

test_object = b3u('ssm://ABC:XYZ@/path/to/parameter?region_name=us-east-1')
assert test_object.to_string() == 'ssm://ABC:XYZ@/path/to/parameter?region_name=us-east-1'
test_object.name = '/path/to/parameter2'
test_object.Name = '/path/to/parameter2'
assert test_object.to_string() == 'ssm://ABC:XYZ@/path/to/parameter2?region_name=us-east-1'

0 comments on commit bb3dd2c

Please sign in to comment.