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 # echo "Check keyfile"
109 FILE="$LOCAL/org.osaaf.aaf.p12"
110 if [ ! -e $FILE ]; then
111 if [ -e $CONFIG/cert/org.osaaf.aaf.p12 ]; then
112 cp $CONFIG/cert/org.osaaf.aaf.p12 $FILE
113 echo "Installed AAF P12"
116 echo "Bootstrap Creation of Keystore from Signer"
119 # Remove this after Casablanca
120 CADI_X509_ISSUERS="CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US:CN=intermediateCA_7, OU=OSAAF, O=ONAP, C=US"
121 bash bootstrap.sh $LOCAL/org.osaaf.aaf.signer.p12 'something easy'
122 cp aaf.bootstrap.p12 $FILE
123 if [ -n "$CADI_X509_ISSUERS" ]; then
124 CADI_X509_ISSUERS="$CADI_X509_ISSUERS:"
126 BOOT_ISSUER="$(cat aaf.bootstrap.issuer)"
127 CADI_X509_ISSUERS="$CADI_X509_ISSUERS$BOOT_ISSUER"
129 I=${BOOT_ISSUER##CN=};I=${I%%,*}
130 CM_CA_PASS="something easy"
131 CM_CA_LOCAL="org.onap.aaf.auth.cm.ca.LocalCA,$LOCAL/org.osaaf.aaf.signer.p12;aaf_intermediate_9;enc:"
132 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
133 echo "Generated ONAP Test AAF certs"
138 # Only initialize once, automatically...
139 if [ ! -e $LOCAL/org.osaaf.aaf.props ]; then
140 cp $CONFIG/local/org.osaaf.aaf* $LOCAL
141 for D in public etc logs; do
143 cp $CONFIG/$D/* $OSAAF/$D
148 if [[ "$P" == aaf_* ]] || [[ "$P" == cadi_* ]]; then
159 cadi_etc_dir=$LOCAL \
160 cadi_prop_files=$CONFIG/local/initialConfig.props:$CONFIG/local/aaf.props:${TMP}
163 # Cassandra Config stuff
164 # Default is expect a Cassandra on same Node
165 CASS_HOST=${CASS_HOST:="aaf-cass"}
166 CASS_PASS=$($JAVA_CADI digest "${CASSANDRA_PASSWORD:-cassandra}" $LOCAL/org.osaaf.aaf.keyfile)
167 CASS_NAME=${CASS_HOST/:*/}
168 sed -i.backup -e "s/\\(cassandra.clusters=\\).*/\\1${CASSANDRA_CLUSTER:=$CASS_HOST}/" \
169 -e "s/\\(cassandra.clusters.user=\\).*/\\1${CASSANDRA_USER:=cassandra}/" \
170 -e "s/\\(cassandra.clusters.password=enc:\\).*/\\1$CASS_PASS/" \
171 -e "s/\\(cassandra.clusters.port=\\).*/\\1${CASSANDRA_PORT:=9042}/" \
172 $LOCAL/org.osaaf.aaf.cassandra.props
174 if [ -n "$CM_CA_LOCAL" ]; then
175 if [ -n "$CM_CA_PASS" ]; then
176 CM_CA_LOCAL=$CM_CA_LOCAL$($JAVA_CADI digest "$CM_CA_PASS" $LOCAL/org.osaaf.aaf.keyfile)
178 # Move and copy method, rather than sed, because of slashes in CM_CA_LOCAL makes too complex
179 FILE=$LOCAL/org.osaaf.aaf.cm.ca.props
180 mv $FILE $FILE.backup
181 grep -v "cm_ca.local=" $FILE.backup > $FILE
182 echo "cm_ca.local=$CM_CA_LOCAL" >> $FILE
183 echo "cm_trust_cas=$CM_TRUST_CAS" >> $FILE
185 echo "Created AAF Initial Configurations"
192 if [ -z "$CMD" ]; then
193 if [ -n "$INITIALIZED" ]; then
194 echo "Initialization Complete"
196 echo "No Additional Initialization required"
206 if [ "$1" = "" ]; then
207 echo "usage: cat <file... ONLY files ending in .props>"
209 if [[ $1 == *.props ]]; then
211 echo "## CONTENTS OF $3"
215 echo "### ERROR ####"
216 echo " \"cat\" may only be used with files ending with \".props\""
221 echo "## validate requested"
222 $JAVA_AAFCLI perm list user aaf@aaf.osaaf.org
225 #echo Initializing ONAP configurations.
230 exec /bin/bash -c "$@"
234 FILES=$(grep -l "$1" ./*.props)
235 if [ -z "$FILES" ]; then
237 FILES=org.osaaf.aaf.props
244 if [ "$ADD" = "Y" ]; then
245 echo "Changing $1 for $F"
248 echo "Changing $1 in $F"
249 sed -i.backup -e "s/\\(${1}=\\).*/\\1${2}/" $F
257 FILES=$(grep -l "$1" ./*.props)
258 if [ "$FILES" = "" ]; then
259 FILES=$LOCAL/org.osaaf.aaf.cred.props
263 echo "Changing $1 in $F"
264 if [ "$2" = "" ]; then
265 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
267 if [ "$ORIG_PW" = "" ]; then
274 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/org.osaaf.aaf.keyfile)
275 if [ "$ADD" = "Y" ]; then
276 echo "$1=enc:$PWD" >> $F
278 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
284 sh $OSAAF/logs/taillog
287 bash $CONFIG/bin/pod_wait.sh wait $1
292 echo "--- Agent Container Comands ---"
293 echo " ls - Lists all files in Configuration"
294 echo " cat <file.props>> - Shows the contents (Prop files only)"
295 echo " validate - Runs a test using Configuration"
296 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
297 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
298 echo " bash - run bash in Container"
299 echo " Note: the following aliases are preset"
300 echo " cadi - CADI CmdLine tool"
301 echo " agent - Agent Java tool (see above help)"
303 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
306 echo "--- cadi Tool Comands ---"
310 echo "--- agent Tool Comands ---"
314 echo "--- aafcli Tool Comands ---"
321 $JAVA_AGENT "$CMD" "$@" cadi_prop_files=$LOCAL/org.osaaf.aaf.props