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_deployed_version=${aaf_deployed_version:-"${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"}
42 JAVA=${JAVA_HOME}/bin/java
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
85 if [ ! -e "${LOCAL}/VERSION" ] || [ "${VERSION}" != "$(cat ${LOCAL}/VERSION)" ]; then
86 echo "Clean up directory ${LOCAL}"
87 rm -Rf ${LOCAL}/org.osaaf.aaf.*props ${LOCAL}/org.osaaf.aaf.p12
90 echo "${VERSION}" > $LOCAL/VERSION
92 # Load up Cert/X509 Artifacts
93 # echo "Check Signer Keyfile"
94 FILE="$LOCAL/org.osaaf.aaf.signer.p12"
95 if [ ! -e $FILE ]; then
98 if [ -e $CONFIG/cert/org.osaaf.aaf.signer.p12 ]; then
99 cp $CONFIG/cert/org.osaaf.aaf.signer.p12 $FILE
100 echo "Installed Signer P12"
104 base64 -d $CONFIG/cert/demoONAPsigner.p12.b64 > $FILE
105 base64 -d $CONFIG/cert/truststoreONAP.p12.b64 > $PUBLIC/truststoreONAP.p12
106 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $PUBLIC/truststoreONAPall.jks
107 ln -s $PUBLIC/truststoreONAPall.jks $LOCAL
108 cp $CONFIG/cert/AAF_RootCA.cer $PUBLIC
109 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
110 echo "Setup ONAP Test CAs and Signers"
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 # Redo all of this after Dublin
126 export cadi_x509_issuers="CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US:CN=intermediateCA_7, OU=OSAAF, O=ONAP, C=US"
127 export signer_subj="/CN=intermediateCA_9/OU=OSAAF/O=ONAP/C=US"
128 bash bootstrap.sh $LOCAL/org.osaaf.aaf.signer.p12 'something easy'
129 cp aaf.bootstrap.p12 $FILE
130 if [ -n "$CADI_X509_ISSUERS" ]; then
131 CADI_X509_ISSUERS="$CADI_X509_ISSUERS:"
133 BOOT_ISSUER="$(cat aaf.bootstrap.issuer)"
134 CADI_X509_ISSUERS="$CADI_X509_ISSUERS$BOOT_ISSUER"
136 I=${BOOT_ISSUER##CN=};I=${I%%,*}
137 CM_CA_PASS="something easy"
138 CM_CA_LOCAL="org.onap.aaf.auth.cm.ca.LocalCA,$LOCAL/org.osaaf.aaf.signer.p12;aaf_intermediate_9;enc:"
139 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
140 echo "Generated ONAP Test AAF certs"
145 # Only initialize once, automatically...
146 if [ ! -e $LOCAL/org.osaaf.aaf.props ]; then
147 cp $CONFIG/local/org.osaaf.aaf* $LOCAL
148 for D in public etc logs; do
150 cp $CONFIG/$D/* $OSAAF/$D
155 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}
170 echo "cm_always_ignore_ips=${cm_always_ignore_ips:=false}" >> $LOCAL/org.osaaf.aaf.props;
172 # Cassandra Config stuff
173 # Default is expect a Cassandra on same Node
174 CASS_HOST=${CASS_HOST:="aaf-cass"}
175 CASS_PASS=$($JAVA_CADI digest "${CASSANDRA_PASSWORD:-cassandra}" $LOCAL/org.osaaf.aaf.keyfile)
176 CASS_NAME=${CASS_HOST/:*/}
177 sed -i.backup -e "s/\\(cassandra.clusters=\\).*/\\1${CASSANDRA_CLUSTER:=$CASS_HOST}/" \
178 -e "s/\\(cassandra.clusters.user=\\).*/\\1${CASSANDRA_USER:=cassandra}/" \
179 -e "s/\\(cassandra.clusters.password=enc:\\).*/\\1$CASS_PASS/" \
180 -e "s/\\(cassandra.clusters.port=\\).*/\\1${CASSANDRA_PORT:=9042}/" \
181 $LOCAL/org.osaaf.aaf.cassandra.props
183 if [ -n "$CM_CA_LOCAL" ]; then
184 if [ -n "$CM_CA_PASS" ]; then
185 CM_CA_LOCAL=$CM_CA_LOCAL$($JAVA_CADI digest "$CM_CA_PASS" $LOCAL/org.osaaf.aaf.keyfile)
187 # Move and copy method, rather than sed, because of slashes in CM_CA_LOCAL makes too complex
188 FILE=$LOCAL/org.osaaf.aaf.cm.ca.props
189 mv $FILE $FILE.backup
190 grep -v "cm_ca.local=" $FILE.backup > $FILE
191 echo "cm_ca.local=$CM_CA_LOCAL" >> $FILE
192 echo "cm_trust_cas=$CM_TRUST_CAS" >> $FILE
194 echo "Created AAF Initial Configurations"
201 if [ -z "$CMD" ]; then
202 if [ -n "$INITIALIZED" ]; then
203 echo "Initialization Complete"
205 echo "No Additional Initialization required"
215 if [ "$1" = "" ]; then
216 echo "usage: cat <file... ONLY files ending in .props>"
218 if [[ $1 == *.props ]]; then
220 echo "## CONTENTS OF $3"
224 echo "### ERROR ####"
225 echo " \"cat\" may only be used with files ending with \".props\""
230 echo "## validate requested"
231 $JAVA_AAFCLI perm list user aaf@aaf.osaaf.org
234 #echo Initializing ONAP configurations.
239 exec /bin/bash -c "$@"
243 FILES=$(grep -l "$1" ./*.props)
244 if [ -z "$FILES" ]; then
246 FILES=org.osaaf.aaf.props
253 if [ "$ADD" = "Y" ]; then
254 echo "Changing $1 for $F"
257 echo "Changing $1 in $F"
258 sed -i.backup -e "s/\\(${1}=\\).*/\\1${2}/" $F
266 FILES=$(grep -l "$1" ./*.props)
267 if [ "$FILES" = "" ]; then
268 FILES=$LOCAL/org.osaaf.aaf.cred.props
272 echo "Changing $1 in $F"
273 if [ "$2" = "" ]; then
274 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
276 if [ "$ORIG_PW" = "" ]; then
283 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/org.osaaf.aaf.keyfile)
284 if [ "$ADD" = "Y" ]; then
285 echo "$1=enc:$PWD" >> $F
287 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
293 sh $OSAAF/logs/taillog
296 bash $CONFIG/bin/pod_wait.sh wait $1
301 echo "--- Agent Container Comands ---"
302 echo " ls - Lists all files in Configuration"
303 echo " cat <file.props>> - Shows the contents (Prop files only)"
304 echo " validate - Runs a test using Configuration"
305 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
306 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
307 echo " bash - run bash in Container"
308 echo " Note: the following aliases are preset"
309 echo " cadi - CADI CmdLine tool"
310 echo " agent - Agent Java tool (see above help)"
312 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
315 echo "--- cadi Tool Comands ---"
319 echo "--- agent Tool Comands ---"
323 echo "--- aafcli Tool Comands ---"
330 $JAVA_AGENT "$CMD" "$@" cadi_prop_files=$LOCAL/org.osaaf.aaf.props