8000 Remove fallback account ID and region for core ARN builder by viren-nadkarni · Pull Request #9528 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

Remove fallback account ID and region for core ARN builder #9528

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

Merged
merged 6 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion localstack/services/s3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def capitalize_header_name_from_snake_case(header_name: str) -> str:
return "-".join([part.capitalize() for part in header_name.split("-")])


def get_kms_key_arn(kms_key: str, account_id: str, bucket_region: str = None) -> Optional[str]:
def get_kms_key_arn(kms_key: str, account_id: str, bucket_region: str) -> Optional[str]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch, thanks for fixing this! 🙏

"""
In S3, the KMS key can be passed as a KeyId or a KeyArn. This method allows to always get the KeyArn from either.
It can also validate if the key is in the same region, and raise an exception.
Expand Down
4 changes: 3 additions & 1 deletion localstack/services/s3/v3/provider.py
Original file line number Diff line number Diff line change
Expand Up < 8000 /td> @@ -3601,7 +3601,9 @@ def get_encryption_parameters_from_request_and_bucket(
key_id = kms_key_id or s3_bucket.encryption_rule[
"ApplyServerSideEncryptionByDefault"
].get("KMSMasterKeyID")
kms_key_id = get_kms_key_arn(key_id, s3_bucket.bucket_account_id)
kms_key_id = get_kms_key_arn(
key_id, s3_bucket.bucket_account_id, s3_bucket.bucket_region
)
if not kms_key_id:
# if not key is provided, AWS will use an AWS managed KMS key
# create it if it doesn't already exist, and save it in the store per region
Expand Down
12 changes: 3 additions & 9 deletions localstack/utils/aws/arns.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

from botocore.utils import ArnParser, InvalidArnException

from localstack.aws.accounts import DEFAULT_AWS_ACCOUNT_ID, get_aws_account_id
from localstack.aws.accounts import DEFAULT_AWS_ACCOUNT_ID
from localstack.aws.connect import connect_to
from localstack.utils.aws.aws_stack import get_region

LOG = logging.getLogger(__name__)

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


# TODO make account_id and region required
def _resource_arn(name: str, pattern: str, account_id: str = None, region_name: str = None) -> str:
def _resource_arn(name: str, pattern: str, account_id: str, region_name: str) -> str:
if ":" in name:
return name
account_id = account_id or get_aws_account_id()
region_name = region_name or get_region()
if len(pattern.split("%s")) == 3:
return pattern % (account_id, name)
return pattern % (region_name, account_id, name)
Expand Down Expand Up @@ -280,8 +276,6 @@ def sqs_queue_arn(queue_name: str, account_id: str, region_name: str) -> str:


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


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

def apigateway_invocations_arn(lambda_uri: str, region_name: str) -> str:
return "arn:aws:apigateway:%s:lambda:path/2015-03-31/functions/%s/invocations" % (
region_name or get_region(),
region_name,
lambda_uri,
)

Expand Down
Empty file.
2 changes: 1 addition & 1 deletion tests/aws/services/s3/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9912,7 +9912,7 @@ def test_s3_presigned_post_success_action_status_201_response(self, s3_bucket, a
assert "PostResponse" in json_response
json_response = json_response["PostResponse"]

location = f"{_bucket_url_vhost(s3_bucket, aws_stack.get_region())}/key-my-file"
location = f"{_bucket_url_vhost(s3_bucket, TEST_AWS_REGION_NAME)}/key-my-file"
etag = '"43281e21fce675ac3bcb3524b38ca4ed"'
assert response.headers["ETag"] == etag
assert response.headers["Location"] == location
Expand Down
0