-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
add rules for ASF S3 virtual host urls #6846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
39d0c87
to
bcc47b2
Compare
bcc47b2
to
540f802
Compare
540f802
to
69347dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good overall! just a couple of comments/questions before i approve the PR.
localstack/services/s3/provider.py
Outdated
original_host = copied_headers["Host"] | ||
copied_headers["Host"] = host | ||
params = {"data": request.data, "headers": copied_headers} | ||
response = requests.request(method=request.method, url=rewritten_url, **params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a question: as i understand we are forwarding the request to moto here, right? is moto doing a lot for us, or could we also implement the serving logic ourselves by accessing the moto backend directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's doing a lot. this can actually be any api call from s3, as everything in s3 works just with query-parameters and headers.
localstack/services/s3/provider.py
Outdated
copied_headers = copy.deepcopy(request.headers) | ||
# TODO is_internal_call_context | ||
original_host = copied_headers["Host"] | ||
copied_headers["Host"] = host | ||
params = {"data": request.data, "headers": copied_headers} | ||
response = requests.request(method=request.method, url=rewritten_url, **params) | ||
|
||
response.request.headers["Host"] = original_host | ||
response.request.url = request.url | ||
ls_response = convert_response(response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you considered using the localstack.http.proxy
module? it has a bunch of utilities that could simplify some of the code here. alternatively you could also use the HttpClient
from localstack.http.client
. in any case i would avoid importing convert_response
from the apigateway provider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will check, thanks :)
code, headers, body = fn(self, bucket_name, *args, **kwargs) | ||
bucket = self.backend.get_bucket(bucket_name) | ||
headers["x-amz-bucket-region"] = bucket.region_name | ||
headers["content-type"] = "application/xml" | ||
return code, headers, body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this is out of scope, but would it be better to remove this patch all together, and wrap the head_bucket
operation? or is that not an option because the moto response is a problem for our parser?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked to @bentsku about it: we probably change it in a future PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for clarifying and implementing the suggestions :-)
Buckets can be addressed either in path-style
s3.<region>.localhost.localstack.cloud:4566/mybucket
or virtual host-stylemybucket.<region>.localhost.localstack.cloud:4566
.Path style (without region) is covered by moto.
Note: AWS works a bit differently (also compared to the old provider): if bucket is created with a location constraint and the path-style contains another region, it would respond with 301 (for any region other than
us-east-1
), or 307 (forus-east-1
). see testtest_access_bucket_different_region