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