Skip to content

Commit 680a58a

Browse files
Define and use LocalStack user-agent string
1 parent 8689130 commit 680a58a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

localstack-core/localstack/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
LOCALHOST_IP = "127.0.0.1"
2121
LOCALHOST_HOSTNAME = "localhost.localstack.cloud"
2222

23+
# User-agent string used in outgoing HTTP requests made by LocalStack
24+
USER_AGENT_STRING = f"localstack/{VERSION}"
25+
2326
# version of the Maven dependency with Java utility code
2427
LOCALSTACK_MAVEN_VERSION = "0.2.21"
2528
MAVEN_REPO_URL = "https://repo1.maven.org/maven2"

localstack-core/localstack/packages/java.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import requests
66

7+
from localstack.constants import USER_AGENT_STRING
78
from localstack.packages import InstallTarget, Package
89
from localstack.packages.core import ArchiveDownloadAndExtractInstaller
910
from localstack.utils.files import rm_rf
@@ -100,7 +101,8 @@ def _download_url_latest_release(self) -> str:
100101
f"https://api.adoptium.net/v3/assets/latest/{self.version}/hotspot?"
101102
f"os=linux&architecture={self.arch}&image_type=jdk"
102103
)
103-
response = requests.get(endpoint, headers={"user-agent": "example/0.0.0"}).json()
104+
# Override user-agent because Adoptium API denies service to `requests` library
105+
response = requests.get(endpoint, headers={"user-agent": USER_AGENT_STRING}).json()
104106
return response[0]["binary"]["package"]["link"]
105107

106108
def _download_url_fallback(self) -> str:

0 commit comments

Comments
 (0)