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
52 rsync -avzh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
56 # Setup Bash, first time only
57 if [ ! -e "$HOME/.bash_aliases" ] || [ -z "$(grep agent $HOME/.bash_aliases)" ]; then
58 echo "alias cadi='$JAVA_CADI \$*'" >>$HOME/.bash_aliases
59 echo "alias agent='$OSAAF/bin/agent.sh EMPTY \$*'" >>$HOME/.bash_aliases
60 echo "alias aafcli='$JAVA_AAFCLI \$*'" >>$HOME/.bash_aliases
61 chmod a+x $OSAAF/bin/agent.sh
65 # Setup SSO info for Deploy ID
66 function sso_encrypt() {
67 $JAVA_CADI digest ${1} $DOT_AAF/keyfile
71 # Create Deployer Info, located at /root/.aaf
72 if [ ! -e "$DOT_AAF/keyfile" ]; then
74 $JAVA_CADI keygen $DOT_AAF/keyfile
75 chmod 400 $DOT_AAF/keyfile
76 echo cadi_latitude=${LATITUDE} > ${SSO}
77 echo cadi_longitude=${LONGITUDE} >> ${SSO}
78 echo aaf_id=${DEPLOY_FQI} >> ${SSO}
79 if [ ! "${DEPLOY_PASSWORD}" = "" ]; then
80 echo aaf_password=enc:$(sso_encrypt ${DEPLOY_PASSWORD}) >> ${SSO}
82 echo aaf_locate_url=https://${AAF_FQDN}:8095 >> ${SSO}
83 echo aaf_url=https://AAF_LOCATE_URL/AAF_NS.service:${AAF_INTERFACE_VERSION} >> ${SSO}
85 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks
86 echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO}
87 echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO}
88 echo "Caller Properties Initialized"
92 # Only initialize once, automatically...
93 if [ ! -e $LOCAL/${NS}.props ]; then
94 echo "#### Create Configuration files "
95 $JAVA_AGENT config $APP_FQI \
96 aaf_url=https://AAF_LOCATE_URL/AAF_NS.locate:${AAF_INTERFACE_VERSION} \
101 echo "#### Certificate Authorization Artifact"
103 $JAVA_AGENT read ${APP_FQI} ${APP_FQDN} \
104 cadi_prop_files=${SSO} \
105 cadi_etc_dir=$LOCAL > $TMP
108 if [ -n "$(grep 'Namespace:' $TMP)" ]; then
109 echo "#### Place Certificates (by deployer)"
110 $JAVA_AGENT place ${APP_FQI} ${APP_FQDN} \
111 cadi_prop_files=${SSO} \
114 echo "#### Validate Configuration and Certificate with live call"
115 $JAVA_AGENT_SELF validate
116 echo "Obtained Certificates"
119 echo "#### Certificate Authorization Artifact must be valid to continue"
126 if [ -z "$CMD" ]; then
127 if [ -n "$INITIALIZED" ]; then
128 echo "Initialization complete"
138 find /opt/app/osaaf -depth
141 if [ "$1" = "" ]; then
142 echo "usage: cat <file... ONLY files ending in .props>"
144 if [[ $1 == *.props ]]; then
146 echo "## CONTENTS OF $3"
150 echo "### ERROR ####"
151 echo " \"cat\" may only be used with files ending with \".props\""
156 for D in bin logs; do
157 rsync -uh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
161 echo "## Show Passwords"
162 $JAVA_AGENT showpass ${APP_FQI} ${APP_FQDN}
165 $JAVA_AGENT check ${APP_FQI} ${APP_FQDN}
168 echo "## validate requested"
169 $JAVA_AGENT_SELF validate
178 FILES=$(grep -l "$1" ./*.props)
179 if [ -z "$FILES" ]; then
188 if [ "$ADD" = "Y" ]; then
189 echo "Changing $1 to $F"
192 echo "Changing $1 in $F"
193 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
201 FILES=$(grep -l "$1" ./*.props)
202 if [ "$FILES" = "" ]; then
203 FILES=$LOCAL/${NS}.cred.props
207 echo "Changing $1 in $F"
208 if [ "$2" = "" ]; then
209 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
211 if [ "$ORIG_PW" = "" ]; then
218 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/${NS}.keyfile)
219 if [ "$ADD" = "Y" ]; then
220 echo "$1=enc:$PWD" >> $F
222 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
228 sh /opt/app/osaaf/logs/taillog
233 echo "--- Agent Container Comands ---"
234 echo " ls - Lists all files in Configuration"
235 echo " cat <file.props>> - Shows the contents (Prop files only)"
236 echo " validate - Runs a test using Configuration"
237 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
238 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
239 echo " bash - run bash in Container"
240 echo " Note: the following aliases are preset"
241 echo " cadi - CADI CmdLine tool"
242 echo " agent - Agent Java tool (see above help)"
244 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
247 echo "--- cadi Tool Comands ---"
251 echo "--- agent Tool Comands ---"
255 echo "--- aafcli Tool Comands ---"
263 # echo "--- run Sample Servlet App ---"
264 # $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
267 $JAVA_AGENT "$CMD" "$@"