-
Notifications
You must be signed in to change notification settings - Fork 123
Prevent randomness in health check endpoint #2013
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
Changes from all commits
b5c592f
ef887d3
48af9b0
8b1d90c
86d03dc
f736684
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| from . import multihash | ||
|
|
||
|
|
||
| def get_ip(request_obj): | ||
| """Gets the IP address from a request using the X-Forwarded-For header if present""" | ||
| ip = request_obj.headers.get("X-Forwarded-For", request_obj.remote_addr) | ||
|
|
@@ -27,6 +28,16 @@ def get_ip(request_obj): | |
| return ip.split(",")[0].strip() | ||
|
|
||
|
|
||
| def get_openresty_public_key(): | ||
| """Get public key for openresty if it is running""" | ||
| try: | ||
| resp = requests.get("http://localhost:5000/openresty_pubkey") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should never change after a container comes up right? and openresty should always boot up first before web server
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's right, this function is to just keep the code for this isolated |
||
| resp.raise_for_status() | ||
| return resp.text | ||
| except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError): | ||
| return None | ||
|
|
||
|
|
||
| def redis_restore(redis, key): | ||
| logger = logging.getLogger(__name__) | ||
| filename = f"{key}_dump" | ||
|
|
@@ -50,6 +61,7 @@ def redis_get_or_restore(redis, key): | |
| value = redis.get(key) | ||
| return value if value else redis_restore(redis, key) | ||
|
|
||
|
|
||
| def redis_get_json_cached_key_or_restore(redis, key): | ||
| logger = logging.getLogger(__name__) | ||
| cached_value = redis.get(key) | ||
|
|
@@ -68,6 +80,7 @@ def redis_get_json_cached_key_or_restore(redis, key): | |
| logger.info(f"Redis Cache - miss {key}") | ||
| return None | ||
|
|
||
|
|
||
| def redis_dump(redis, key): | ||
| logger = logging.getLogger(__name__) | ||
| try: | ||
|
|
@@ -85,6 +98,7 @@ def redis_set_json_and_dump(redis, key, value): | |
| serialized = json.dumps(value) | ||
| redis_set_and_dump(redis, key, serialized) | ||
|
|
||
|
|
||
| def redis_set_and_dump(redis, key, value): | ||
| redis.set(key, value) | ||
| redis_dump(redis, key) | ||
|
|
@@ -113,6 +127,7 @@ def bytes32_to_str(bytes32input): | |
| r"^(?:^|[ \t])((https?:\/\/)?(?:localhost|[\w-]+(?:\.[\w-]+)+)(:\d+)?(\/\S*)?)$" | ||
| ) | ||
|
|
||
|
|
||
| # Helper function to check if a given string is a valid FQDN | ||
| def is_fqdn(endpoint_str): | ||
| # Regex used to verify valid FQDN | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.