-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
5637712
Start tests for url returning
simonrw 0325017
Add patch_hostnames fixture
simonrw 480bb2f
Add test for s3 location
simonrw 61c4994
Add helpers for configuring the hostname
simonrw 3ede981
Use host utils in opensearch
simonrw dd812b5
Update S3 to use new host config
simonrw fe4d980
Cover more cases with SQS tests
simonrw 74abbfb
Partially update SQS to use the new config
simonrw 1a1df4e
Add `assert_host_customisation` fixture
simonrw 91e483f
Update lambda function urls to use new localstack_host function
simonrw 2b5d625
Correct typo with localstack-hostname value
simonrw c94c3f1
Set localstack_hostname to the hostname of the host
simonrw edad51b
Handle S3 201 response hostname returning
simonrw a912dc9
S3 vpath: handle HOSTNAME_EXTERNAL if supplied
simonrw bae2c59
Update s3 vhosts to use new localstack_host config
simonrw 888059a
Run ASF tests correctly
simonrw fef6b5c
Run ASF lambda tests correctly
simonrw 53dab3a
Add explanation comment for socket.gethostname
simonrw 9845857
Update `s3_listener._update_location`
simonrw 600d22f
Make suggested changes to sqs tests
simonrw 75176fe
Remove outdated comment
simonrw fa16a0d
Merge branch 'master' into network-unification
simonrw 263bacb
Merge branch 'master' into network-unification
simonrw a75d3e1
Merge branch 'master' into network-unification
simonrw 2c5899f
Fix pro integration test with s3
simonrw 46ea0e9
Fix issue with legacy s3 provider
simonrw ba95b63
Increase timeout of tests
simonrw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
from queue import PriorityQueue | ||
from typing import Dict, NamedTuple, Optional, Set | ||
|
||
from localstack import config, constants | ||
from localstack import config | ||
from localstack.aws.api import RequestContext | ||
from localstack.aws.api.sqs import ( | ||
InvalidAttributeName, | ||
|
@@ -21,7 +21,7 @@ | |
ReceiptHandleIsInvalid, | ||
TagMap, | ||
) | ||
from localstack.config import external_service_url | ||
from localstack.config import get_protocol | ||
from localstack.services.sqs import constants as sqs_constants | ||
from localstack.services.sqs.exceptions import ( | ||
InvalidAttributeValue, | ||
|
@@ -35,6 +35,7 @@ | |
) | ||
from localstack.services.stores import AccountRegionBundle, BaseStore, LocalAttribute | ||
from localstack.utils.time import now | ||
from localstack.utils.urls import localstack_host | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
<
F421
svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-fold-down">
|
@@ -249,13 +250,18 @@ def url(self, context: RequestContext) -> str: | |
# or us-east-2.queue.localhost.localstack.cloud:4566/000000000000/my-queue | ||
region = "" if self.region == "us-east-1" else self.region + "." | ||
scheme = context.request.scheme | ||
host_url = f"{scheme}://{region}queue.{constants.LOCALHOST_HOSTNAME}:{config.EDGE_PORT}" | ||
|
||
host_definition = localstack_host(use_localhost_cloud=True) | ||
host_url = f"{scheme}://{region}queue.{host_definition.host_and_port()}" | ||
elif config.SQS_ENDPOINT_STRATEGY == "path": | ||
# https?://localhost:4566/queue/us-east-1/00000000000/my-queue (us-east-1) | ||
host_url = f"{context.request.host_url}queue/{self.region}" | ||
else: | ||
if config.SQS_PORT_EXTERNAL: | ||
host_url = external_service_url("sqs") | ||
host_definition = localstack_host( | ||
use_hostname_external=True, custom_port=config.SQS_PORT_EXTERNAL | ||
) | ||
host_url = f"{get_protocol()}://{host_definition.host_and_port()}" | ||
|
||
return "{host}/{account_id}/{name}".format( | ||
host=host_url.rstrip("/"), | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 host_and_port(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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey! i can see that
SQS_PORT_EXTERNAL
is still in the control path here although we decided to boot it. can we just remove this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is just matching existing behaviour. I'll get rid of it in a follow up PR targeting the
v2
branch once this is merged 👍