diff options
Diffstat (limited to 'aai-traversal/src')
-rw-r--r-- | aai-traversal/src/main/docker/Dockerfile | 32 | ||||
-rw-r--r-- | aai-traversal/src/main/docker/aai.sh | 3 | ||||
-rw-r--r-- | aai-traversal/src/main/docker/docker-entrypoint.sh | 41 | ||||
-rw-r--r-- | aai-traversal/src/main/scripts/common_functions.sh | 15 | ||||
-rw-r--r-- | aai-traversal/src/main/scripts/deleteNamedQuery.sh | 9 | ||||
-rw-r--r-- | aai-traversal/src/main/scripts/deleteTool.sh | 18 | ||||
-rw-r--r-- | aai-traversal/src/main/scripts/getTool.sh | 12 | ||||
-rwxr-xr-x[-rw-r--r--] | aai-traversal/src/main/scripts/install/updateQueryData.sh | 49 | ||||
-rw-r--r-- | aai-traversal/src/main/scripts/putTool.sh | 114 |
9 files changed, 103 insertions, 190 deletions
diff --git a/aai-traversal/src/main/docker/Dockerfile b/aai-traversal/src/main/docker/Dockerfile index 0186e25..e17fa90 100644 --- a/aai-traversal/src/main/docker/Dockerfile +++ b/aai-traversal/src/main/docker/Dockerfile @@ -1,28 +1,14 @@ -FROM @aai.docker.namespace@/aai-common-@aai.base.image@:@aai.base.image.version@ +FROM eclipse-temurin:8-jre-alpine +# curl is used in the putTool script +# (PUT's can't be done using the busybox wget) +RUN apk --no-cache add curl -USER root +USER nobody +ENV SERVER_PORT=8446 +EXPOSE ${SERVER_PORT} -RUN mkdir -p /opt/aaihome/aaiadmin /opt/aai/logroot/AAI-GQ \ - /opt/app/aai-traversal \ - && chown -R aaiadmin:aaiadmin /opt/aaihome/aaiadmin /opt/aai/logroot/AAI-GQ \ - /opt/app/aai-traversal /etc/profile.d /opt/app /opt/aai/logroot \ - /etc/profile.d \ - /opt/app - -VOLUME /tmp -VOLUME /opt/tools - -HEALTHCHECK --interval=40s --timeout=10s --retries=3 CMD nc -z -v localhost 8446 || exit 1 - -# Add the proper files into the docker image from your build WORKDIR /opt/app/aai-traversal -COPY --chown=aaiadmin:aaiadmin /maven/aai-traversal/ . - -USER aaiadmin +COPY --chown=nobody:nobody /maven/aai-traversal/ . -ENV AAI_BUILD_VERSION @aai.docker.version@ -# Expose the ports for outside linux to use -# 8446 is the important one to be used -EXPOSE 8446 -ENTRYPOINT ["/bin/bash", "/opt/app/aai-traversal/docker-entrypoint.sh"]
\ No newline at end of file +ENTRYPOINT ["/bin/sh", "/opt/app/aai-traversal/docker-entrypoint.sh"] diff --git a/aai-traversal/src/main/docker/aai.sh b/aai-traversal/src/main/docker/aai.sh index 8cda4f0..412586e 100644 --- a/aai-traversal/src/main/docker/aai.sh +++ b/aai-traversal/src/main/docker/aai.sh @@ -30,7 +30,8 @@ if [ -z $JAVA_HOME ] && [ $(grep -i "ID=ubuntu" /etc/os-release | wc -w) -eq 1 ] fi # set app related env -export PROJECT_HOME=/opt/app/aai-traversal +: ${PROJECT_HOME:=/opt/app/aai-traversal} +export PROJECT_HOME=$PROJECT_HOME export AAIENV=dev export PROJECT_OWNER=aaiadmin export PROJECT_GROUP=aaiadmin diff --git a/aai-traversal/src/main/docker/docker-entrypoint.sh b/aai-traversal/src/main/docker/docker-entrypoint.sh index 7d3ca9a..be29460 100644 --- a/aai-traversal/src/main/docker/docker-entrypoint.sh +++ b/aai-traversal/src/main/docker/docker-entrypoint.sh @@ -7,9 +7,9 @@ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,45 +28,12 @@ GROUP_ID=${LOCAL_GROUP_ID:-9001} find /opt/app/ -name "*.sh" -exec chmod +x {} + -if [ -f ${APP_HOME}/aai.sh ]; then - - ln -s bin scripts - ln -s /opt/aai/logroot/AAI-GQ logs - mv ${APP_HOME}/aai.sh /etc/profile.d/aai.sh - - chmod 755 /etc/profile.d/aai.sh - - scriptName=$1; - - if [ ! -z $scriptName ]; then - - if [ -f ${APP_HOME}/bin/${scriptName} ]; then - shift 1; - ${APP_HOME}/bin/${scriptName} "$@" || { - echo "Failed to run the ${scriptName}"; - exit 1; - } - else - echo "Unable to find the script ${scriptName} in ${APP_HOME}/bin"; - exit 1; - fi; - - exit 0; - fi; -fi; - if [ -z ${DISABLE_UPDATE_QUERY} ]; then UPDATE_QUERY_RAN_FILE="updateQueryRan.txt"; /opt/app/aai-traversal/bin/install/updateQueryData.sh touch ${UPDATE_QUERY_RAN_FILE}; fi -mkdir -p /opt/app/aai-traversal/logs/gc - -if [ -f ${APP_HOME}/resources/aai-traversal-swm-vars.sh ]; then - source ${APP_HOME}/resources/aai-traversal-swm-vars.sh; -fi; - MIN_HEAP_SIZE=${MIN_HEAP_SIZE:-512m}; MAX_HEAP_SIZE=${MAX_HEAP_SIZE:-1024m}; MAX_METASPACE_SIZE=${MAX_METASPACE_SIZE:-512m}; @@ -105,10 +72,6 @@ JAVA_OPTS="${PRE_JAVA_OPTS} -DAJSC_HOME=$APP_HOME"; JAVA_OPTS="${JAVA_OPTS} -Dserver.port=${SERVER_PORT}"; JAVA_OPTS="${JAVA_OPTS} -DBUNDLECONFIG_DIR=./resources"; JAVA_OPTS="${JAVA_OPTS} -Dserver.local.startpath=${RESOURCES_HOME}"; -JAVA_OPTS="${JAVA_OPTS} -DAAI_CHEF_ENV=${AAI_CHEF_ENV}"; -JAVA_OPTS="${JAVA_OPTS} -DSCLD_ENV=${SCLD_ENV}"; -JAVA_OPTS="${JAVA_OPTS} -DAFT_ENVIRONMENT=${AFT_ENVIRONMENT}"; -JAVA_OPTS="${JAVA_OPTS} -DAAI_BUILD_VERSION=${AAI_BUILD_VERSION}"; JAVA_OPTS="${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom"; JAVA_OPTS="${JAVA_OPTS} -Dlogback.configurationFile=./resources/logback.xml"; JAVA_OPTS="${JAVA_OPTS} -Dloader.path=$APP_HOME/resources"; diff --git a/aai-traversal/src/main/scripts/common_functions.sh b/aai-traversal/src/main/scripts/common_functions.sh index 43de18c..6fb725a 100644 --- a/aai-traversal/src/main/scripts/common_functions.sh +++ b/aai-traversal/src/main/scripts/common_functions.sh @@ -1,22 +1,11 @@ -#!/bin/ksh +#!/bin/sh # Common functions that can be used throughout multiple scripts # In order to call these functions, this file needs to be sourced -# Checks if the user that is currently running is aaiadmin -check_user(){ - - userid=$( id | cut -f2 -d"(" | cut -f1 -d")" ) - - if [ "${userid}" != "aaiadmin" ]; then - echo "You must be aaiadmin to run $0. The id used $userid." - exit 1 - fi -} - # Sources the profile and sets the project home source_profile(){ - PROJECT_HOME=/opt/app/aai-traversal + : ${PROJECT_HOME:=/opt/app/aai-traversal} } # Runs the spring boot jar based on which main class diff --git a/aai-traversal/src/main/scripts/deleteNamedQuery.sh b/aai-traversal/src/main/scripts/deleteNamedQuery.sh index 43aaae7..6213de3 100644 --- a/aai-traversal/src/main/scripts/deleteNamedQuery.sh +++ b/aai-traversal/src/main/scripts/deleteNamedQuery.sh @@ -1,4 +1,4 @@ -#!/bin/ksh +#!/bin/sh # # ============LICENSE_START======================================================= # org.onap.aai @@ -31,13 +31,6 @@ OUTFILE=/opt/app/aai-traversal/logs/misc/${PROGNAME}.log.$(date +\%Y-\%m-\%d) TS=$(date "+%Y-%m-%d %H:%M:%S") -CHECK_USER="aaiadmin" -userid=$( id | cut -f2 -d"(" | cut -f1 -d")" ) -if [ "${userid}" != $CHECK_USER ]; then - echo "You must be $CHECK_USER to run $0. The id used $userid." - exit 1 -fi - error_exit () { echo "${PROGNAME}: failed for ${1:-"Unknown error"} on cmd $2" 1>&2 echo "${PROGNAME}: failed for ${1:-"Unknown error"} on cmd $2" >> $OUTFILE diff --git a/aai-traversal/src/main/scripts/deleteTool.sh b/aai-traversal/src/main/scripts/deleteTool.sh index c347b0d..239563b 100644 --- a/aai-traversal/src/main/scripts/deleteTool.sh +++ b/aai-traversal/src/main/scripts/deleteTool.sh @@ -1,4 +1,4 @@ -#!/bin/ksh +#!/bin/sh # # ============LICENSE_START======================================================= # org.onap.aai @@ -23,7 +23,7 @@ # # The script is called with a resource to be deleted. -# Uses aaiconfig.properties for authorization type and url. +# Uses aaiconfig.properties for authorization type and url. # It invokes a GET on the resource using curl and parses the resource-version. # If found, prompts the user to continue and invokes DELETE using curl. # responses in the range of 200 to 299 are considered successful @@ -39,17 +39,11 @@ fi echo `date` " Starting $0 for resource $RESOURCE" XFROMAPPID="AAI-TOOLS" -XTRANSID=`uuidgen` -XTRANSID1=`uuidgen` - -userid=$( id | cut -f2 -d"(" | cut -f1 -d")" ) -if [ "${userid}" != "aaiadmin" ]; then - echo "You must be aaiadmin to run $0. The id used $userid." - exit 1 -fi +XTRANSID="someUUID" +XTRANSID1="someUUID" -PROJECT_HOME=/opt/app/aai-traversal +: ${PROJECT_HOME:=/opt/app/aai-traversal} prop_file=$PROJECT_HOME/resources/etc/appprops/aaiconfig.properties log_dir=$PROJECT_HOME/logs/misc today=$(date +\%Y-\%m-\%d) @@ -98,7 +92,7 @@ if [ $MISSING_PROP = false ]; then echo `date` " Done $0, returning -1" exit -1 fi - + result=`curl --request DELETE -sL -w "%{http_code}" -o /dev/null -k $AUTHSTRING -H "X-FromAppId: $XFROMAPPID" -H "X-TransactionId: $XTRANSID" -H "Accept: application/json" $RESTURL$RESOURCE?resource-version=$RESOURCEVERSION` echo "result is $result." RC=0; diff --git a/aai-traversal/src/main/scripts/getTool.sh b/aai-traversal/src/main/scripts/getTool.sh index 6db0914..f72120b 100644 --- a/aai-traversal/src/main/scripts/getTool.sh +++ b/aai-traversal/src/main/scripts/getTool.sh @@ -1,4 +1,4 @@ -#!/bin/ksh +#!/bin/sh # # ============LICENSE_START======================================================= # org.onap.aai @@ -36,16 +36,10 @@ fi echo `date` " Starting $0 for resource $RESOURCE" XFROMAPPID="AAI-TOOLS" -XTRANSID=`uuidgen` - -userid=$( id | cut -f2 -d"(" | cut -f1 -d")" ) -if [ "${userid}" != "aaiadmin" ]; then - echo "You must be aaiadmin to run $0. The id used $userid." - exit 1 -fi +XTRANSID="someUUID" -PROJECT_HOME=/opt/app/aai-traversal +: ${PROJECT_HOME:=/opt/app/aai-traversal} prop_file=$PROJECT_HOME/resources/etc/appprops/aaiconfig.properties log_dir=$PROJECT_HOME/logs/misc today=$(date +\%Y-\%m-\%d) diff --git a/aai-traversal/src/main/scripts/install/updateQueryData.sh b/aai-traversal/src/main/scripts/install/updateQueryData.sh index 7b5d1b3..9884efe 100644..100755 --- a/aai-traversal/src/main/scripts/install/updateQueryData.sh +++ b/aai-traversal/src/main/scripts/install/updateQueryData.sh @@ -1,4 +1,4 @@ -#!/bin/ksh +#!/bin/sh # # ============LICENSE_START======================================================= # org.onap.aai @@ -22,8 +22,8 @@ # PROGNAME=$(basename $0) -PROJECT_HOME=/opt/app/aai-traversal -OUTFILE=$PROJECT_HOME/logs/misc/${PROGNAME}.log.$(date +\%Y-\%m-\%d) + +: ${PROJECT_HOME:=/opt/app/aai-traversal} if [ "$1" = "--debug" ]; then set -x; @@ -31,16 +31,8 @@ fi; TS=$(date "+%Y-%m-%d %H:%M:%S") -CHECK_USER="aaiadmin" -userid=$( id | cut -f2 -d"(" | cut -f1 -d")" ) -if [ "${userid}" != $CHECK_USER ]; then - echo "You must be $CHECK_USER to run $0. The id used $userid." - exit 1 -fi - error_exit () { echo "${PROGNAME}: failed for ${1:-"Unknown error"} on cmd $2" 1>&2 - echo "${PROGNAME}: failed for ${1:-"Unknown error"} on cmd $2" >> $OUTFILE # exit ${2:-"1"} } @@ -54,11 +46,11 @@ vers=`grep model-invariant-id $filepath|cut -d':' -f2|cut -d'"' -f2` # last parameter will skip put if it exists resource=service-design-and-creation/models/model/$vers if [ "$1" = "--debug" ]; then - bash -x $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j -else - $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j + sh -x $PROJECT_HOME/bin/putTool.sh $resource $filepath 412 2>&1 || error_exit "$resource $filepath" $j +else + $PROJECT_HOME/bin/putTool.sh $resource $filepath 412 2>&1 || error_exit "$resource $filepath" $j fi; -echo "End putTool for widget $filename" | tee -a $OUTFILE +echo "End putTool for widget $filename" done j=0 @@ -66,16 +58,16 @@ for filepath in `ls $PROJECT_HOME/resources/etc/scriptdata/named-query-json/*.js do j=$(expr "$j" + 1) filename=$(basename $filepath) -echo "Begin putTool for named-query $filename" | tee -a $OUTFILE +echo "Begin putTool for named-query $filename" vers=`grep named-query-uuid $filepath|cut -d':' -f2|cut -d'"' -f2` # last parameter will skip put if it exists resource=service-design-and-creation/named-queries/named-query/$vers if [ "$1" = "--debug" ]; then - bash -x $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j + bash -x $PROJECT_HOME/bin/putTool.sh $resource $filepath 412 2>&1 || error_exit "$resource $filepath" $j else - $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j + $PROJECT_HOME/bin/putTool.sh $resource $filepath 412 2>&1 || error_exit "$resource $filepath" $j fi; -echo "End putTool for named-query $filename" | tee -a $OUTFILE +echo "End putTool for named-query $filename" done j=0 @@ -83,16 +75,16 @@ for filepath in `ls $PROJECT_HOME/resources/etc/scriptdata/resource-model-json/* do j=$(expr "$j" + 1) filename=$(basename $filepath) -echo "Begin putTool for resource model $filename" | tee -a $OUTFILE +echo "Begin putTool for resource model $filename" vers=`grep model-invariant-id $filepath|cut -d':' -f2|cut -d'"' -f2` # last parameter will skip put if it exists resource=service-design-and-creation/models/model/$vers if [ "$1" = "--debug" ]; then - bash -x $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j + bash -x $PROJECT_HOME/bin/putTool.sh $resource $filepath 412 2>&1 || error_exit "$resource $filepath" $j else - $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j + $PROJECT_HOME/bin/putTool.sh $resource $filepath 412 2>&1 || error_exit "$resource $filepath" $j fi; -echo "End putTool for resource model $filename" | tee -a $OUTFILE +echo "End putTool for resource model $filename" done j=0 @@ -100,19 +92,18 @@ for filepath in `ls $PROJECT_HOME/resources/etc/scriptdata/service-model-json/*. do j=$(expr "$j" + 1) filename=$(basename $filepath) -echo "Begin putTool for service model $filename" | tee -a $OUTFILE +echo "Begin putTool for service model $filename" vers=`grep model-invariant-id $filepath|cut -d':' -f2|cut -d'"' -f2` # last parameter will skip put if it exists resource=service-design-and-creation/models/model/$vers if [ "$1" = "--debug" ]; then - bash -x $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j + bash -x $PROJECT_HOME/bin/putTool.sh $resource $filepath 412 2>&1 || error_exit "$resource $filepath" $j else - $PROJECT_HOME/scripts/putTool.sh $resource $filepath 412 >> $OUTFILE 2>&1 || error_exit "$resource $filepath" $j + $PROJECT_HOME/bin/putTool.sh $resource $filepath 412 2>&1 || error_exit "$resource $filepath" $j fi; -echo "End putTool for service model $filename" | tee -a $OUTFILE +echo "End putTool for service model $filename" done -echo "$PROGNAME completed ${TS}" | tee -a $OUTFILE -echo "See output and error file: $OUTFILE" +echo "$PROGNAME completed ${TS}" exit 0 diff --git a/aai-traversal/src/main/scripts/putTool.sh b/aai-traversal/src/main/scripts/putTool.sh index 6f22067..28463f4 100644 --- a/aai-traversal/src/main/scripts/putTool.sh +++ b/aai-traversal/src/main/scripts/putTool.sh @@ -1,4 +1,4 @@ -#!/bin/ksh +#!/bin/sh # # ============LICENSE_START======================================================= # org.onap.aai @@ -78,16 +78,11 @@ echo `date` " Starting $0 for resource $RESOURCE" ALLOWHTTPRESPONSES=$3 XFROMAPPID="AAI-TOOLS" -XTRANSID=`uuidgen` +XTRANSID="someUUID" -userid=$( id | cut -f2 -d"(" | cut -f1 -d")" ) -if [ "${userid}" != "aaiadmin" ]; then - echo "You must be aaiadmin to run $0. The id used $userid." - exit 1 -fi -PROJECT_HOME=/opt/app/aai-traversal +: ${PROJECT_HOME:=/opt/app/aai-traversal} prop_file=$PROJECT_HOME/resources/etc/appprops/aaiconfig.properties log_dir=$PROJECT_HOME/logs/misc today=$(date +\%Y-\%m-\%d) @@ -130,62 +125,69 @@ fi fname=$JSONFILE if [ -f /tmp/$(basename $JSONFILE) ]; then - fname=/tmp/$(basename $JSONFILE) + fname=/tmp/$(basename $JSONFILE) elif [ ! -f $JSONFILE ]; then - echo "The file $JSONFILE does not exist" - exit -1 + echo "The file $JSONFILE does not exist" + exit -1 fi if [ $MISSING_PROP = false ]; then - if [ $USEBASICAUTH = false ]; then - AUTHSTRING="--cert $PROJECT_HOME/resources/etc/auth/aaiClientPublicCert.pem --key $PROJECT_HOME/resources/etc/auth/aaiClientPrivateKey.pem" - else - AUTHSTRING="-u $CURLUSER:$CURLPASSWORD" - fi - if [ $RETURNRESPONSE = true ]; then - curl --request PUT -sL -k $AUTHSTRING -H "X-FromAppId: $XFROMAPPID" -H "X-TransactionId: $XTRANSID" -H "Accept: application/json" -H "Content-Type: application/json" -T $fname $RESTURL$RESOURCE | jq '.' - RC=$? - else - result=`curl --request PUT -w "%{http_code}" -o /dev/null -k $AUTHSTRING -H "X-FromAppId: $XFROMAPPID" -H "X-TransactionId: $XTRANSID" -H "Accept: application/json" -H "Content-Type: application/json" -T $fname $RESTURL$RESOURCE` - #echo "result is $result." - RC=0; - if [ $? -eq 0 ]; then - case $result in - +([0-9])?) - if [[ "$result" -ge 200 && $result -lt 300 ]] - then - echo "PUT result is OK, $result" - else - if [ -z $ALLOWHTTPRESPONSES ]; then - echo "PUT request failed, response code was $result" - RC=$result - else - contains $ALLOWHTTPRESPONSES $result - if [ $? -ne 0 ] - then - echo "PUT request failed, unexpected response code was $result" - RC=$result - else - echo "PUT result is expected, $result" - fi - fi - fi - ;; - *) - echo "PUT request failed, response was $result" - RC=-1 - ;; - + if [ $USEBASICAUTH = false ]; then + AUTHSTRING="--cert $PROJECT_HOME/resources/etc/auth/aaiClientPublicCert.pem --key $PROJECT_HOME/resources/etc/auth/aaiClientPrivateKey.pem" + else + AUTHSTRING="-u $CURLUSER:$CURLPASSWORD" + fi + if [ $RETURNRESPONSE = true ]; then + curl --request PUT -sL -k $AUTHSTRING -H "X-FromAppId: $XFROMAPPID" -H "X-TransactionId: $XTRANSID" -H "Accept: application/json" -H "Content-Type: application/json" -T $fname $RESTURL$RESOURCE | jq '.' + RC=$? + else + result=`curl --request PUT -w "%{http_code}" -o /dev/null -k $AUTHSTRING -H "X-FromAppId: $XFROMAPPID" -H "X-TransactionId: $XTRANSID" -H "Accept: application/json" -H "Content-Type: application/json" -T $fname $RESTURL$RESOURCE` + #echo "result is $result." + RC=0; + if [ $? -eq 0 ]; then + case $result in + # Match one or more digits optionally followed by another character + *[0-9]*) + if [ "$result" -ge 200 ] && [ "$result" -lt 300 ]; then + echo "PUT result is OK, $result" + else + if [ -z "$ALLOWHTTPRESPONSES" ]; then + echo "PUT request failed, response code was $result" + RC=$result + else + # Function to check if a string is in a list of strings + contains() { + for item in $1; do + if [ "$item" = "$2" ]; then + return 0 + fi + done + return 1 + } + contains "$ALLOWHTTPRESPONSES" "$result" + if [ $? -ne 0 ]; then + echo "PUT request failed, unexpected response code was $result" + RC=$result + else + echo "PUT result is expected, $result" + fi + fi + fi + ;; + *) + echo "PUT request failed, response was $result" + RC=-1 + ;; esac - else + else echo "FAILED to send request to $RESTURL" RC=-1 - fi - fi + fi + fi else - echo "usage: $0 resource file [expected-failure-codes]" - RC=-1 + echo "usage: $0 resource file [expected-failure-codes]" + RC=-1 fi echo `date` " Done $0, returning $RC" -exit $RC
\ No newline at end of file +exit $RC |