Skip to content

Commit

Permalink
ensure relative path works properly for s3 improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Aug 9, 2023
1 parent 2745780 commit 98d6906
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
35 changes: 30 additions & 5 deletions tests/providers/s3/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,36 @@ class TestValidatePath:
async def test_validate_v1_path_file(self, provider, file_header_metadata, mock_time):
file_path = 'foobah'

params = {'prefix': '/' + file_path + '/', 'delimiter': '/'}
good_metadata_url = provider.bucket.new_key('/' + file_path).generate_url(100, 'HEAD')
bad_metadata_url = provider.bucket.generate_url(100)
aiohttpretty.register_uri('HEAD', good_metadata_url, headers=file_header_metadata)
aiohttpretty.register_uri('GET', bad_metadata_url, params=params, status=404)
good_metadata_url = provider.bucket.new_key(f'/{file_path}').generate_url(100, 'HEAD')
root_metadata_url = provider.bucket.new_key('/').generate_url(100, 'GET')
aiohttpretty.register_uri(
'HEAD',
good_metadata_url,
headers=file_header_metadata
)
aiohttpretty.register_uri(
'GET',
good_metadata_url,
headers=file_header_metadata
)
aiohttpretty.register_uri(
'GET',
root_metadata_url,
params={
'prefix': '/' + file_path + '/',
'delimiter': '/'
},
status=404
)
aiohttpretty.register_uri(
'GET',
root_metadata_url,
params={
'prefix': '/',
'delimiter': '/'
},
headers=file_header_metadata
)

assert WaterButlerPath('/') == await provider.validate_v1_path('/')

Expand Down
2 changes: 2 additions & 0 deletions waterbutler/providers/s3/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def name(self):

@property
def path(self):
if self.raw.get('base_folder'):
return '/' + self.raw['Prefix'].replace(self.raw['base_folder'], '')
return '/' + self.raw['Prefix']


Expand Down
12 changes: 10 additions & 2 deletions waterbutler/providers/s3/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ def __init__(self, auth, credentials, settings, **kwargs):
async def validate_v1_path(self, path, **kwargs):
await self._check_region()

if path == '/':
return WaterButlerPath(path)
base_folder = self.settings.get('id', ':/').split(':/')[1]
path = base_folder + path.lstrip('/')

if not path.startswith('/'):
path = f'/{path}'

implicit_folder = path.endswith('/')

Expand Down Expand Up @@ -686,6 +689,7 @@ async def _metadata_folder(self, path):
await self._check_region()

params = {'prefix': path.path, 'delimiter': '/'}

resp = await self.make_request(
'GET',
functools.partial(self.bucket.generate_url, settings.TEMP_URL_SECS, 'GET', query_parameters=params),
Expand Down Expand Up @@ -719,6 +723,10 @@ async def _metadata_folder(self, path):
if isinstance(prefixes, dict):
prefixes = [prefixes]

# The user selected base folder, the root of the where that user's node is connected.
for item in prefixes:
item['base_folder'] = self.settings.get('id', ':/').split(':/')[1]

items = [
S3FolderMetadata(item)
for item in prefixes
Expand Down

0 comments on commit 98d6906

Please sign in to comment.