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 CLPATH="$CONFIG_BIN/aaf-auth-cmd-*-full.jar"
51 JAVA_CADI="$JAVA -cp $CLPATH org.onap.aaf.cadi.CmdLine"
52 JAVA_AGENT="$JAVA -cp $CLPATH -Dcadi_prop_files=$SSO org.onap.aaf.cadi.configure.Agent"
53 JAVA_AGENT_SELF="$JAVA -cp $CLPATH -Dcadi_prop_files=$LOCAL/${NS}.props org.onap.aaf.cadi.configure.Agent"
54 JAVA_AAFCLI="$JAVA -cp $CLPATH -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props org.onap.aaf.auth.cmd.AAFcli"
57 if [ ! -d $LOCAL ]; then
61 cp $CONFIG/$D/* $OSAAF/$D
65 # Setup Bash, first time only
66 if [ ! -e "$HOME/.bashrc" ] || [ -z "$(grep cadi $HOME/.bashrc)" ]; then
67 echo "alias cadi='$JAVA_CADI \$*'" >>$HOME/.bashrc
68 echo "alias agent='$CONFIG_BIN/agent.sh agent \$*'" >>$HOME/.bashrc
69 echo "alias aafcli='$JAVA_AAFCLI \$*'" >>$HOME/.bashrc
70 chmod a+x $CONFIG_BIN/agent.sh
74 # Setup SSO info for Deploy ID
75 function sso_encrypt() {
76 $JAVA_CADI digest ${1} $DOT_AAF/keyfile
80 # Create Deployer Info, located at /root/.aaf
81 if [ ! -e "$DOT_AAF/keyfile" ]; then
83 $JAVA_CADI keygen $DOT_AAF/keyfile
84 chmod 400 $DOT_AAF/keyfile
85 echo cadi_latitude=${LATITUDE} > ${SSO}
86 echo cadi_longitude=${LONGITUDE} >> ${SSO}
87 echo aaf_id=${DEPLOY_FQI} >> ${SSO}
88 if [ ! "${DEPLOY_PASSWORD}" = "" ]; then
89 echo aaf_password=enc:$(sso_encrypt ${DEPLOY_PASSWORD}) >> ${SSO}
92 if [ ! -z "${aaf_locator_container}" ]; then
93 echo "aaf_locator_container=${aaf_locator_container}" >> ${SSO}
95 if [ -z "${aaf_locator_container_ns}" ]; then
96 if [ !-z "${CONTAINER_NS}" ]; then
97 echo "aaf_locator_container_ns=${CONTAINER_NS}" >> ${SSO}
100 echo "aaf_locator_container_ns=${aaf_locator_container_ns}" >> ${SSO}
102 if [ ! -z "${AAF_ENV}" ]; then
103 echo "aaf_env=${AAF_ENV}" >> ${SSO}
105 echo aaf_locate_url=https://${AAF_FQDN}:8095 >> ${SSO}
106 echo aaf_url=https://AAF_LOCATE_URL/%CNS.%AAF_NS.service:${AAF_INTERFACE_VERSION} >> ${SSO}
108 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks
109 echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO}
110 echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO}
111 echo "Caller Properties Initialized"
115 # Only initialize once, automatically...
116 if [ ! -e $LOCAL/${NS}.props ]; then
117 if [ -e '/opt/app/aaf_config/bin' ]; then
118 cp /opt/app/aaf_config/bin/*.jar $LOCAL
119 echo "#!/bin/bash" > agent
120 echo 'case "$1" in' >> agent
121 echo ' ""|-?|--help)CMD="";FQI="";FQDN="";;' >> agent
122 echo ' validate)CMD="$1";FQI="";FQDN="${2:-'"$NS.props"'}";;' >> agent
123 echo ' *)CMD="$1";FQI="${2:-'"$APP_FQI"'}";FQDN="${3:-'"$APP_FQDN"'}";;' >> agent
125 echo 'java -cp '$(ls aaf-auth-cmd-*-full.jar)' -Dcadi_prop_files='"$NS"'.props org.onap.aaf.cadi.configure.Agent $CMD $FQI $FQDN' >> agent
127 echo "#!/bin/bash" > cadi
128 echo "java -cp $(ls aaf-auth-cmd-*-full.jar) -Dcadi_prop_files=$NS.props org.onap.aaf.cadi.CmdLine " '$*' >> cadi
129 # echo "#!/bin/bash" > aafcli
130 # echo "java -cp $(ls aaf-auth-cmd-*-full.jar) -Dcadi_prop_files=$NS.props org.onap.aaf.auth.cmd.AAFcli " '$*' >> aafcli
132 echo "#!/bin/bash" > testConnectivity
133 echo "java -cp $(ls aaf-auth-cmd-*-full.jar) org.onap.aaf.cadi.aaf.TestConnectivity $NS.props" >> testConnectivity
134 chmod ug+x agent cadi testConnectivity
136 echo "#### Create Configuration files "
137 $JAVA_AGENT config $APP_FQI \
138 aaf_url=https://AAF_LOCATE_URL/AAF_NS.locate:${AAF_INTERFACE_VERSION} \
140 # Grab all properties passed in that start with "aaf_" or "cadi_"
142 if [[ $E == aaf_* ]] || [[ $E == cadi_* ]]; then
143 if [ -z "$(grep $E $LOCAL/$NS.props)" ]; then
144 echo "${E}" >> $LOCAL/$NS.props
151 echo "#### Certificate Authorization Artifact"
153 $JAVA_AGENT read ${APP_FQI} ${APP_FQDN} \
154 cadi_prop_files=${SSO} \
155 cadi_etc_dir=$LOCAL > $TMP
158 if [ -n "$(grep 'Namespace:' $TMP)" ]; then
159 echo "#### Place Certificates (by deployer)"
160 $JAVA_AGENT place ${APP_FQI} ${APP_FQDN} \
161 cadi_prop_files=${SSO} \
164 echo "#### Validate Configuration and Certificate with live call"
165 echo "Obtained Certificates"
168 echo "#### Certificate Authorization Artifact must be valid to continue"
175 if [ -z "$CMD" ]; then
176 if [ -n "$INITIALIZED" ]; then
177 echo "Initialization complete"
187 find /opt/app/osaaf -depth
190 if [ "$1" = "" ]; then
191 echo "usage: cat <file... ONLY files ending in .props>"
193 if [[ $1 == *.props ]]; then
195 echo "## CONTENTS OF $3"
199 echo "### ERROR ####"
200 echo " \"cat\" may only be used with files ending with \".props\""
205 echo "## Show Passwords"
206 $JAVA_AGENT showpass ${APP_FQI} ${APP_FQDN}
209 echo "## Check Certificate"
210 $JAVA_AGENT check ${APP_FQI} ${APP_FQDN}
213 echo "## validate requested"
214 $JAVA_AGENT_SELF validate
217 echo "## Renew Certificate"
218 $JAVA_AGENT place ${APP_FQI} ${APP_FQDN}
227 FILES=$(grep -l "$1" ./*.props)
228 if [ -z "$FILES" ]; then
237 if [ "$ADD" = "Y" ]; then
238 echo "Changing $1 to $F"
241 echo "Changing $1 in $F"
242 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
250 FILES=$(grep -l "$1" ./*.props)
251 if [ "$FILES" = "" ]; then
252 FILES=$LOCAL/${NS}.cred.props
256 echo "Changing $1 in $F"
257 if [ "$2" = "" ]; then
258 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
260 if [ "$ORIG_PW" = "" ]; then
267 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/${NS}.keyfile)
268 if [ "$ADD" = "Y" ]; then
269 echo "$1=enc:$PWD" >> $F
271 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
277 sh /opt/app/osaaf/logs/taillog
279 testConnectivity|testconnectivity)
280 echo "--- Test Connectivity ---"
281 $JAVA -cp $CONFIG_BIN/aaf-auth-cmd-*-full.jar org.onap.aaf.cadi.aaf.TestConnectivity $LOCAL/org.osaaf.aaf.props
286 echo "--- Agent Container Comands ---"
287 echo " ls - Lists all files in Configuration"
288 echo " cat <file.props>> - Shows the contents (Prop files only)"
289 echo " validate - Runs a test using Configuration"
290 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
291 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
292 echo " bash - run bash in Container"
293 echo " Note: the following aliases are preset"
294 echo " cadi - CADI CmdLine tool"
295 echo " agent - Agent Java tool (see above help)"
297 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
300 echo "--- cadi Tool Comands ---"
304 echo "--- agent Tool Comands ---"
308 echo "--- aafcli Tool Comands ---"
316 # echo "--- run Sample Servlet App ---"
317 # $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
320 $JAVA_AGENT "$CMD" "$@"