Skip to content

Commit abab8f2

Browse files
committed
raise proper exception if CORS does not exist in store
1 parent 54eef43 commit abab8f2

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

localstack/services/s3/provider.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22
import logging
33
import os
4-
from typing import IO, Dict, List
4+
from typing import IO, Dict, List, Optional
55
from urllib.parse import parse_qs, quote, urlencode, urlparse, urlunparse
66

77
import moto.s3.responses as moto_s3_responses
@@ -65,6 +65,7 @@
6565
MissingSecurityHeader,
6666
MultipartUpload,
6767
NoSuchBucket,
68+
NoSuchCORSConfiguration,
6869
NoSuchKey,
6970
NoSuchLifecycleConfiguration,
7071
NoSuchWebsiteConfiguration,
@@ -179,8 +180,11 @@ def get_full_default_bucket_location(bucket_name):
179180

180181
class S3Provider(S3Api, ServiceLifecycleHook):
181182
@staticmethod
182-
def get_store() -> S3Store:
183-
return s3_stores[get_aws_account_id()][aws_stack.get_region()]
183+
def get_store(context: Optional[RequestContext] = None) -> S3Store:
184+
if not context:
185+
return s3_stores[get_aws_account_id()][aws_stack.get_region()]
186+
187+
return s3_stores[context.account_id][context.region]
184188

185189
def _clear_bucket_from_store(self, bucket: BucketName):
186190
store = self.get_store()
@@ -807,22 +811,27 @@ def put_bucket_cors(
807811
expected_bucket_owner: AccountId = None,
808812
) -> None:
809813
response = call_moto(context)
810-
self.get_store().bucket_cors[bucket] = cors_configuration
814+
self.get_store(context).bucket_cors[bucket] = cors_configuration
811815
self._cors_handler.invalidate_cache()
812816
return response
813817

814818
def get_bucket_cors(
815819
self, context: RequestContext, bucket: BucketName, expected_bucket_owner: AccountId = None
816820
) -> GetBucketCorsOutput:
817821
call_moto(context)
818-
cors_rules = self.get_store().bucket_cors.get(bucket)
822+
cors_rules = self.get_store(context).bucket_cors.get(bucket)
823+
if not cors_rules:
824+
raise NoSuchCORSConfiguration(
825+
"The CORS configuration does not exist",
826+
BucketName=bucket,
827+
)
819828
return GetBucketCorsOutput(CORSRules=cors_rules["CORSRules"])
820829

821830
def delete_bucket_cors(
822831
self, context: RequestContext, bucket: BucketName, expected_bucket_owner: AccountId = None
823832
) -> None:
824833
response = call_moto(context)
825-
if self.get_store().bucket_cors.pop(bucket, None):
834+
if self.get_store(context).bucket_cors.pop(bucket, None):
826835
self._cors_handler.invalidate_cache()
827836
return response
828837

0 commit comments

Comments
 (0)