Skip to content

Commit 2b07bcd

Browse files
authored
adjust aws-replicator code imports for v3 changes (#43)
1 parent 0067af5 commit 2b07bcd

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

.github/workflows/aws-replicator.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ jobs:
8282
AWS_SECRET_ACCESS_KEY: ${{ secrets.TEST_AWS_SECRET_ACCESS_KEY }}
8383
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
8484
run: |
85-
# TODO tmp fix for https://github.com/localstack/localstack/issues/8267:
86-
pip install --upgrade 'botocore<1.31.81'
8785
cd aws-replicator/example
8886
make test
8987

aws-replicator/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ localstack extensions install "git+https://github.com/localstack/localstack-exte
115115

116116
## Change Log
117117

118+
* `0.1.3`: Adjust code imports for recent LocalStack v3.0 module changes
118119
* `0.1.2`: Remove deprecated ProxyListener for starting local aws-replicator proxy server
119120
* `0.1.1`: Add simple configuration Web UI
120121
* `0.1.0`: Initial version of extension

aws-replicator/aws_replicator/client/auth_proxy.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from localstack.aws.api import HttpRequest
1818
from localstack.aws.protocol.parser import create_parser
1919
from localstack.aws.spec import load_service
20-
from localstack.config import get_edge_url
20+
from localstack.config import internal_service_url
2121
from localstack.constants import AWS_REGION_US_EAST_1, DOCKER_IMAGE_NAME_PRO
2222
from localstack.http import Request
2323
from localstack.utils.aws.aws_responses import requests_response
@@ -30,8 +30,8 @@
3030
from localstack.utils.net import get_free_tcp_port
3131
from localstack.utils.server.http2_server import run_server
3232
from localstack.utils.serving import Server
33-
from localstack.utils.strings import short_uid, to_str, truncate
34-
from localstack_ext.bootstrap.licensing import ENV_LOCALSTACK_API_KEY
33+
from localstack.utils.strings import short_uid, to_bytes, to_str, truncate
34+
from localstack_ext.bootstrap.licensingv2 import ENV_LOCALSTACK_API_KEY
3535
from requests import Response
3636

3737
from aws_replicator.client.utils import truncate_content
@@ -138,7 +138,7 @@ def register_in_instance(self):
138138
port = getattr(self, "port", None)
139139
if not port:
140140
raise Exception("Proxy currently not running")
141-
url = f"{get_edge_url()}{HANDLER_PATH_PROXIES}"
141+
url = f"{internal_service_url()}{HANDLER_PATH_PROXIES}"
142142
data = AddProxyRequest(port=port, config=self.config)
143143
try:
144144
response = requests.post(url, json=data)
@@ -214,13 +214,22 @@ def _adjust_request_dict(self, service_name: str, request_dict: Dict):
214214
'<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">'
215215
f"<LocationConstraint>{region}</LocationConstraint></CreateBucketConfiguration>"
216216
)
217+
217218
if service_name == "sqs" and isinstance(req_body, dict):
218219
account_id = self._query_account_id_from_aws()
219220
if "QueueUrl" in req_body:
220221
queue_name = req_body["QueueUrl"].split("/")[-1]
221222
req_body["QueueUrl"] = f"https://queue.amazonaws.com/{account_id}/{queue_name}"
222223
if "QueueOwnerAWSAccountId" in req_body:
223224
req_body["QueueOwnerAWSAccountId"] = account_id
225+
if service_name == "sqs" and request_dict.get("url"):
226+
req_json = run_safe(lambda: json.loads(body_str)) or {}
227+
account_id = self._query_account_id_from_aws()
228+
queue_name = req_json.get("QueueName")
229+
if account_id and queue_name:
230+
request_dict["url"] = f"https://queue.amazonaws.com/{account_id}/{queue_name}"
231+
req_json["QueueOwnerAWSAccountId"] = account_id
232+
request_dict["body"] = to_bytes(json.dumps(req_json))
224233

225234
def _fix_headers(self, request: HttpRequest, service_name: str):
226235
if service_name == "s3":

aws-replicator/aws_replicator/server/aws_request_forwarder.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def select_proxy(self, context: RequestContext) -> Optional[ProxyInstance]:
6161
proxy = self.PROXY_INSTANCES[port]
6262
proxy_config = proxy.get("config") or {}
6363
services = proxy_config.get("services") or {}
64-
service_config = services.get(context.service.service_name)
64+
service_name = self._get_canonical_service_name(context.service.service_name)
65+
service_config = services.get(service_name)
6566
if not service_config:
6667
continue
6768

@@ -96,11 +97,12 @@ def select_proxy(self, context: RequestContext) -> Optional[ProxyInstance]:
9697
def _request_matches_resource(
9798
self, context: RequestContext, resource_name_pattern: str
9899
) -> bool:
99-
if context.service.service_name == "s3":
100+
service_name = self._get_canonical_service_name(context.service.service_name)
101+
if service_name == "s3":
100102
bucket_name = context.service_request.get("Bucket") or ""
101103
s3_bucket_arn = arns.s3_bucket_arn(bucket_name)
102104
return bool(re.match(resource_name_pattern, s3_bucket_arn))
103-
if context.service.service_name == "sqs":
105+
if service_name == "sqs":
104106
queue_name = context.service_request.get("QueueName") or ""
105107
queue_url = context.service_request.get("QueueUrl") or ""
106108
queue_name = queue_name or queue_url.split("/")[-1]
@@ -200,3 +202,9 @@ def _get_resource_names(cls, service_config: ProxyServiceConfig) -> list[str]:
200202
default_names = [".*"]
201203
result = service_config.get("resources") or default_names
202204
return ensure_list(result)
205+
206+
@classmethod
207+
def _get_canonical_service_name(cls, service_name: str) -> str:
208+
if service_name == "sqs-query":
209+
return "sqs"
210+
return service_name

aws-replicator/setup.cfg

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = localstack-extension-aws-replicator
3-
version = 0.1.2
3+
version = 0.1.3
44
summary = LocalStack Extension: AWS replicator
55
description = Replicate AWS resources into your LocalStack instance
66
long_description = file: README.md
@@ -16,8 +16,7 @@ install_requires =
1616
# TODO: currently requires a version pin, see note in auth_proxy.py
1717
boto3>=1.26.151
1818
# TODO: currently requires a version pin, see note in auth_proxy.py
19-
# TODO: upper version pin due to https://github.com/localstack/localstack/issues/8267
20-
botocore>=1.29.151,<1.31.81
19+
botocore>=1.29.151
2120
flask
2221
localstack
2322
localstack-client

0 commit comments

Comments
 (0)