|
5 | 5 | from typing import Dict, Optional, Union |
6 | 6 |
|
7 | 7 | import boto3 |
| 8 | +from moto.core import DEFAULT_ACCOUNT_ID |
8 | 9 |
|
9 | 10 | from localstack import config |
10 | | -from localstack.aws.accounts import get_aws_account_id |
11 | 11 | from localstack.config import S3_VIRTUAL_HOSTNAME |
12 | 12 | from localstack.constants import ( |
13 | 13 | AWS_REGION_US_EAST_1, |
@@ -98,20 +98,23 @@ def get_s3_hostname(): |
98 | 98 | return LOCALHOST |
99 | 99 |
|
100 | 100 |
|
101 | | -def fix_account_id_in_arns(response, colon_delimiter=":", existing=None, replace=None): |
| 101 | +def fix_account_id_in_arns( |
| 102 | + response, replacement: str, colon_delimiter: str = ":", existing: str | list[str] = None |
| 103 | +): |
102 | 104 | """Fix the account ID in the ARNs returned in the given Flask response or string""" |
103 | | - existing = existing or ["123456789", "1234567890", "123456789012", get_aws_account_id()] |
| 105 | + existing = existing or ["123456789", "1234567890", DEFAULT_ACCOUNT_ID] |
104 | 106 | existing = existing if isinstance(existing, list) else [existing] |
105 | | - replace = replace or get_aws_account_id() |
106 | 107 | is_str_obj = is_string_or_bytes(response) |
107 | 108 | content = to_str(response if is_str_obj else response._content) |
108 | 109 |
|
109 | | - replace = r"arn{col}aws{col}\1{col}\2{col}{acc}{col}".format(col=colon_delimiter, acc=replace) |
| 110 | + replacement = r"arn{col}aws{col}\1{col}\2{col}{acc}{col}".format( |
| 111 | + col=colon_delimiter, acc=replacement |
| 112 | + ) |
110 | 113 | for acc_id in existing: |
111 | 114 | regex = r"arn{col}aws{col}([^:%]+){col}([^:%]*){col}{acc}{col}".format( |
112 | 115 | col=colon_delimiter, acc=acc_id |
113 | 116 | ) |
114 | | - content = re.sub(regex, replace, content) |
| 117 | + content = re.sub(regex, replacement, content) |
115 | 118 |
|
116 | 119 | if not is_str_obj: |
117 | 120 | response._content = content |
|
0 commit comments