Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4b8518e

Browse files
Remove fallback account ID and region for core ARN builder (localstack#9528)
1 parent 78999d0 commit 4b8518e

File tree

5 files changed

+8
-12
lines changed

5 files changed

+8
-12
lines changed

‎localstack/services/s3/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ def capitalize_header_name_from_snake_case(header_name: str) -> str:
593593
return "-".join([part.capitalize() for part in header_name.split("-")])
594594

595595

596-
def get_kms_key_arn(kms_key: str, account_id: str, bucket_region: str = None) -> Optional[str]:
596+
def get_kms_key_arn(kms_key: str, account_id: str, bucket_region: str) -> Optional[str]:
597597
"""
598598
In S3, the KMS key can be passed as a KeyId or a KeyArn. This method allows to always get the KeyArn from either.
599599
It can also validate if the key is in the same region, and raise an exception.

‎localstack/services/s3/v3/provider.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3601,7 +3601,9 @@ def get_encryption_parameters_from_request_and_bucket(
36013601
key_id = kms_key_id or s3_bucket.encryption_rule[
36023602
"ApplyServerSideEncryptionByDefault"
36033603
].get("KMSMasterKeyID")
3604-
kms_key_id = get_kms_key_arn(key_id, s3_bucket.bucket_account_id)
3604+
kms_key_id = get_kms_key_arn(
3605+
key_id, s3_bucket.bucket_account_id, s3_bucket.bucket_region
3606+
)
36053607
if not kms_key_id:
36063608
# if not key is provided, AWS will use an AWS managed KMS key
36073609
# create it if it doesn't already exist, and save it in the store per region

‎localstack/utils/aws/arns.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
from botocore.utils import ArnParser, InvalidArnException
77

8-
from localstack.aws.accounts import DEFAULT_AWS_ACCOUNT_ID, get_aws_account_id
8+
from localstack.aws.accounts import DEFAULT_AWS_ACCOUNT_ID
99
from localstack.aws.connect import connect_to
10-
from localstack.utils.aws.aws_stack import get_region
1110

1211
LOG = logging.getLogger(__name__)
1312

@@ -72,12 +71,9 @@ def extract_resource_from_arn(arn: str) -> Optional[str]:
7271
#
7372

7473

75-
# TODO make account_id and region required
76-
def _resource_arn(name: str, pattern: str, account_id: str = None, region_name: str = None) -> str:
74+
def _resource_arn(name: str, pattern: str, account_id: str, region_name: str) -> str:
7775
if ":" in name:
7876
return name
79-
account_id = account_id or get_aws_account_id()
80-
region_name = region_name or get_region()
8177
if len(pattern.split("%s")) == 3:
8278
return pattern % (account_id, name)
8379
return pattern % (region_name, account_id, name)
@@ -280,8 +276,6 @@ def sqs_queue_arn(queue_name: str, account_id: str, region_name: str) -> str:
280276

281277

282278
def apigateway_restapi_arn(api_id: str, account_id: str, region_name: str) -> str:
283-
account_id = account_id or get_aws_account_id()
284-
region_name = region_name or get_region()
285279
return "arn:aws:apigateway:%s:%s:/restapis/%s" % (region_name, account_id, api_id)
286280

287281

@@ -299,7 +293,7 @@ def opensearch_domain_name(domain_arn: str) -> str:
299293

300294
def apigateway_invocations_arn(lambda_uri: str, region_name: str) -> str:
301295
return "arn:aws:apigateway:%s:lambda:path/2015-03-31/functions/%s/invocations" % (
302-
region_name or get_region(),
296+
region_name,
303297
lambda_uri,
304298
)
305299

‎tests/aws/services/lambda_/test_lambda_legacy.py

Whitespace-only changes.

‎tests/aws/services/s3/test_s3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9912,7 +9912,7 @@ def test_s3_presigned_post_success_action_status_201_response(self, s3_bucket, a
99129912
assert "PostResponse" in json_response
99139913
json_response = json_response["PostResponse"]
99149914

9915-
location = f"{_bucket_url_vhost(s3_bucket, aws_stack.get_region())}/key-my-file"
9915+
location = f"{_bucket_url_vhost(s3_bucket, TEST_AWS_REGION_NAME)}/key-my-file"
99169916
etag = '"43281e21fce675ac3bcb3524b38ca4ed"'
99179917
assert response.headers["ETag"] == etag
99189918
assert response.headers["Location"] == location

0 commit comments

Comments
 (0)