support bucket names in url paths in s3bucket_path
This commit is contained in:
parent
59858dd685
commit
5a475881d2
13 changed files with 575 additions and 163 deletions
2
moto/s3bucket_path/__init__.py
Normal file
2
moto/s3bucket_path/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
from .models import s3bucket_path_backend
|
||||
mock_s3bucket_path = s3bucket_path_backend.decorator
|
||||
7
moto/s3bucket_path/models.py
Normal file
7
moto/s3bucket_path/models.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from moto.s3.models import S3Backend
|
||||
|
||||
|
||||
class S3BucketPathBackend(S3Backend):
|
||||
True
|
||||
|
||||
s3bucket_path_backend = S3BucketPathBackend()
|
||||
15
moto/s3bucket_path/responses.py
Normal file
15
moto/s3bucket_path/responses.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from .models import s3bucket_path_backend
|
||||
|
||||
from .utils import bucket_name_from_url
|
||||
|
||||
from moto.s3.responses import ResponseObject
|
||||
|
||||
|
||||
def parse_key_name(pth):
|
||||
return "/".join(pth.rstrip("/").split("/")[2:])
|
||||
|
||||
S3BucketPathResponseInstance = ResponseObject(
|
||||
s3bucket_path_backend,
|
||||
bucket_name_from_url,
|
||||
parse_key_name,
|
||||
)
|
||||
20
moto/s3bucket_path/urls.py
Normal file
20
moto/s3bucket_path/urls.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from .responses import S3BucketPathResponseInstance as ro
|
||||
|
||||
url_bases = [
|
||||
"https?://s3.amazonaws.com"
|
||||
]
|
||||
|
||||
|
||||
def bucket_response2(*args):
|
||||
return ro.bucket_response(*args)
|
||||
|
||||
|
||||
def bucket_response3(*args):
|
||||
return ro.bucket_response(*args)
|
||||
|
||||
url_paths = {
|
||||
'{0}/$': bucket_response3,
|
||||
'{0}/(?P<bucket_name>[a-zA-Z0-9\-_.]+)$': ro.bucket_response,
|
||||
'{0}/(?P<bucket_name>[a-zA-Z0-9\-_.]+)/$': bucket_response2,
|
||||
'{0}/(?P<bucket_name>[a-zA-Z0-9\-_./]+)/(?P<key_name>[a-zA-Z0-9\-_.?]+)': ro.key_response
|
||||
}
|
||||
10
moto/s3bucket_path/utils.py
Normal file
10
moto/s3bucket_path/utils.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import urlparse
|
||||
|
||||
|
||||
def bucket_name_from_url(url):
|
||||
pth = urlparse.urlparse(url).path.lstrip("/")
|
||||
|
||||
l = pth.lstrip("/").split("/")
|
||||
if len(l) == 0 or l[0] == "":
|
||||
return None
|
||||
return l[0]
|
||||
Loading…
Add table
Add a link
Reference in a new issue