8000 fix imports of bootstrap.auth modules in aws-replicator (#44) · localstack/localstack-extensions@44db605 · GitHub
[go: up one dir, main page]

Skip to content

Commit 44db605

Browse files
authored
fix imports of bootstrap.auth modules in aws-replicator (#44)
1 parent 2b07bcd commit 44db605

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

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.4`: Fix imports of `bootstrap.auth` modules for v3.0 compatibility
118119
* `0.1.3`: Adjust code imports for recent LocalStack v3.0 module changes
119120
* `0.1.2`: Remove deprecated ProxyListener for starting local aws-replicator proxy server
120121
* `0.1.1`: Add simple configuration Web UI

aws-replicator/aws_replicator/client/auth_proxy.py

Lines changed: 7 additions & 5 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 internal_service_url
20+
from localstack.config import external_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
@@ -44,7 +44,9 @@
4444
LOG.setLevel(logging.DEBUG)
4545

4646
# TODO make configurable
47-
CLI_PIP_PACKAGE = "git+https://github.com/localstack/localstack-extensions/@main#egg=localstack-extension-aws-replicator&subdirectory=aws-replicator"
47+
CLI_PIP_PACKAGE = "localstack-extension-aws-replicator"
48+
# note: enable the line below temporarily for testing:
49+
# CLI_PIP_PACKAGE = "git+https://github.com/localstack/localstack-extensions/@branch#egg=localstack-extension-aws-replicator&subdirectory=aws-replicator"
4850

4951
CONTAINER_NAME_PREFIX = "ls-aws-proxy-"
5052
CONTAINER_CONFIG_FILE = "/tmp/ls.aws.proxy.yml"
@@ -138,7 +140,7 @@ def register_in_instance(self):
138140
port = getattr(self, "port", None)
139141
if not port:
140142
raise Exception("Proxy currently not running")
141-
url = f"{internal_service_url()}{HANDLER_PATH_PROXIES}"
143+
url = f"{external_service_url()}{HANDLER_PATH_PROXIES} 8000 "
142144
data = AddProxyRequest(port=port, config=self.config)
143145
try:
144146
response = requests.post(url, json=data)
@@ -334,11 +336,11 @@ def start_aws_auth_proxy_in_container(
334336
]
335337
env_vars = env_vars or os.environ
336338
env_vars = select_attributes(dict(env_vars), env_var_names)
337-
env_vars["LOCALSTACK_HOSTNAME"] = "host.docker.internal"
339+
env_vars["LOCALSTACK_HOST"] = "host.docker.internal"
338340

339341
try:
340342
print("Proxy container is ready.")
341-
command = f"{venv_activate}; localstack aws proxy -c {CONTAINER_CONFIG_FILE} -p {port} > {CONTAINER_LOG_FILE} 2>&1"
343+
command = f"{venv_activate}; localstack aws proxy -c {CONTAINER_CONFIG_FILE} -p {port} --host 0.0.0.0 > {CONTAINER_LOG_FILE} 2>&1"
342344
if quiet:
343345
DOCKER_CLIENT.exec_in_container(
344346
container_name, command=["bash", "-c", command], env_vars=env_vars, interactive=True

aws-replicator/aws_replicator/client/cli.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
from localstack.cli import LocalstackCli, LocalstackCliPlugin, console
77
from localstack.logging.setup import setup_logging
88
from localstack.utils.files import load_file
9-
from localstack_ext.bootstrap.licensing import api_key_configured, is_logged_in
9+
from localstack_ext.bootstrap.auth import get_auth_headers
1010
from localstack_ext.cli.aws import aws
11+
from localstack_ext.config import is_api_key_configured
1112

1213
from aws_replicator.shared.models import ProxyConfig, ProxyServiceConfig
1314

@@ -16,7 +17,7 @@ class AwsReplicatorPlugin(LocalstackCliPlugin):
1617
name = "aws-replicator"
1718

1819
def should_load(self) -> bool:
19-
return is_logged_in() or api_key_configured()
20+
return _is_logged_in() or is_api_key_configured()
2021

2122
def attach(self, cli: LocalstackCli) -> None:
2223
group: click.Group = cli.group
@@ -26,6 +27,15 @@ def attach(self, cli: LocalstackCli) -> None:
2627
aws.add_command(cmd_aws_replicate)
2728

2829

30+
# TODO: remove over time as we're phasing out the `login` command
31+
def _is_logged_in() -> bool:
32+
try:
33+
get_auth_headers()
34+
return True
35+
except Exception:
36+
return False
37+
38+
2939
@click.command(name="proxy", help="Start up an authentication proxy against real AWS")
3040
@click.option(
3141
"-s",
@@ -62,9 +72,11 @@ def cmd_aws_proxy(services: str, config: str, container: bool, port: int, host:
6272
start_aws_auth_proxy_in_container,
6373
)
6474

65-
config_json: ProxyConfig = {"services": {}, "bind_host": host}
75+
config_json: ProxyConfig = {"services": {}}
6676
if config:
6777
config_json = yaml.load(load_file(config), Loader=yaml.SafeLoader)
78+
if host:
79+
config_json["bind_host"] = host
6880
if services:
6981
services = _split_string(services)
7082
for service in services:

aws-replicator/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = localstack-extension-aws-replicator
3-
version = 0.1.3
3+
version = 0.1.4
44
summary = LocalStack Extension: AWS replicator
55
description = Replicate AWS resources into your LocalStack instance
66
long_description = file: README.md

0 commit comments

Comments
 (0)
0