Skip to content

Commit

Permalink
[FAB-1959] Support proxy auth in java buildscript
Browse files Browse the repository at this point in the history
java buildscript of Docker image cannot work in proxy
authentication environment because it does not support
authentication. This patch supports proxy authentication
in java buildscript. See FAB-1959

Change-Id: I5ee5526e0a06c59cfec440e61d0e37df96c1e4ef
Signed-off-by: Nao Nishijima <Nao.nishijima@hal.hitachi.com>
  • Loading branch information
Nao Nishijima authored and Nao Nishijima committed Apr 25, 2017
1 parent bf4f424 commit ad1200b
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions core/chaincode/shim/java/javabuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,30 @@ set -e
PARENTDIR=$(pwd)
ARCH=`uname -m`

function getProxyHost {
ADDR=${1#*://}
echo ${ADDR%:*}
}
pattern='(https?://)?((([^:\/]+)(:([^\/]*))?@)?([^:\/?]+)(:([0-9]+))?)'

function getProxyPort {
ADDR=${1#*://}
echo ${ADDR#*:}
}
[ -n "$http_proxy" ] && HTTPPROXY=$http_proxy
[ -n "$HTTP_PROXY" ] && HTTPPROXY=$HTTP_PROXY
[ -n "$https_proxy" ] && HTTPSPROXY=$https_proxy
[ -n "$HTTPS_PROXY" ] && HTTPSPROXY=$HTTPS_PROXY

if [ -n "$HTTPPROXY" ]; then
if [[ "$HTTPPROXY" =~ $pattern ]]; then
[ -n "${BASH_REMATCH[4]}" ] && JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyUser=${BASH_REMATCH[4]}"
[ -n "${BASH_REMATCH[6]}" ] && JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyPass=${BASH_REMATCH[6]}"
[ -n "${BASH_REMATCH[7]}" ] && JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=${BASH_REMATCH[7]}"
[ -n "${BASH_REMATCH[9]}" ] && JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyPort=${BASH_REMATCH[9]}"
fi
fi
if [ -n "$HTTPSPROXY" ]; then
if [[ "$HTTPSPROXY" =~ $pattern ]]; then
[ -n "${BASH_REMATCH[4]}" ] && JAVA_OPTS="$JAVA_OPTS -Dhttps.proxyUser=${BASH_REMATCH[4]}"
[ -n "${BASH_REMATCH[6]}" ] && JAVA_OPTS="$JAVA_OPTS -Dhttps.proxyPass=${BASH_REMATCH[6]}"
[ -n "${BASH_REMATCH[7]}" ] && JAVA_OPTS="$JAVA_OPTS -Dhttps.proxyHost=${BASH_REMATCH[7]}"
[ -n "${BASH_REMATCH[9]}" ] && JAVA_OPTS="$JAVA_OPTS -Dhttps.proxyPort=${BASH_REMATCH[9]}"
fi
fi

[ -n "$http_proxy" ] && JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=$(getProxyHost $http_proxy) -Dhttp.proxyPort=$(getProxyPort $http_proxy)"
[ -n "$https_proxy" ] && JAVA_OPTS="$JAVA_OPTS -Dhttps.proxyHost=$(getProxyHost $https_proxy) -Dhttps.proxyPort=$(getProxyPort $https_proxy)"
[ -n "$HTTP_PROXY" ] && JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=$(getProxyHost $HTTP_PROXY) -Dhttp.proxyPort=$(getProxyPort $HTTP_PROXY)"
[ -n "$HTTPS_PROXY" ] && JAVA_OPTS="$JAVA_OPTS -Dhttps.proxyHost=$(getProxyHost $HTTPS_PROXY) -Dhttps.proxyPort=$(getProxyPort $HTTPS_PROXY)"
export JAVA_OPTS

if [ x$ARCH == xx86_64 ]
Expand Down

0 comments on commit ad1200b

Please sign in to comment.