8000 Unify hostnames in returned URLs by simonrw · Pull Request #7774 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

Unify hostnames in returned URLs #7774

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 27 commits into from
Mar 20, 2023
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5637712
Start tests for url returning
simonrw Feb 23, 2023
0325017
Add patch_hostnames fixture
simonrw Feb 27, 2023
480bb2f
Add test for s3 location
simonrw Feb 27, 2023
61c4994
Add helpers for configuring the hostname
simonrw Mar 1, 2023
3ede981
Use host utils in opensearch
simonrw Mar 1, 2023
dd812b5
Update S3 to use new host config
simonrw Mar 2, 2023
fe4d980
Cover more cases with SQS tests
simonrw Mar 3, 2023
74abbfb
Partially update SQS to use the new config
simonrw Mar 3, 2023
1a1df4e
Add `assert_host_customisation` fixture
simonrw Mar 3, 2023
91e483f
Update lambda function urls to use new localstack_host function
simonrw Mar 7, 2023
2b5d625
Correct typo with localstack-hostname value
simonrw Mar 8, 2023
c94c3f1
Set localstack_hostname to the hostname of the host
simonrw Mar 8, 2023
edad51b
Handle S3 201 response hostname returning
simonrw Mar 8, 2023
a912dc9
S3 vpath: handle HOSTNAME_EXTERNAL if supplied
simonrw Mar 9, 2023
bae2c59
Update s3 vhosts to use new localstack_host config
simonrw Mar 9, 2023
888059a
Run ASF tests correctly
simonrw Mar 10, 2023
fef6b5c
Run ASF lambda tests correctly
simonrw Mar 10, 2023
53dab3a
Add explanation comment for socket.gethostname
simonrw Mar 10, 2023
9845857
Update `s3_listener._update_location`
simonrw Mar 10, 2023
600d22f
Make suggested changes to sqs tests
simonrw Mar 10, 2023
75176fe
Remove outdated comment
simonrw Mar 13, 2023
fa16a0d
Merge branch 'master' into network-unification
simonrw Mar 15, 2023
263bacb
Merge branch 'master' into network-unification
simonrw Mar 16, 2023
a75d3e1
Merge branch 'master' into network-unification
simonrw Mar 17, 2023
2c5899f
Fix pro integration test with s3
simonrw Mar 17, 2023
46ea0e9
Fix issue with legacy s3 provider
simonrw Mar 17, 2023
ba95b63
Increase timeout of tests
simonrw Mar 17, 2023
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
Prev Previous commit
Next Next commit
Add helpers for configuring the hostname
  • Loading branch information
simonrw committed Mar 10, 2023
commit 61c4994606108b2bb9ae0a9a4264ff2a5b90996b
41 changes: 41 additions & 0 deletions localstack/utils/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
from dataclasses import dataclass
from typing import Optional

from localstack import config, constants


def path_from_url(url: str) -> str:
return f'/{url.partition("://")[2].partition("/")[2]}' if "://" in url else url


def hostname_from_url(url: str) -> str:
return url.split("://")[-1].split("/")[0].split(":")[0]


@dataclass
class HostDefinition:
host: str
port: int

def __str__(self):
return f"{self.host}:{self.port}"


def localstack_host(
use_hostname_external: bool = False,
use_localstack_hostname: bool = False,
use_localhost_cloud: bool = False,
custom_port: Optional[int] = None,
) -> HostDefinition:
"""
Determine the host and port to return to the user based on:
- the user's configuration (e.g environment variable overrides)
- the defaults of the system
"""
port = config.EDGE_PORT
if custom_port is not None:
port = custom_port

host = config.LOCALHOST
if use_hostname_external:
host = config.HOSTNAME_EXTERNAL
elif use_localstack_hostname:
host = config.LOCALSTACK_HOSTNAME
elif use_localhost_cloud:
host = constants.LOCALHOST_HOSTNAME

return HostDefinition(host=host, port=port)
0