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)
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
59 if [ ! -e "$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
64 if [ ! -e "$DOT_AAF/truststoreONAPall.jks" ]; then
66 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks
69 # Create Deployer Info, located at /root/.aaf
70 if [ ! -e "$DOT_AAF/keyfile" ]; then
71 $JAVA_AGENT cadi keygen $DOT_AAF/keyfile
72 chmod 400 $DOT_AAF/keyfile
74 # Add Deployer Creds to Root's SSO
75 DEPLOY_FQI="${DEPLOY_FQI:=$app_id}"
76 echo "aaf_id=${DEPLOY_FQI}" > ${SSO}
77 if [ ! "${DEPLOY_PASSWORD}" = "" ]; then
78 echo aaf_password=enc:$(sso_encrypt ${DEPLOY_PASSWORD}) >> ${SSO}
81 # Cover case where using app.props
82 aaf_locator_container_ns=${aaf_locator_container_ns:=$CONTAINER_NS}
83 if [ "$aaf_locator_container" = "docker" ]; then
84 echo "aaf_locate_url=https://aaf-locate:8095" >> ${SSO}
85 echo "aaf_url_cm=https://aaf-cm:8150" >> ${SSO}
86 echo "aaf_url=https://aaf-service:8100" >> ${SSO}
88 echo "aaf_locate_url=https://$aaf-locator.${CONTAINER_NS}:8095" >> ${SSO}
89 echo "aaf_url_cm=https://AAF_LOCATE_URL/%CNS.%NS.cm:2.1" >> ${SSO}
90 echo "aaf_url=https://AAF_LOCATE_URL/%CNS.%NS.service:2.1" >> ${SSO}
93 echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO}
94 echo "cadi_truststore_password=changeit" >> ${SSO}
95 echo "cadi_latitude=${LATITUDE}" >> ${SSO}
96 echo "cadi_longitude=${LONGITUDE}" >> ${SSO}
97 echo "hostname=${aaf_locator_fqdn}" >> ${SSO}
99 # Push in all AAF and CADI properties to SSO
101 if [ "${E:0:4}" = "aaf_" ] || [ "${E:0:5}" = "cadi_" ]; then
102 # Use Deployer ID in ${SSO}
103 if [ "app_id" != "${E%=*}" ]; then
112 echo "Caller Properties Initialized"
118 # Check for local dir
119 if [ -d $LOCAL ]; then
123 echo "Created $LOCAL"
127 echo "Existing files in $LOCAL"
130 # Should we clean up?
131 if [ "${VERSION}" != "$(cat ${LOCAL}/VERSION 2> /dev/null)" ]; then
132 echo "Clean up directory ${LOCAL}"
135 echo "${VERSION}" > $LOCAL/VERSION
137 echo "Namespace is ${NS}"
138 # Only initialize once, automatically...
139 if [ ! -e $LOCAL/${NS}.props ]; then
140 echo "#### Create Configuration files "
141 $JAVA_AGENT config $APP_FQI $APP_FQDN
145 echo "#### Certificate Authorization Artifact"
148 $JAVA_AGENT read ${APP_FQI} ${APP_FQDN} | tee $TMP
150 if [ -n "$(grep 'Namespace:' $TMP)" ]; then
151 echo "#### Place Certificates (by deployer)"
152 $JAVA_AGENT place $APP_FQI $APP_FQDN
154 if [ -z "$(grep cadi_alias $NS.cred.props)" ]; then
155 echo "FAILED to get Certificate"
158 echo "Obtained Certificates"
159 echo "#### Validate Configuration and Certificate with live call"
160 $JAVA_AGENT validate cadi_prop_files=${NS}.props
164 echo "#### Certificate Authorization Artifact must be valid to continue"
173 if [ -z "$CMD" ]; then
174 if [ -n "$INITIALIZED" ]; then
175 echo "Initialization complete"
183 find /opt/app/osaaf -depth
186 if [ "$1" = "" ]; then
187 echo "usage: cat <file... ONLY files ending in .props>"
189 if [[ $1 == *.props ]]; then
191 echo "## CONTENTS OF $3"
195 echo "### ERROR ####"
196 echo " \"cat\" may only be used with files ending with \".props\""
201 echo "## Show Passwords"
202 $JAVA_AGENT showpass $APP_FQI $APP_FQDN cadi_prop_files=${SSO}
205 echo "## Check Certificate"
206 echo "$JAVA_AGENT check $APP_FQI $APP_FQDN cadi_prop_files=${LOCAL}/${NS}.props"
207 $JAVA_AGENT check $APP_FQI $APP_FQDN cadi_prop_files=${LOCAL}/${NS}.props
210 echo "## validate requested"
211 $JAVA_AGENT validate $APP_FQI $APP_FQDN
214 echo "## Renew Certificate"
215 $JAVA_AGENT place $APP_FQI $APP_FQDN cadi_prop_files=${SSO}
218 echo "## Renew Certificate"
219 $JAVA_AGENT place $APP_FQI $APP_FQDN
228 FILES=$(grep -l "$1" ./*.props)
229 if [ -z "$FILES" ]; then
238 if [ "$ADD" = "Y" ]; then
239 echo "Changing $1 to $F"
242 echo "Changing $1 in $F"
243 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
251 FILES=$(grep -l "$1" ./*.props)
252 if [ "$FILES" = "" ]; then
253 FILES=$LOCAL/${NS}.cred.props
257 echo "Changing $1 in $F"
258 if [ "$2" = "" ]; then
259 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
261 if [ "$ORIG_PW" = "" ]; then
268 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/${NS}.keyfile)
269 if [ "$ADD" = "Y" ]; then
270 echo "$1=enc:$PWD" >> $F
272 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
278 sh /opt/app/osaaf/logs/taillog
280 testConnectivity|testconnectivity)
281 echo "--- Test Connectivity ---"
282 $JAVA -cp $CONFIG_BIN/aaf-auth-cmd-*-full.jar org.onap.aaf.cadi.aaf.TestConnectivity $LOCAL/org.osaaf.aaf.props
287 echo "--- Agent Container Comands ---"
288 echo " ls - Lists all files in Configuration"
289 echo " cat <file.props>> - Shows the contents (Prop files only)"
290 echo " validate - Runs a test using Configuration"
291 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
292 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
293 echo " bash - run bash in Container"
294 echo " Note: the following aliases are preset"
295 echo " cadi - CADI CmdLine tool"
296 echo " agent - Agent Java tool (see above help)"
298 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
301 echo "--- cadi Tool Comands ---"
305 echo "--- agent Tool Comands ---"
309 echo "--- aafcli Tool Comands ---"
317 # echo "--- run Sample Servlet App ---"
318 # $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -cp $CONFIG_BIN/aaf-auth-cmd-*-full.jar:$CONFIG_BIN/aaf-cadi-servlet-sample-*-sample.jar org.onap.aaf.sample.cadi.jetty.JettyStandalone ${NS}.props
321 $JAVA_AGENT "$CMD" "$@"