3 # ============LICENSE_START====================================================
5 # ===========================================================================
6 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
7 # ===========================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # ============LICENSE_END====================================================
21 # This script is run when starting client Container.
22 # It needs to cover the cases where the initial data doesn't exist, and when it has already been configured (don't overwrite)
24 JAVA=${JAVA_HOME}/bin/java
25 AAF_INTERFACE_VERSION=2.1
27 # Extract Name, Domain and NS from FQI
28 FQIA=($(echo ${APP_FQI} | tr '@' '\n'))
31 # Reverse DOMAIN for NS
32 FQIA_E=($(echo ${FQI_DOMAIN} | tr '.' '\n'))
33 for (( i=( ${#FQIA_E[@]} -1 ); i>0; i-- )); do
34 NS=${NS}${FQIA_E[i]}'.'
37 CONFIG="/opt/app/aaf_config"
38 OSAAF="/opt/app/osaaf"
41 SSO="$DOT_AAF/sso.props"
43 if [ -e "$CONFIG" ]; then
44 CONFIG_BIN="$CONFIG/bin"
49 AGENT_JAR="$CONFIG_BIN/aaf-cadi-aaf-*-full.jar"
51 JAVA_AGENT="$JAVA -Dcadi_loglevel=DEBUG -Dcadi_etc_dir=${LOCAL} -Dcadi_log_dir=${LOCAL} -jar $AGENT_JAR "
53 # Setup SSO info for Deploy ID
54 function sso_encrypt() {
55 $JAVA_AGENT cadi digest ${1} $DOT_AAF/keyfile
58 # Setup Bash, first time only, Agent only
59 if [ -n "$HOME/.bashrc" ] || [ -z "$(grep agent $HOME/.bashrc)" ]; then
60 echo "alias agent='$CONFIG_BIN/agent.sh agent \$*'" > $HOME/.bashrc
61 chmod a+x $CONFIG_BIN/agent.sh
65 if [ ! -e "$DOT_AAF/truststoreONAPall.jks" ]; then
67 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks
70 # Create Deployer Info, located at /root/.aaf
71 if [ ! -e "$DOT_AAF/keyfile" ]; then
72 $JAVA_AGENT cadi keygen $DOT_AAF/keyfile
73 chmod 400 $DOT_AAF/keyfile
74 echo "cadi_keyfile=$DOT_AAF/keyfile" > ${SSO}
76 # Add Deployer Creds to Root's SSO
77 DEPLOY_FQI="${DEPLOY_FQI:=$app_id}"
78 echo "aaf_id=${DEPLOY_FQI}" >> ${SSO}
79 if [ ! "${DEPLOY_PASSWORD}" = "" ]; then
80 echo aaf_password=enc:$(sso_encrypt ${DEPLOY_PASSWORD}) >> ${SSO}
83 # Cover case where using app.props
84 aaf_locator_container_ns=${aaf_locator_container_ns:=$CONTAINER_NS}
85 if [ "$aaf_locator_container" = "docker" ]; then
86 echo "aaf_locate_url=https://aaf-locate:8095" >> ${SSO}
87 echo "aaf_url_cm=https://aaf-cm:8150" >> ${SSO}
88 echo "aaf_url=https://aaf-service:8100" >> ${SSO}
90 echo "aaf_locate_url=https://$aaf-locator.${CONTAINER_NS}:8095" >> ${SSO}
91 echo "aaf_url_cm=https://AAF_LOCATE_URL/%CNS.%NS.cm:2.1" >> ${SSO}
92 echo "aaf_url=https://AAF_LOCATE_URL/%CNS.%NS.service:2.1" >> ${SSO}
95 echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO}
96 echo "cadi_truststore_password=changeit" >> ${SSO}
97 echo "cadi_latitude=${LATITUDE}" >> ${SSO}
98 echo "cadi_longitude=${LONGITUDE}" >> ${SSO}
99 echo "hostname=${aaf_locator_fqdn}" >> ${SSO}
101 # Push in all AAF and CADI properties to SSO
103 if [ "${E:0:4}" = "aaf_" ] || [ "${E:0:5}" = "cadi_" ]; then
104 # Use Deployer ID in ${SSO}
105 if [ "app_id" != "${E%=*}" ]; then
114 echo "Caller Properties Initialized"
120 # Check for local dir
121 if [ -d $LOCAL ]; then
125 echo "Created $LOCAL"
129 echo "Existing files in $LOCAL"
132 # Should we clean up?
133 if [ "${VERSION}" != "$(cat ${LOCAL}/VERSION 2> /dev/null)" ]; then
134 echo "Clean up directory ${LOCAL}"
139 echo "${VERSION}" > $LOCAL/VERSION
141 echo "#!/bin/bash" > $LOCAL/agent
142 echo 'java -jar aaf-cadi-aaf-*-full.jar $*' >> $LOCAL/agent
143 echo "#!/bin/bash" > $LOCAL/cadi
144 echo 'java -jar aaf-cadi-aaf-*-full.jar cadi $*' >> $LOCAL/cadi
145 chmod 755 $LOCAL/agent $LOCAL/cadi
147 echo "Namespace is ${NS}"
148 # Only initialize once, automatically...
149 if [ -n $LOCAL/${NS}.props ]; then
150 echo "#### Create Configuration files "
152 $JAVA_AGENT config $APP_FQI $APP_FQDN --nopasswd
156 echo "#### Certificate Authorization Artifact"
159 $JAVA_AGENT read ${APP_FQI} ${APP_FQDN} | tee $TMP
161 if [ -n "$(grep 'Namespace:' $TMP)" ]; then
162 echo "#### Place Certificates (by deployer)"
163 $JAVA_AGENT place $APP_FQI $APP_FQDN
165 if [ -z "$(grep cadi_alias $NS.cred.props)" ]; then
166 echo "FAILED to get Certificate"
169 echo "Obtained Certificates"
170 echo "#### Validate Configuration and Certificate with live call"
171 $JAVA_AGENT validate cadi_prop_files=${NS}.props
175 echo "#### Certificate Authorization Artifact must be valid to continue"
184 if [ -z "$CMD" ]; then
185 if [ -n "$INITIALIZED" ]; then
186 echo "Initialization complete"
194 find /opt/app/osaaf -depth
197 if [ "$1" = "" ]; then
198 echo "usage: cat <file... ONLY files ending in .props>"
200 if [[ $1 == *.props ]]; then
202 echo "## CONTENTS OF $3"
206 echo "### ERROR ####"
207 echo " \"cat\" may only be used with files ending with \".props\""
212 echo "## Read Artifacts"
213 $JAVA_AGENT read $APP_FQI $APP_FQDN cadi_prop_files=${SSO} cadi_loglevel=INFO
216 echo "## Show Passwords"
217 $JAVA_AGENT showpass $APP_FQI $APP_FQDN cadi_prop_files=${SSO} cadi_loglevel=ERROR
220 echo "## Check Certificate"
221 echo "$JAVA_AGENT check $APP_FQI $APP_FQDN cadi_prop_files=${LOCAL}/${NS}.props"
222 $JAVA_AGENT check $APP_FQI $APP_FQDN cadi_prop_files=${LOCAL}/${NS}.props
225 echo "## validate requested"
226 $JAVA_AGENT validate $APP_FQI $APP_FQDN
229 echo "## Renew Certificate"
230 $JAVA_AGENT place $APP_FQI $APP_FQDN cadi_prop_files=${SSO}
233 echo "## Renew Certificate"
234 $JAVA_AGENT place $APP_FQI $APP_FQDN
243 FILES=$(grep -l "$1" ./*.props)
244 if [ -z "$FILES" ]; then
253 if [ "$ADD" = "Y" ]; then
254 echo "Changing $1 to $F"
257 echo "Changing $1 in $F"
258 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
266 FILES=$(grep -l "$1" ./*.props)
267 if [ "$FILES" = "" ]; then
268 FILES=$LOCAL/${NS}.cred.props
272 echo "Changing $1 in $F"
273 if [ "$2" = "" ]; then
274 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
276 if [ "$ORIG_PW" = "" ]; then
283 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/${NS}.keyfile)
284 if [ "$ADD" = "Y" ]; then
285 echo "$1=enc:$PWD" >> $F
287 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
293 sh /opt/app/osaaf/logs/taillog
295 testConnectivity|testconnectivity)
296 echo "--- Test Connectivity ---"
297 $JAVA -cp $AGENT_JAR org.onap.aaf.cadi.aaf.TestConnectivity $LOCAL/org.osaaf.aaf.props
302 echo "--- Agent Container Comands ---"
303 echo " ls - Lists all files in Configuration"
304 echo " cat <file.props>> - Shows the contents (Prop files only)"
305 echo " validate - Runs a test using Configuration"
306 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
307 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
308 echo " bash - run bash in Container"
309 echo " Note: the following aliases are preset"
310 echo " cadi - CADI CmdLine tool"
311 echo " agent - Agent Java tool (see above help)"
313 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
316 echo "--- cadi Tool Comands ---"
320 echo "--- agent Tool Comands ---"
324 echo "--- aafcli Tool Comands ---"
332 # echo "--- run Sample Servlet App ---"
333 # $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -cp $AGENT_JAR:$CONFIG_BIN/aaf-cadi-servlet-sample-*-sample.jar org.onap.aaf.sample.cadi.jetty.JettyStandalone ${NS}.props
336 $JAVA_AGENT "$CMD" "$@"