Skip to content

Commit

Permalink
fix imports of bootstrap.auth modules in aws-replicator (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
whummer authored Nov 18, 2023
1 parent 2b07bcd commit 44db605
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions aws-replicator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ localstack extensions install "git+https://github.com/localstack/localstack-exte

## Change Log

* `0.1.4`: Fix imports of `bootstrap.auth` modules for v3.0 compatibility
* `0.1.3`: Adjust code imports for recent LocalStack v3.0 module changes
* `0.1.2`: Remove deprecated ProxyListener for starting local aws-replicator proxy server
* `0.1.1`: Add simple configuration Web UI
Expand Down
12 changes: 7 additions & 5 deletions aws-replicator/aws_replicator/client/auth_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from localstack.aws.api import HttpRequest
from localstack.aws.protocol.parser import create_parser
from localstack.aws.spec import load_service
from localstack.config import internal_service_url
from localstack.config import external_service_url
from localstack.constants import AWS_REGION_US_EAST_1, DOCKER_IMAGE_NAME_PRO
from localstack.http import Request
from localstack.utils.aws.aws_responses import requests_response
Expand All @@ -44,7 +44,9 @@
LOG.setLevel(logging.DEBUG)

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

CONTAINER_NAME_PREFIX = "ls-aws-proxy-"
CONTAINER_CONFIG_FILE = "/tmp/ls.aws.proxy.yml"
Expand Down Expand Up @@ -138,7 +140,7 @@ def register_in_instance(self):
port = getattr(self, "port", None)
if not port:
raise Exception("Proxy currently not running")
url = f"{internal_service_url()}{HANDLER_PATH_PROXIES}"
url = f"{external_service_url()}{HANDLER_PATH_PROXIES}"
data = AddProxyRequest(port=port, config=self.config)
try:
response = requests.post(url, json=data)
Expand Down Expand Up @@ -334,11 +336,11 @@ def start_aws_auth_proxy_in_container(
]
env_vars = env_vars or os.environ
env_vars = select_attributes(dict(env_vars), env_var_names)
env_vars["LOCALSTACK_HOSTNAME"] = "host.docker.internal"
env_vars["LOCALSTACK_HOST"] = "host.docker.internal"

try:
print("Proxy container is ready.")
command = f"{venv_activate}; localstack aws proxy -c {CONTAINER_CONFIG_FILE} -p {port} > {CONTAINER_LOG_FILE} 2>&1"
command = f"{venv_activate}; localstack aws proxy -c {CONTAINER_CONFIG_FILE} -p {port} --host 0.0.0.0 > {CONTAINER_LOG_FILE} 2>&1"
if quiet:
DOCKER_CLIENT.exec_in_container(
container_name, command=["bash", "-c", command], env_vars=env_vars, interactive=True
Expand Down
18 changes: 15 additions & 3 deletions aws-replicator/aws_replicator/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from localstack.cli import LocalstackCli, LocalstackCliPlugin, console
from localstack.logging.setup import setup_logging
from localstack.utils.files import load_file
from localstack_ext.bootstrap.licensing import api_key_configured, is_logged_in
from localstack_ext.bootstrap.auth import get_auth_headers
from localstack_ext.cli.aws import aws
from localstack_ext.config import is_api_key_configured

from aws_replicator.shared.models import ProxyConfig, ProxyServiceConfig

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

def should_load(self) -> bool:
return is_logged_in() or api_key_configured()
return _is_logged_in() or is_api_key_configured()

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


# TODO: remove over time as we're phasing out the `login` command
def _is_logged_in() -> bool:
try:
get_auth_headers()
return True
except Exception:
return False


@click.command(name="proxy", help="Start up an authentication proxy against real AWS")
@click.option(
"-s",
Expand Down Expand Up @@ -62,9 +72,11 @@ def cmd_aws_proxy(services: str, config: str, container: bool, port: int, host:
start_aws_auth_proxy_in_container,
)

config_json: ProxyConfig = {"services": {}, "bind_host": host}
config_json: ProxyConfig = {"services": {}}
if config:
config_json = yaml.load(load_file(config), Loader=yaml.SafeLoader)
if host:
config_json["bind_host"] = host
if services:
services = _split_string(services)
for service in services:
Expand Down
2 changes: 1 addition & 1 deletion aws-replicator/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = localstack-extension-aws-replicator
version = 0.1.3
version = 0.1.4
summary = LocalStack Extension: AWS replicator
description = Replicate AWS resources into your LocalStack instance
long_description = file: README.md
Expand Down

0 comments on commit 44db605

Please sign in to comment.