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 aaf_config 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 echo "# Properties passed in"
27 if [[ "$P" == cadi* ]] || [[ "$P" == aaf* ]] || [[ "$P" == HOSTNAME* ]]; then
34 # Set from CAP Based PROPS, if necessary
35 aaf_env=${aaf_env:-"${AAF_ENV}"}
36 aaf_release=${aaf_release:-"${VERSION}"}
37 cadi_latitude=${cadi_latitude:-"${LATITUDE}"}
38 cadi_longitude=${cadi_longitude:-"${LONGITUDE}"}
39 cadi_x509_issuers=${cadi_x509_issuers:-"${CADI_X509_ISSUERS}"}
40 aaf_locate_url=${aaf_locate_url:-"https://${HOSTNAME}:8095"}
48 CONFIG=/opt/app/aaf_config
50 JAVA_CADI="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar org.onap.aaf.cadi.CmdLine"
51 JAVA_AGENT="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props org.onap.aaf.cadi.configure.Agent"
52 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"
53 JAVA_AAFBATCH="$JAVA -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.batch.props -jar $CONFIG/bin/aaf-auth-batch-*-full.jar"
55 # If doesn't exist... still create
58 # If not created by separate PV, create
59 mkdir -p /opt/app/aaf/status
61 # Temp use for clarity of code
64 # Setup Bash, first time only
65 if [ ! -e "$HOME/.bashrc" ] || [ -z "$(grep cadi $HOME/.bashrc)" ]; then
66 echo "alias cadi='$JAVA_CADI \$*'" >>$HOME/.bashrc
67 echo "alias agent='$CONFIG/bin/agent.sh \$*'" >>$HOME/.bashrc
68 echo "alias aafcli='$JAVA_AAFCLI \$*'" >>$HOME/.bashrc
69 echo "alias batch='$JAVA_AAFBATCH \$*'" >>$HOME/.bashrc
70 chmod a+x $CONFIG/bin/agent.sh
74 # Only load Identities once
75 # echo "Check Identities"
76 FILE="$DATA/identities.dat"
77 if [ ! -e $FILE ]; then
79 cp $CONFIG/data/sample.identities.dat $FILE
84 # Load up Cert/X509 Artifacts
85 # echo "Check Signer Keyfile"
86 FILE="$LOCAL/org.osaaf.aaf.signer.p12"
87 if [ ! -e $FILE ]; then
90 if [ -e $CONFIG/cert/org.osaaf.aaf.signer.p12 ]; then
91 cp $CONFIG/cert/org.osaaf.aaf.signer.p12 $FILE
92 echo "Installed Signer P12"
96 base64 -d $CONFIG/cert/demoONAPsigner.p12.b64 > $FILE
97 base64 -d $CONFIG/cert/truststoreONAP.p12.b64 > $PUBLIC/truststoreONAP.p12
98 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $PUBLIC/truststoreONAPall.jks
99 ln -s $PUBLIC/truststoreONAPall.jks $LOCAL
100 cp $CONFIG/cert/AAF_RootCA.cer $PUBLIC
101 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
102 echo "cadi_keystore_password=something easy" >> $CONFIG/local/aaf.props
103 echo "Setup ONAP Test CAs and Signers"
108 # Should we clean up?
109 if [ "${VERSION}" != "$(cat ${LOCAL}/VERSION)" ]; then
110 echo "Clean up directory ${LOCAL}"
113 echo "${VERSION}" > $LOCAL/VERSION
115 FILE="$LOCAL/org.osaaf.aaf.p12"
116 if [ ! -e $FILE ]; then
117 if [ -e $CONFIG/cert/org.osaaf.aaf.p12 ]; then
118 cp $CONFIG/cert/org.osaaf.aaf.p12 $FILE
119 echo "Installed AAF P12"
122 echo "Bootstrap Creation of Keystore from Signer"
125 # Remove this after Casablanca
126 CADI_X509_ISSUERS="CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US:CN=intermediateCA_7, OU=OSAAF, O=ONAP, C=US"
127 bash bootstrap.sh $LOCAL/org.osaaf.aaf.signer.p12 'something easy'
128 cp aaf.bootstrap.p12 $FILE
129 if [ -n "$CADI_X509_ISSUERS" ]; then
130 CADI_X509_ISSUERS="$CADI_X509_ISSUERS:"
132 BOOT_ISSUER="$(cat aaf.bootstrap.issuer)"
133 CADI_X509_ISSUERS="$CADI_X509_ISSUERS$BOOT_ISSUER"
135 I=${BOOT_ISSUER##CN=};I=${I%%,*}
136 CM_CA_PASS="something easy"
137 CM_CA_LOCAL="org.onap.aaf.auth.cm.ca.LocalCA,$LOCAL/org.osaaf.aaf.signer.p12;aaf_intermediate_9;enc:"
138 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
139 echo "Generated ONAP Test AAF certs"
144 # Only initialize once, automatically...
145 if [ ! -e $LOCAL/org.osaaf.aaf.props ]; then
146 cp $CONFIG/local/org.osaaf.aaf* $LOCAL
147 for D in public etc logs; do
149 cp $CONFIG/$D/* $OSAAF/$D
154 if [[ "$P" == aaf_* ]] || [[ "$P" == cadi_* ]]; then
165 cadi_etc_dir=$LOCAL \
166 cadi_latitude=${cadi_latitude} \
167 cadi_longitude=${cadi_longitude} \
168 cadi_prop_files=$CONFIG/local/initialConfig.props:$CONFIG/local/aaf.props:${TMP}
171 # Cassandra Config stuff
172 # Default is expect a Cassandra on same Node
173 CASS_HOST=${CASS_HOST:="aaf-cass"}
174 CASS_PASS=$($JAVA_CADI digest "${CASSANDRA_PASSWORD:-cassandra}" $LOCAL/org.osaaf.aaf.keyfile)
175 CASS_NAME=${CASS_HOST/:*/}
176 sed -i.backup -e "s/\\(cassandra.clusters=\\).*/\\1${CASSANDRA_CLUSTER:=$CASS_HOST}/" \
177 -e "s/\\(cassandra.clusters.user=\\).*/\\1${CASSANDRA_USER:=cassandra}/" \
178 -e "s/\\(cassandra.clusters.password=enc:\\).*/\\1$CASS_PASS/" \
179 -e "s/\\(cassandra.clusters.port=\\).*/\\1${CASSANDRA_PORT:=9042}/" \
180 $LOCAL/org.osaaf.aaf.cassandra.props
182 if [ -n "$CM_CA_LOCAL" ]; then
183 if [ -n "$CM_CA_PASS" ]; then
184 CM_CA_LOCAL=$CM_CA_LOCAL$($JAVA_CADI digest "$CM_CA_PASS" $LOCAL/org.osaaf.aaf.keyfile)
186 # Move and copy method, rather than sed, because of slashes in CM_CA_LOCAL makes too complex
187 FILE=$LOCAL/org.osaaf.aaf.cm.ca.props
188 mv $FILE $FILE.backup
189 grep -v "cm_ca.local=" $FILE.backup > $FILE
190 echo "cm_ca.local=$CM_CA_LOCAL" >> $FILE
191 echo "cm_trust_cas=$CM_TRUST_CAS" >> $FILE
193 echo "Created AAF Initial Configurations"
200 if [ -z "$CMD" ]; then
201 if [ -n "$INITIALIZED" ]; then
202 echo "Initialization Complete"
204 echo "No Additional Initialization required"
214 if [ "$1" = "" ]; then
215 echo "usage: cat <file... ONLY files ending in .props>"
217 if [[ $1 == *.props ]]; then
219 echo "## CONTENTS OF $3"
223 echo "### ERROR ####"
224 echo " \"cat\" may only be used with files ending with \".props\""
229 echo "## validate requested"
230 $JAVA_AAFCLI perm list user aaf@aaf.osaaf.org
233 #echo Initializing ONAP configurations.
238 exec /bin/bash -c "$@"
242 FILES=$(grep -l "$1" ./*.props)
243 if [ -z "$FILES" ]; then
245 FILES=org.osaaf.aaf.props
252 if [ "$ADD" = "Y" ]; then
253 echo "Changing $1 for $F"
256 echo "Changing $1 in $F"
257 sed -i.backup -e "s/\\(${1}=\\).*/\\1${2}/" $F
265 FILES=$(grep -l "$1" ./*.props)
266 if [ "$FILES" = "" ]; then
267 FILES=$LOCAL/org.osaaf.aaf.cred.props
271 echo "Changing $1 in $F"
272 if [ "$2" = "" ]; then
273 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
275 if [ "$ORIG_PW" = "" ]; then
282 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/org.osaaf.aaf.keyfile)
283 if [ "$ADD" = "Y" ]; then
284 echo "$1=enc:$PWD" >> $F
286 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
292 sh $OSAAF/logs/taillog
295 bash $CONFIG/bin/pod_wait.sh wait $1
300 echo "--- Agent Container Comands ---"
301 echo " ls - Lists all files in Configuration"
302 echo " cat <file.props>> - Shows the contents (Prop files only)"
303 echo " validate - Runs a test using Configuration"
304 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
305 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
306 echo " bash - run bash in Container"
307 echo " Note: the following aliases are preset"
308 echo " cadi - CADI CmdLine tool"
309 echo " agent - Agent Java tool (see above help)"
311 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
314 echo "--- cadi Tool Comands ---"
318 echo "--- agent Tool Comands ---"
322 echo "--- aafcli Tool Comands ---"
329 $JAVA_AGENT "$CMD" "$@" cadi_prop_files=$LOCAL/org.osaaf.aaf.props