mirror of https://github.com/samply/bridgehead.git
Merge pull request #127 from samply/fix/proxy_usage
Added proxy user + pw detection
This commit is contained in:
commit
b52d49b4ef
|
@ -65,6 +65,7 @@ loadVars() {
|
||||||
fi
|
fi
|
||||||
detectCompose
|
detectCompose
|
||||||
setHostname
|
setHostname
|
||||||
|
setupProxy
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$ACTION" in
|
case "$ACTION" in
|
||||||
|
|
|
@ -9,6 +9,33 @@ detectCompose() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupProxy() {
|
||||||
|
### Note: As the current data protection concepts do not allow communication via HTTP,
|
||||||
|
### we are not setting a proxy for HTTP requests.
|
||||||
|
|
||||||
|
local http="no"
|
||||||
|
local https="no"
|
||||||
|
if [ $HTTPS_PROXY_URL ]; then
|
||||||
|
local proto="$(echo $HTTPS_PROXY_URL | grep :// | sed -e 's,^\(.*://\).*,\1,g')"
|
||||||
|
local fqdn="$(echo ${HTTPS_PROXY_URL/$proto/})"
|
||||||
|
local hostport=$(echo $HTTPS_PROXY_URL | sed -e "s,$proto,,g" | cut -d/ -f1)
|
||||||
|
HTTPS_PROXY_HOST="$(echo $hostport | sed -e 's,:.*,,g')"
|
||||||
|
HTTPS_PROXY_PORT="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')"
|
||||||
|
if [[ ! -z "$HTTPS_PROXY_USERNAME" && ! -z "$HTTPS_PROXY_PASSWORD" ]]; then
|
||||||
|
local proto="$(echo $HTTPS_PROXY_URL | grep :// | sed -e 's,^\(.*://\).*,\1,g')"
|
||||||
|
local fqdn="$(echo ${HTTPS_PROXY_URL/$proto/})"
|
||||||
|
HTTPS_PROXY_FULL_URL="$(echo $proto$HTTPS_PROXY_USERNAME:$HTTPS_PROXY_PASSWORD@$fqdn)"
|
||||||
|
https="authenticated"
|
||||||
|
else
|
||||||
|
HTTPS_PROXY_FULL_URL=$HTTPS_PROXY_URL
|
||||||
|
https="unauthenticated"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
log INFO "Configuring proxy servers: $http http proxy (we're not supporting unencrypted comms), $https https proxy"
|
||||||
|
export HTTPS_PROXY_HOST HTTPS_PROXY_PORT HTTPS_PROXY_FULL_URL
|
||||||
|
}
|
||||||
|
|
||||||
exitIfNotRoot() {
|
exitIfNotRoot() {
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
log "ERROR" "Please run as root"
|
log "ERROR" "Please run as root"
|
||||||
|
|
|
@ -47,8 +47,8 @@ function hc_send(){
|
||||||
|
|
||||||
if [ -n "$2" ]; then
|
if [ -n "$2" ]; then
|
||||||
MSG="$2\n\nDocker stats:\n$UPTIME"
|
MSG="$2\n\nDocker stats:\n$UPTIME"
|
||||||
echo -e "$MSG" | https_proxy=$HTTPS_PROXY_URL curl --max-time 5 -A "$USER_AGENT" -s -o /dev/null -X POST --data-binary @- "$HCURL"/"$1" || log WARN "Monitoring failed: Unable to send data to $HCURL/$1"
|
echo -e "$MSG" | https_proxy=$HTTPS_PROXY_FULL_URL curl --max-time 5 -A "$USER_AGENT" -s -o /dev/null -X POST --data-binary @- "$HCURL"/"$1" || log WARN "Monitoring failed: Unable to send data to $HCURL/$1"
|
||||||
else
|
else
|
||||||
https_proxy=$HTTPS_PROXY_URL curl --max-time 5 -A "$USER_AGENT" -s -o /dev/null "$HCURL"/"$1" || log WARN "Monitoring failed: Unable to send data to $HCURL/$1"
|
https_proxy=$HTTPS_PROXY_FULL_URL curl --max-time 5 -A "$USER_AGENT" -s -o /dev/null "$HCURL"/"$1" || log WARN "Monitoring failed: Unable to send data to $HCURL/$1"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ source /etc/bridgehead/${PROJECT}.conf
|
||||||
source ${PROJECT}/vars
|
source ${PROJECT}/vars
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
SERVERTIME="$(https_proxy=$HTTPS_PROXY_URL curl -m 5 -s -I $BROKER_URL_FOR_PREREQ 2>&1 | grep -i -e '^Date: ' | sed -e 's/^Date: //i')"
|
SERVERTIME="$(https_proxy=$HTTPS_PROXY_FULL_URL curl -m 5 -s -I $BROKER_URL_FOR_PREREQ 2>&1 | grep -i -e '^Date: ' | sed -e 's/^Date: //i')"
|
||||||
RET=$?
|
RET=$?
|
||||||
set -e
|
set -e
|
||||||
if [ $RET -ne 0 ]; then
|
if [ $RET -ne 0 ]; then
|
||||||
|
|
|
@ -50,12 +50,12 @@ for DIR in /etc/bridgehead $(pwd); do
|
||||||
git -C $DIR config credential.helper "$CREDHELPER"
|
git -C $DIR config credential.helper "$CREDHELPER"
|
||||||
fi
|
fi
|
||||||
old_git_hash="$(git -C $DIR rev-parse --verify HEAD)"
|
old_git_hash="$(git -C $DIR rev-parse --verify HEAD)"
|
||||||
if [ -z "$HTTP_PROXY_URL" ]; then
|
if [ -z "$HTTPS_PROXY_FULL_URL" ]; then
|
||||||
log "INFO" "Git is using no proxy!"
|
log "INFO" "Git is using no proxy!"
|
||||||
OUT=$(retry 5 git -C $DIR fetch 2>&1 && retry 5 git -C $DIR pull 2>&1)
|
OUT=$(retry 5 git -C $DIR fetch 2>&1 && retry 5 git -C $DIR pull 2>&1)
|
||||||
else
|
else
|
||||||
log "INFO" "Git is using proxy ${HTTP_PROXY_URL} from ${CONFFILE}"
|
log "INFO" "Git is using proxy ${HTTPS_PROXY_URL} from ${CONFFILE}"
|
||||||
OUT=$(retry 5 git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR fetch 2>&1 && retry 5 git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR pull 2>&1)
|
OUT=$(retry 5 git -c https.proxy=$HTTPS_PROXY_FULL_URL -C $DIR fetch 2>&1 && retry 5 git -c https.proxy=$HTTPS_PROXY_FULL_URL -C $DIR pull 2>&1)
|
||||||
fi
|
fi
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
report_error log "Unable to update git $DIR: $OUT"
|
report_error log "Unable to update git $DIR: $OUT"
|
||||||
|
|
Loading…
Reference in New Issue