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 JAVA_CADI="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar org.onap.aaf.cadi.CmdLine"
44 JAVA_AGENT="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar -Dcadi_prop_files=$SSO org.onap.aaf.cadi.configure.Agent"
45 JAVA_AGENT_SELF="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar -Dcadi_prop_files=$LOCAL/${NS}.props org.onap.aaf.cadi.configure.Agent"
46 JAVA_AAFCLI="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props org.onap.aaf.auth.cmd.AAFcli"
49 if [ ! -d $LOCAL ]; then
53 cp $CONFIG/$D/*.* $OSAAF/$D
57 # Setup Bash, first time only
58 if [ ! -e "$HOME/.bashrc" ] || [ -z "$(grep cadi $HOME/.bashrc)" ]; then
59 echo "alias cadi='$JAVA_CADI \$*'" >>$HOME/.bashrc
60 echo "alias agent='$CONFIG/bin/agent.sh agent \$*'" >>$HOME/.bashrc
61 echo "alias aafcli='$JAVA_AAFCLI \$*'" >>$HOME/.bashrc
62 chmod a+x $CONFIG/bin/agent.sh
66 # Setup SSO info for Deploy ID
67 function sso_encrypt() {
68 $JAVA_CADI digest ${1} $DOT_AAF/keyfile
72 # Create Deployer Info, located at /root/.aaf
73 if [ ! -e "$DOT_AAF/keyfile" ]; then
75 $JAVA_CADI keygen $DOT_AAF/keyfile
76 chmod 400 $DOT_AAF/keyfile
77 echo cadi_latitude=${LATITUDE} > ${SSO}
78 echo cadi_longitude=${LONGITUDE} >> ${SSO}
79 echo aaf_id=${DEPLOY_FQI} >> ${SSO}
80 if [ ! "${DEPLOY_PASSWORD}" = "" ]; then
81 echo aaf_password=enc:$(sso_encrypt ${DEPLOY_PASSWORD}) >> ${SSO}
83 echo aaf_locate_url=https://${AAF_FQDN}:8095 >> ${SSO}
84 echo aaf_url=https://AAF_LOCATE_URL/AAF_NS.service:${AAF_INTERFACE_VERSION} >> ${SSO}
86 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks
87 echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO}
88 echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO}
89 echo "Caller Properties Initialized"
93 # Only initialize once, automatically...
94 if [ ! -e $LOCAL/${NS}.props ]; then
95 echo "#### Create Configuration files "
96 $JAVA_AGENT config $APP_FQI \
97 aaf_url=https://AAF_LOCATE_URL/AAF_NS.locate:${AAF_INTERFACE_VERSION} \
102 echo "#### Certificate Authorization Artifact"
104 $JAVA_AGENT read ${APP_FQI} ${APP_FQDN} \
105 cadi_prop_files=${SSO} \
106 cadi_etc_dir=$LOCAL > $TMP
109 if [ -n "$(grep 'Namespace:' $TMP)" ]; then
110 echo "#### Place Certificates (by deployer)"
111 $JAVA_AGENT place ${APP_FQI} ${APP_FQDN} \
112 cadi_prop_files=${SSO} \
115 echo "#### Validate Configuration and Certificate with live call"
116 $JAVA_AGENT_SELF validate
117 echo "Obtained Certificates"
120 echo "#### Certificate Authorization Artifact must be valid to continue"
127 if [ -z "$CMD" ]; then
128 if [ -n "$INITIALIZED" ]; then
129 echo "Initialization complete"
139 find /opt/app/osaaf -depth
142 if [ "$1" = "" ]; then
143 echo "usage: cat <file... ONLY files ending in .props>"
145 if [[ $1 == *.props ]]; then
147 echo "## CONTENTS OF $3"
151 echo "### ERROR ####"
152 echo " \"cat\" may only be used with files ending with \".props\""
157 echo "## Show Passwords"
158 $JAVA_AGENT showpass ${APP_FQI} ${APP_FQDN}
161 $JAVA_AGENT check ${APP_FQI} ${APP_FQDN}
164 echo "## validate requested"
165 $JAVA_AGENT_SELF validate
174 FILES=$(grep -l "$1" ./*.props)
175 if [ -z "$FILES" ]; then
184 if [ "$ADD" = "Y" ]; then
185 echo "Changing $1 to $F"
188 echo "Changing $1 in $F"
189 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
197 FILES=$(grep -l "$1" ./*.props)
198 if [ "$FILES" = "" ]; then
199 FILES=$LOCAL/${NS}.cred.props
203 echo "Changing $1 in $F"
204 if [ "$2" = "" ]; then
205 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
207 if [ "$ORIG_PW" = "" ]; then
214 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/${NS}.keyfile)
215 if [ "$ADD" = "Y" ]; then
216 echo "$1=enc:$PWD" >> $F
218 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
224 sh /opt/app/osaaf/logs/taillog
229 echo "--- Agent Container Comands ---"
230 echo " ls - Lists all files in Configuration"
231 echo " cat <file.props>> - Shows the contents (Prop files only)"
232 echo " validate - Runs a test using Configuration"
233 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
234 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
235 echo " bash - run bash in Container"
236 echo " Note: the following aliases are preset"
237 echo " cadi - CADI CmdLine tool"
238 echo " agent - Agent Java tool (see above help)"
240 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
243 echo "--- cadi Tool Comands ---"
247 echo "--- agent Tool Comands ---"
251 echo "--- aafcli Tool Comands ---"
259 # echo "--- run Sample Servlet App ---"
260 # $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
263 $JAVA_AGENT "$CMD" "$@"