Skip to content

Commit

Permalink
Merge pull request #43 from Appdynamics/features/controller-connection
Browse files Browse the repository at this point in the history
Validations - add controller connection check;
  • Loading branch information
AlexJov committed Feb 4, 2021
2 parents c057f3c + 60ff116 commit f2d0efe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
19 changes: 18 additions & 1 deletion modules/validations/controller.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#!/bin/bash

#todo
source ./modules/common/http_check.sh # func_check_http_status

_controller_url=${1} # hostname + /controller
_user_credentials=${2} # ${username}:${password}

_proxy_details=${3}

# Check if you can connect to a controler
echo "VAL|Checking connection to controller '${_controller_url}'..."

# timeout after 10s
controllerReponse=$(curl -s --user ${_user_credentials} ${_controller_url}/rest/applications ${_proxy_details} --connect-timeout 10)

if [ "$controllerReponse" = "" ]; then
func_check_http_status 404 "Unable to connect to controller: '"$_controller_url"'. Aborting..."
fi

echo "VAL||Succesfully reached '${_controller_url}'."
23 changes: 21 additions & 2 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -813,18 +813,32 @@ _arg_user_credentials="$_arg_username@$_arg_account:$_arg_password"

# 3.2 Set protocol

# extract protocol based on input flags
if [ $_arg_use_https = true ]; then
protocol="https"
else
protocol="http"
fi

# extract protocol from controller host variable, without trailing :// and convert to lower caps
_arg_controller_host_protocol="$(echo $_arg_controller_host | grep :// | sed -e's,^\(.*://\).*,\1,g' | sed 's/.\{3\}$//' | tr '[:upper:]' '[:lower:]')"

# if host url does not contain protocol
if [ -z "${_arg_controller_host_protocol}" ]; then
_arg_controller_host_protocol=$protocol
fi

# 3.3 Prepare controller url

# remove anything before // (protocol) and after : or / (path and/or port) in hostname - to keep only domain name
_arg_controller_host="$(echo $_arg_controller_host | sed -e 's|^[^/]*//||' -e 's|/.*$||' -e 's|:.*$||')"

_arg_controller_url="$protocol://$_arg_controller_host:$_arg_controller_port/controller"
_arg_controller_url="$_arg_controller_host_protocol://$_arg_controller_host:$_arg_controller_port/controller"

if [ "${protocol}" != "${_arg_controller_host_protocol}" ]; then
echo "WARNING --use-https / --no-use-https flag value '${protocol}' does not match controller host protocol '${_arg_controller_host_protocol}'."
echo " Note that controller host protocol takes precedence and final URL to connect to is: '${_arg_controller_url}'."
fi

# 3.4 Prepare proxy details

Expand Down Expand Up @@ -872,7 +886,12 @@ case $ec in
esac

## 2. contrtoller connection
#todo
./modules/validations/controller.sh "$_arg_controller_url" "$_arg_user_credentials" "$_arg_proxy_details" ; ec=$?

case $ec in
0) ;;
1) printf '%s\n' "Command exited with non-zero code"; exit 1;;
esac

## 3. application

Expand Down

0 comments on commit f2d0efe

Please sign in to comment.