Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Instrumental | 7a1817b | 2018-11-05 11:11:15 -0600 | [diff] [blame] | 2 | ######### |
| 3 | # ============LICENSE_START==================================================== |
| 4 | # org.onap.aaf |
| 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 |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 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==================================================== |
| 20 | # |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 21 | # This script is run when starting client Container. |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 22 | # It needs to cover the cases where the initial data doesn't exist, and when it has already been configured (don't overwrite) |
| 23 | # |
| 24 | JAVA=/usr/bin/java |
| 25 | AAF_INTERFACE_VERSION=2.1 |
| 26 | |
| 27 | # Extract Name, Domain and NS from FQI |
| 28 | FQIA=($(echo ${APP_FQI} | tr '@' '\n')) |
| 29 | FQI_SHORT=${FQIA[0]} |
| 30 | FQI_DOMAIN=${FQIA[1]} |
| 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]}'.' |
| 35 | done |
| 36 | NS=${NS}${FQIA_E[0]} |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 37 | CONFIG="/opt/app/aaf_config" |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 38 | OSAAF="/opt/app/osaaf" |
| 39 | LOCAL="$OSAAF/local" |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 40 | DOT_AAF="$HOME/.aaf" |
| 41 | SSO="$DOT_AAF/sso.props" |
| 42 | |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 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" |
| 47 | |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 48 | # Check for local dir |
| 49 | if [ ! -d $LOCAL ]; then |
| 50 | mkdir -p $LOCAL |
| 51 | for D in bin logs; do |
| 52 | rsync -avzh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D |
| 53 | done |
| 54 | fi |
| 55 | |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 56 | # Setup Bash, first time only |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 57 | if [ ! -e "$HOME/.bash_aliases" ] || [ -z "$(grep agent $HOME/.bash_aliases)" ]; then |
| 58 | echo "alias cadi='$JAVA_CADI \$*'" >>$HOME/.bash_aliases |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 59 | echo "alias agent='$OSAAF/bin/agent.sh EMPTY \$*'" >>$HOME/.bash_aliases |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 60 | echo "alias aafcli='$JAVA_AAFCLI \$*'" >>$HOME/.bash_aliases |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 61 | chmod a+x $OSAAF/bin/agent.sh |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 62 | . $HOME/.bash_aliases |
| 63 | fi |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 64 | |
| 65 | # Setup SSO info for Deploy ID |
| 66 | function sso_encrypt() { |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 67 | $JAVA_CADI digest ${1} $DOT_AAF/keyfile |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 68 | } |
| 69 | |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 70 | |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 71 | # Create Deployer Info, located at /root/.aaf |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 72 | if [ ! -e "$DOT_AAF/keyfile" ]; then |
| 73 | mkdir -p $DOT_AAF |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 74 | $JAVA_CADI keygen $DOT_AAF/keyfile |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 75 | chmod 400 $DOT_AAF/keyfile |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 76 | echo cadi_latitude=${LATITUDE} > ${SSO} |
| 77 | echo cadi_longitude=${LONGITUDE} >> ${SSO} |
| 78 | echo aaf_id=${DEPLOY_FQI} >> ${SSO} |
| 79 | if [ ! "${DEPLOY_PASSWORD}" = "" ]; then |
| 80 | echo aaf_password=enc:$(sso_encrypt ${DEPLOY_PASSWORD}) >> ${SSO} |
| 81 | fi |
| 82 | echo aaf_locate_url=https://${AAF_FQDN}:8095 >> ${SSO} |
| 83 | echo aaf_url=https://AAF_LOCATE_URL/AAF_NS.service:${AAF_INTERFACE_VERSION} >> ${SSO} |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 84 | |
| 85 | base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks |
| 86 | echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO} |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 87 | echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO} |
Instrumental | 284ad0a | 2018-10-24 07:01:09 -0500 | [diff] [blame] | 88 | echo "Caller Properties Initialized" |
| 89 | INITIALIZED="true" |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 90 | fi |
| 91 | |
| 92 | # Only initialize once, automatically... |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 93 | if [ ! -e $LOCAL/${NS}.props ]; then |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 94 | echo "#### Create Configuration files " |
| 95 | $JAVA_AGENT config $APP_FQI \ |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 96 | aaf_url=https://AAF_LOCATE_URL/AAF_NS.locate:${AAF_INTERFACE_VERSION} \ |
| 97 | cadi_etc_dir=$LOCAL |
| 98 | cat $LOCAL/$NS.props |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 99 | |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 100 | echo |
| 101 | echo "#### Certificate Authorization Artifact" |
| 102 | TMP=$(mktemp) |
| 103 | $JAVA_AGENT read ${APP_FQI} ${APP_FQDN} \ |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 104 | cadi_prop_files=${SSO} \ |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 105 | cadi_etc_dir=$LOCAL > $TMP |
| 106 | cat $TMP |
| 107 | echo |
| 108 | if [ -n "$(grep 'Namespace:' $TMP)" ]; then |
| 109 | echo "#### Place Certificates (by deployer)" |
| 110 | $JAVA_AGENT place ${APP_FQI} ${APP_FQDN} \ |
| 111 | cadi_prop_files=${SSO} \ |
| 112 | cadi_etc_dir=$LOCAL |
| 113 | |
| 114 | echo "#### Validate Configuration and Certificate with live call" |
| 115 | $JAVA_AGENT_SELF validate |
Instrumental | 284ad0a | 2018-10-24 07:01:09 -0500 | [diff] [blame] | 116 | echo "Obtained Certificates" |
| 117 | INITIALIZED="true" |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 118 | else |
| 119 | echo "#### Certificate Authorization Artifact must be valid to continue" |
| 120 | fi |
| 121 | rm $TMP |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 122 | fi |
| 123 | |
| 124 | # Now run a command |
| 125 | CMD=$2 |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 126 | if [ -z "$CMD" ]; then |
Instrumental | 284ad0a | 2018-10-24 07:01:09 -0500 | [diff] [blame] | 127 | if [ -n "$INITIALIZED" ]; then |
| 128 | echo "Initialization complete" |
| 129 | else |
| 130 | $JAVA_AGENT |
| 131 | fi |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 132 | else |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 133 | shift |
| 134 | shift |
| 135 | case "$CMD" in |
| 136 | ls) |
| 137 | echo ls requested |
| 138 | find /opt/app/osaaf -depth |
| 139 | ;; |
| 140 | cat) |
| 141 | if [ "$1" = "" ]; then |
| 142 | echo "usage: cat <file... ONLY files ending in .props>" |
| 143 | else |
| 144 | if [[ $1 == *.props ]]; then |
| 145 | echo |
| 146 | echo "## CONTENTS OF $3" |
| 147 | echo |
| 148 | cat "$1" |
| 149 | else |
| 150 | echo "### ERROR ####" |
| 151 | echo " \"cat\" may only be used with files ending with \".props\"" |
| 152 | fi |
| 153 | fi |
| 154 | ;; |
| 155 | update) |
| 156 | for D in bin logs; do |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 157 | rsync -uh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 158 | done |
| 159 | ;; |
Instrumental | 87da9fe | 2018-07-19 16:44:02 -0500 | [diff] [blame] | 160 | showpass) |
| 161 | echo "## Show Passwords" |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 162 | $JAVA_AGENT showpass ${APP_FQI} ${APP_FQDN} |
Instrumental | 87da9fe | 2018-07-19 16:44:02 -0500 | [diff] [blame] | 163 | ;; |
| 164 | check) |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 165 | $JAVA_AGENT check ${APP_FQI} ${APP_FQDN} |
Instrumental | 87da9fe | 2018-07-19 16:44:02 -0500 | [diff] [blame] | 166 | ;; |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 167 | validate) |
| 168 | echo "## validate requested" |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 169 | $JAVA_AGENT_SELF validate |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 170 | ;; |
| 171 | bash) |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 172 | shift |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 173 | cd $LOCAL || exit |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 174 | /bin/bash "$@" |
| 175 | ;; |
| 176 | setProp) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 177 | cd $LOCAL || exit |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 178 | FILES=$(grep -l "$1" ./*.props) |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 179 | if [ -z "$FILES" ]; then |
| 180 | if [ -z "$3" ]; then |
| 181 | FILES=${NS}.props |
| 182 | else |
| 183 | FILES="$3" |
| 184 | fi |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 185 | ADD=Y |
| 186 | fi |
| 187 | for F in $FILES; do |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 188 | if [ "$ADD" = "Y" ]; then |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 189 | echo "Changing $1 to $F" |
| 190 | echo "$1=$2" >> $F |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 191 | else |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 192 | echo "Changing $1 in $F" |
Instrumental | 6095e29 | 2018-09-06 13:27:15 -0500 | [diff] [blame] | 193 | sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 194 | fi |
| 195 | cat $F |
| 196 | done |
| 197 | ;; |
| 198 | encrypt) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 199 | cd $LOCAL || exit |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 200 | echo $1 |
| 201 | FILES=$(grep -l "$1" ./*.props) |
| 202 | if [ "$FILES" = "" ]; then |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 203 | FILES=$LOCAL/${NS}.cred.props |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 204 | ADD=Y |
| 205 | fi |
| 206 | for F in $FILES; do |
| 207 | echo "Changing $1 in $F" |
| 208 | if [ "$2" = "" ]; then |
| 209 | read -r -p "Password (leave blank to cancel): " -s ORIG_PW |
| 210 | echo " " |
| 211 | if [ "$ORIG_PW" = "" ]; then |
| 212 | echo canceling... |
| 213 | break |
| 214 | fi |
| 215 | else |
| 216 | ORIG_PW="$2" |
| 217 | fi |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 218 | PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/${NS}.keyfile) |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 219 | if [ "$ADD" = "Y" ]; then |
| 220 | echo "$1=enc:$PWD" >> $F |
| 221 | else |
| 222 | sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F |
| 223 | fi |
| 224 | cat $F |
| 225 | done |
| 226 | ;; |
| 227 | taillog) |
| 228 | sh /opt/app/osaaf/logs/taillog |
| 229 | ;; |
| 230 | --help | -?) |
| 231 | case "$1" in |
| 232 | "") |
| 233 | echo "--- Agent Container Comands ---" |
| 234 | echo " ls - Lists all files in Configuration" |
| 235 | echo " cat <file.props>> - Shows the contents (Prop files only)" |
| 236 | echo " validate - Runs a test using Configuration" |
| 237 | echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)" |
| 238 | echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)" |
| 239 | echo " bash - run bash in Container" |
| 240 | echo " Note: the following aliases are preset" |
| 241 | echo " cadi - CADI CmdLine tool" |
| 242 | echo " agent - Agent Java tool (see above help)" |
| 243 | echo "" |
| 244 | echo " --help|-? [cadi|agent] - This help, cadi help or agent help" |
| 245 | ;; |
| 246 | cadi) |
| 247 | echo "--- cadi Tool Comands ---" |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 248 | $JAVA_CADI |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 249 | ;; |
| 250 | agent) |
| 251 | echo "--- agent Tool Comands ---" |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 252 | $JAVA_AGENT |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 253 | ;; |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 254 | aafcli) |
| 255 | echo "--- aafcli Tool Comands ---" |
| 256 | $JAVA_AAFCLI |
| 257 | ;; |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 258 | esac |
| 259 | echo "" |
| 260 | ;; |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 261 | ### Possible Dublin |
| 262 | # sample) |
| 263 | # echo "--- run Sample Servlet App ---" |
| 264 | # $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 |
| 265 | # ;; |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 266 | *) |
Instrumental | 9fe1153 | 2018-10-23 17:40:47 -0500 | [diff] [blame] | 267 | $JAVA_AGENT "$CMD" "$@" |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 268 | ;; |
| 269 | esac |
| 270 | fi |