This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch v2-1-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v2-1-test by this push:
new c11d368 Sane detection of the host/port in entrypoint prod (#17847)
c11d368 is described below
commit c11d368b236f27681b85c35dcf5ad2ec10df6193
Author: Jarek Potiuk <[email protected]>
AuthorDate: Fri Aug 27 17:22:15 2021 +0200
Sane detection of the host/port in entrypoint prod (#17847)
The previous regexp parsing was well, not perfect closely following the
ancient Chinese proverb "If you have problem, introduce regexp - you
will have two problems".
This PR replaces regexp matching with python urlsplit method.
Fixes: #17828
(cherry picked from commit 275e0d1b91949ad1a1b916b0ffa27009e0797fea)
---
scripts/in_container/prod/entrypoint_prod.sh | 25 +++++++------------------
1 file changed, 7 insertions(+), 18 deletions(-)
diff --git a/scripts/in_container/prod/entrypoint_prod.sh
b/scripts/in_container/prod/entrypoint_prod.sh
index 674b569..bcf57c0 100755
--- a/scripts/in_container/prod/entrypoint_prod.sh
+++ b/scripts/in_container/prod/entrypoint_prod.sh
@@ -75,6 +75,7 @@ function run_nc() {
nc -zvvn "${ip}" "${port}"
}
+
function wait_for_connection {
# Waits for Connection to the backend specified via URL passed as first
parameter
# Detects backend type depending on the URL schema and assigns
@@ -83,24 +84,12 @@ function wait_for_connection {
# It tries `CONNECTION_CHECK_MAX_COUNT` times and sleeps
`CONNECTION_CHECK_SLEEP_TIME` between checks
local connection_url
connection_url="${1}"
- local detected_backend=""
- local detected_host=""
- local detected_port=""
-
- # Auto-detect DB parameters
- # Examples:
- # postgres://YourUserName:password@YourHostname:5432/YourDatabaseName
- # postgres://YourUserName:password@YourHostname:5432/YourDatabaseName
- # postgres://YourUserName:@YourHostname:/YourDatabaseName
- # postgres://YourUserName@YourHostname/YourDatabaseName
- [[ ${connection_url} =~
([^:]*)://([^:@]*):?([^@]*)@?([^/:]*):?([0-9]*)/([^\?]*)\??(.*) ]] && \
- detected_backend=${BASH_REMATCH[1]} &&
- # Not used USER match
- # Not used PASSWORD match
- detected_host=${BASH_REMATCH[4]} &&
- detected_port=${BASH_REMATCH[5]} &&
- # Not used SCHEMA match
- # Not used PARAMS match
+ local detected_backend
+ detected_backend=$(python -c "from urllib.parse import urlsplit; import
sys; print(urlsplit(sys.argv[1]).scheme)" "${connection_url}")
+ local detected_host
+ detected_host=$(python -c "from urllib.parse import urlsplit; import sys;
print(urlsplit(sys.argv[1]).hostname)" "${connection_url}")
+ local detected_port
+ detected_port=$(python -c "from urllib.parse import urlsplit; import sys;
print(urlsplit(sys.argv[1]).port or '')" "${connection_url}")
echo BACKEND="${BACKEND:=${detected_backend}}"
readonly BACKEND