Skip to content

Commit 3a30b68

Browse files
rgolanghdjzager
authored andcommitted
Validate and print usage in case of wrong entrypoint usage (#49)
The entrypoint assumes a second ($2) argument is a json string but immediatly after evaluating the first one if shifts, rendering the $2 empty. Since there is no input validation it was impossible to understand the problem without reading the code. - validate that 3 args are passed in - print a usage error with usefull info - map the deprecated flag so it will be easy to remove in the future Signed-off-by: Roy Golan <[email protected]>
1 parent 614afab commit 3a30b68

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

files/usr/bin/entrypoint.sh

+20-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ if [[ $BUNDLE_DEBUG == "true" ]]; then
44
set -x
55
fi
66

7+
usage() {
8+
echo -n 'Usage: entrypoint.sh ACTION FLAG JSONSTRING
9+
ACTION - one of [provision, deprovision, bind, unbind, test] verbs
10+
FLAG - deprecated and will be dropped in the future
11+
JSONSTRING - a valid json string to be used as extra args for the playbook execution
12+
13+
The command line args are positional.
14+
Please see the this for reference - https://github.com/openshift/ansible-service-broker/blob/ansible-service-broker-1.4.1-1/docs/service-bundle.md#input
15+
'
16+
}
17+
718
# Work-Around
819
# The OpenShift's s2i (source to image) requires that no ENTRYPOINT exist
920
# for any of the s2i builder base images. Our 's2i-apb' builder uses the
@@ -29,17 +40,21 @@ if ! whoami &> /dev/null; then
2940
fi
3041
fi
3142

43+
3244
ACTION=$1
33-
shift
45+
FLAG=$2
46+
JSONSTRING=$3
47+
[[ "$#" -lt 3 ]] && usage && exit 1
48+
3449
PLAYBOOKS="/opt/apb/project"
3550
PASSWORDS="/opt/apb/env/passwords"
3651
EXTRAVARS="/opt/apb/env/extravars"
3752
CREDS="/var/tmp/bind-creds"
3853
TEST_RESULT="/var/tmp/test-result"
3954
SECRETS_DIR="/etc/apb-secrets"
40-
GALAXY_URL=$(echo $2 | python -c 'import sys, json; print json.load(sys.stdin)["galaxy_url"]' 2>/dev/null || echo "null")
41-
ROLE_NAME=$(echo $2 | python -c 'import sys, json; print json.load(sys.stdin)["role_name"]' 2>/dev/null || echo "null")
42-
ROLE_NAMESPACE=$(echo $2 | python -c 'import sys, json; print json.load(sys.stdin)["role_namespace"]' 2>/dev/null || echo "null")
55+
GALAXY_URL=$(echo $JSONSTRING | python -c 'import sys, json; print json.load(sys.stdin)["galaxy_url"]' 2>/dev/null || echo "null")
56+
ROLE_NAME=$(echo $JSONSTRING | python -c 'import sys, json; print json.load(sys.stdin)["role_name"]' 2>/dev/null || echo "null")
57+
ROLE_NAMESPACE=$(echo $JSONSTRING | python -c 'import sys, json; print json.load(sys.stdin)["role_namespace"]' 2>/dev/null || echo "null")
4358

4459
# Handle mounted secrets
4560
mounted_secrets=$(ls $SECRETS_DIR)
@@ -53,7 +68,7 @@ if [[ ! -z "$mounted_secrets" ]] ; then
5368
fi
5469

5570
# Add extravars
56-
echo $2 > $EXTRAVARS
71+
echo $JSONSTRING > $EXTRAVARS
5772

5873
# Install role from galaxy
5974
# Used when apb-base is the runner image for the ansible-galaxy adapter

0 commit comments

Comments
 (0)