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 if [ ! -z "${CONTAINER_NS}" ]; then
84 echo "aaf_locator_container_ns=${CONTAINER_NS}" >> ${SSO}
86 if [ ! -z "${AAF_ENV}" ]; then
87 echo "aaf_env=${AAF_ENV}" >> ${SSO}
89 echo aaf_locate_url=https://${AAF_FQDN}:8095 >> ${SSO}
90 echo aaf_url=https://AAF_LOCATE_URL/AAF_NS.service:${AAF_INTERFACE_VERSION} >> ${SSO}
92 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks
93 echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO}
94 echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO}
95 echo "Caller Properties Initialized"
99 # Only initialize once, automatically...
100 if [ ! -e $LOCAL/${NS}.props ]; then
101 echo "#### Create Configuration files "
102 $JAVA_AGENT config $APP_FQI \
103 aaf_url=https://AAF_LOCATE_URL/AAF_NS.locate:${AAF_INTERFACE_VERSION} \
108 echo "#### Certificate Authorization Artifact"
110 $JAVA_AGENT read ${APP_FQI} ${APP_FQDN} \
111 cadi_prop_files=${SSO} \
112 cadi_etc_dir=$LOCAL > $TMP
115 if [ -n "$(grep 'Namespace:' $TMP)" ]; then
116 echo "#### Place Certificates (by deployer)"
117 $JAVA_AGENT place ${APP_FQI} ${APP_FQDN} \
118 cadi_prop_files=${SSO} \
121 echo "#### Validate Configuration and Certificate with live call"
122 $JAVA_AGENT_SELF validate
123 echo "Obtained Certificates"
126 echo "#### Certificate Authorization Artifact must be valid to continue"
133 if [ -z "$CMD" ]; then
134 if [ -n "$INITIALIZED" ]; then
135 echo "Initialization complete"
145 find /opt/app/osaaf -depth
148 if [ "$1" = "" ]; then
149 echo "usage: cat <file... ONLY files ending in .props>"
151 if [[ $1 == *.props ]]; then
153 echo "## CONTENTS OF $3"
157 echo "### ERROR ####"
158 echo " \"cat\" may only be used with files ending with \".props\""
163 echo "## Show Passwords"
164 $JAVA_AGENT showpass ${APP_FQI} ${APP_FQDN}
167 echo "## Check Certificate"
168 $JAVA_AGENT check ${APP_FQI} ${APP_FQDN}
171 echo "## validate requested"
172 $JAVA_AGENT_SELF validate
175 echo "## Renew Certificate"
176 $JAVA_AGENT place ${APP_FQI} ${APP_FQDN}
185 FILES=$(grep -l "$1" ./*.props)
186 if [ -z "$FILES" ]; then
195 if [ "$ADD" = "Y" ]; then
196 echo "Changing $1 to $F"
199 echo "Changing $1 in $F"
200 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
208 FILES=$(grep -l "$1" ./*.props)
209 if [ "$FILES" = "" ]; then
210 FILES=$LOCAL/${NS}.cred.props
214 echo "Changing $1 in $F"
215 if [ "$2" = "" ]; then
216 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
218 if [ "$ORIG_PW" = "" ]; then
225 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/${NS}.keyfile)
226 if [ "$ADD" = "Y" ]; then
227 echo "$1=enc:$PWD" >> $F
229 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
235 sh /opt/app/osaaf/logs/taillog
237 testConnectivity|testconnectivity)
238 echo "--- Test Connectivity ---"
239 $JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar org.onap.aaf.cadi.aaf.TestConnectivity $LOCAL/org.osaaf.aaf.props
244 echo "--- Agent Container Comands ---"
245 echo " ls - Lists all files in Configuration"
246 echo " cat <file.props>> - Shows the contents (Prop files only)"
247 echo " validate - Runs a test using Configuration"
248 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
249 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
250 echo " bash - run bash in Container"
251 echo " Note: the following aliases are preset"
252 echo " cadi - CADI CmdLine tool"
253 echo " agent - Agent Java tool (see above help)"
255 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
258 echo "--- cadi Tool Comands ---"
262 echo "--- agent Tool Comands ---"
266 echo "--- aafcli Tool Comands ---"
274 # echo "--- run Sample Servlet App ---"
275 # $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
278 $JAVA_AGENT "$CMD" "$@"