|
1 | 1 | import datetime
|
2 | 2 | import logging
|
3 | 3 | import os
|
4 |
| -from typing import IO, Dict, List |
| 4 | +from typing import IO, Dict, List, Optional |
5 | 5 | from urllib.parse import parse_qs, quote, urlencode, urlparse, urlunparse
|
6 | 6 |
|
7 | 7 | import moto.s3.responses as moto_s3_responses
|
|
65 | 65 | MissingSecurityHeader,
|
66 | 66 | MultipartUpload,
|
67 | 67 | NoSuchBucket,
|
| 68 | + NoSuchCORSConfiguration, |
68 | 69 | NoSuchKey,
|
69 | 70 | NoSuchLifecycleConfiguration,
|
70 | 71 | NoSuchWebsiteConfiguration,
|
@@ -179,8 +180,11 @@ def get_full_default_bucket_location(bucket_name):
|
179 | 180 |
|
180 | 181 | class S3Provider(S3Api, ServiceLifecycleHook):
|
181 | 182 | @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] |
184 | 188 |
|
185 | 189 | def _clear_bucket_from_store(self, bucket: BucketName):
|
186 | 190 | store = self.get_store()
|
@@ -807,22 +811,27 @@ def put_bucket_cors(
|
807 | 811 | expected_bucket_owner: AccountId = None,
|
808 | 812 | ) -> None:
|
809 | 813 | response = call_moto(context)
|
810 |
| - self.get_store().bucket_cors[bucket] = cors_configuration |
| 814 | + self.get_store(context).bucket_cors[bucket] = cors_configuration |
811 | 815 | self._cors_handler.invalidate_cache()
|
812 | 816 | return response
|
813 | 817 |
|
814 | 818 | def get_bucket_cors(
|
815 | 819 | self, context: RequestContext, bucket: BucketName, expected_bucket_owner: AccountId = None
|
816 | 820 | ) -> GetBucketCorsOutput:
|
817 | 821 | 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 | + ) |
819 | 828 | return GetBucketCorsOutput(CORSRules=cors_rules["CORSRules"])
|
820 | 829 |
|
821 | 830 | def delete_bucket_cors(
|
822 | 831 | self, context: RequestContext, bucket: BucketName, expected_bucket_owner: AccountId = None
|
823 | 832 | ) -> None:
|
824 | 833 | 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): |
826 | 835 | self._cors_handler.invalidate_cache()
|
827 | 836 | return response
|
828 | 837 |
|
|
0 commit comments