-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
implement S3 native CORS #8814
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
implement S3 native CORS #8814
Conversation
59f24eb
to
dd31f9c
Compare
dd31f9c
to
659e02d
Compare
659e02d
to
f0f245f
Compare
f0f245f
to
6d255bd
Compare
1ed59ac
to
0217ab6
Compare
6d255bd
to
897b718
Compare
fd2eeb9
to
4b8f4e6
Compare
4b8f4e6
to
4db25da
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 really good! I like the refactoring around the validators.
I have one minor suggestion but nothing blocking
localstack/services/s3/cors.py
Outdated
bucket_cors_index: BucketCorsIndex | ||
bucket_cors_index: BucketCorsIndex | BucketCorsIndexV2 | ||
|
||
def __init__(self): | ||
self.bucket_cors_index = BucketCorsIndex() | ||
def __init__(self, bucket_cors_index: BucketCorsIndex | BucketCorsIndexV2 = None): | ||
self.bucket_cors_index = bucket_cors_index or BucketCorsIndex() |
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.
This is a minor thing, but since S3CorsHandler
seems independent from the provider, maybe we could further remove the dependency here, instead of introducing a dependency to both providers.
Suggestion (note: remove the call to BucketCorsIndex()
):
introduce a Protocol here:
class BucketCorsIndex(Protocol):
@property
def cors(self) -> dict[str, CORSConfiguration]:
raise NotImplementedError
@property
def buckets(self) -> set[str]:
raise NotImplementedError
class S3CorsHandler(Handler):
bucket_cors_index: BucketCorsIndex
def __init__(self, bucket_cors_index: BucketCorsIndex):
self.bucket_cors_index = bucket_cors_index
...
then, make sure to instantiate the provider-specific BucketCorsIndex in the provier:
localstack/localstack/services/s3/provider.py
Line 249 in a7e97ea
self._cors_handler = S3CorsHandler() |
since it's a protocol and it's just for type checking, there's also no need to let the implementations inherit from the protocol class.
localstack/services/s3/validation.py
Outdated
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.
nice 💯
4db25da
to
0b78a1f
Compare
This PR implements CORS for the new S3 native provider. This is basically just to make it compatible between both provider.