From 3501e74711a2e91ce84d0b4cbc989738f96e0891 Mon Sep 17 00:00:00 2001 From: "Kajur, Harish (vk250x)" Date: Wed, 10 Apr 2019 13:46:17 -0400 Subject: Add additional logging statements Fix the metaspace issue Respond to an invalid content-type appropriately Add getTool.sh to the scripts Issue-ID: AAI-2326 Change-Id: Ib4764ba71be78816e549f59ccbdab8ccb14dc4c0 Signed-off-by: Kajur, Harish (vk250x) --- .../src/main/scripts/common_functions.sh | 100 +++++++++++++++++++ aai-schema-service/src/main/scripts/getTool.sh | 110 +++++++++++++++++++++ aai-schema-service/src/main/scripts/updatePem.sh | 38 +++++++ 3 files changed, 248 insertions(+) create mode 100644 aai-schema-service/src/main/scripts/common_functions.sh create mode 100644 aai-schema-service/src/main/scripts/getTool.sh create mode 100644 aai-schema-service/src/main/scripts/updatePem.sh (limited to 'aai-schema-service/src/main/scripts') diff --git a/aai-schema-service/src/main/scripts/common_functions.sh b/aai-schema-service/src/main/scripts/common_functions.sh new file mode 100644 index 0000000..7dfda25 --- /dev/null +++ b/aai-schema-service/src/main/scripts/common_functions.sh @@ -0,0 +1,100 @@ +#!/bin/ksh +# +# ============LICENSE_START======================================================= +# org.onap.aai +# ================================================================================ +# Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +# + + +# 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(){ + . /etc/profile.d/aai.sh + PROJECT_HOME=/opt/app/aai-schema-service +} + +# Runs the spring boot jar based on which main class +# to execute and which logback file to use for that class +execute_spring_jar(){ + + className=$1; + logbackFile=$2; + + shift 2; + + EXECUTABLE_JAR=$(ls ${PROJECT_HOME}/lib/*.jar); + + JAVA_OPTS="${JAVA_PRE_OPTS} -DAJSC_HOME=$PROJECT_HOME"; + JAVA_OPTS="$JAVA_OPTS -DBUNDLECONFIG_DIR=resources"; + JAVA_OPTS="$JAVA_OPTS -Daai.home=$PROJECT_HOME "; + JAVA_OPTS="$JAVA_OPTS -Dhttps.protocols=TLSv1.1,TLSv1.2"; + JAVA_OPTS="$JAVA_OPTS -Dloader.main=${className}"; + JAVA_OPTS="$JAVA_OPTS -Dloader.path=${PROJECT_HOME}/resources"; + JAVA_OPTS="$JAVA_OPTS -Dlogback.configurationFile=${logbackFile}"; + + export SOURCE_NAME=$(grep '^schema.source.name=' ${PROJECT_HOME}/resources/application.properties | cut -d"=" -f2-); + # Needed for the schema ingest library beans + eval $(grep '^schema\.' ${PROJECT_HOME}/resources/application.properties | \ + sed 's/^\(.*\)$/JAVA_OPTS="$JAVA_OPTS -D\1"/g' | \ + sed 's/${server.local.startpath}/${PROJECT_HOME}\/resources/g'| \ + sed 's/${schema.source.name}/'${SOURCE_NAME}'/g'\ + ) + + JAVA_OPTS="${JAVA_OPTS} ${JAVA_POST_OPTS}"; + + ${JAVA_HOME}/bin/java ${JVM_OPTS} ${JAVA_OPTS} -jar ${EXECUTABLE_JAR} "$@" +} + +# Prints the start date and the script that the user called +start_date(){ + echo + echo `date` " Starting $0" +} + +# Prints the end date and the script that the user called +end_date(){ + echo + echo `date` " Done $0" +} + +# Inserts GEN_DB_WITH_NO_SCHEMA as a paranmter if it isn't there already +force_GEN_DB_WITH_NO_SCHEMA () { + for p in "$@" + do + if [ "$p" == "GEN_DB_WITH_NO_SCHEMA" ] + then + echo "$@" + return + fi + done + echo "GEN_DB_WITH_NO_SCHEMA $@" + return +} + diff --git a/aai-schema-service/src/main/scripts/getTool.sh b/aai-schema-service/src/main/scripts/getTool.sh new file mode 100644 index 0000000..9b8b26e --- /dev/null +++ b/aai-schema-service/src/main/scripts/getTool.sh @@ -0,0 +1,110 @@ +#!/bin/ksh + +### +# ============LICENSE_START======================================================= +# org.onap.aai +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# The script is called with a resource. +# It invokes a GET on the resource using curl +# Uses aaiconfig.properties for authorization type and url. + +display_usage() { + cat < + 2. This script needs only one argument and the argument should be resource-path. + 3. for example: resource-path for a particular customer is /aai/schema-service/v1/versions +EOF +} +if [ $# -eq 0 ]; then + display_usage + exit 1 +fi + +# remove leading slash when present +RESOURCE=$(echo $1 | sed "s,^/,,") + +if [ -z $RESOURCE ]; then + echo "resource parameter is missing" + echo "usage: $0 resource file [expected-failure-codes]" + exit 1 +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 + +. /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-schema-service +prop_file=$PROJECT_HOME/resources/etc/appprops/aaiconfig.properties +log_dir=$PROJECT_HOME/logs/misc +today=$(date +\%Y-\%m-\%d) + + +MISSING_PROP=false +RESTURL=$(grep ^aai.server.url= $prop_file |cut -d'=' -f2 |tr -d "\015") +if [ -z $RESTURL ]; then + echo "Property [aai.server.url] not found in file $prop_file" + MISSING_PROP=true +fi +USEBASICAUTH=false +BASICENABLE=$(grep ^aai.tools.enableBasicAuth $prop_file |cut -d'=' -f2 |tr -d "\015") +if [ -z $BASICENABLE ]; then + USEBASICAUTH=false +else + USEBASICAUTH=true + CURLUSER=$(grep ^aai.tools.username $prop_file |cut -d'=' -f2 |tr -d "\015") + if [ -z $CURLUSER ]; then + echo "Property [aai.tools.username] not found in file $prop_file" + MISSING_PROP=true + fi + CURLPASSWORD=$(grep ^aai.tools.password $prop_file |cut -d'=' -f2 |tr -d "\015") + if [ -z $CURLPASSWORD ]; then + echo "Property [aai.tools.password] not found in file $prop_file" + MISSING_PROP=true + fi +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 [[ $RESOURCE == *"nodes"* ]]; then + curl --request GET -sL -k $AUTHSTRING -H "X-FromAppId: $XFROMAPPID" -H "X-TransactionId: $XTRANSID" -H "Accept: application/xml" $RESTURL$RESOURCE -d sed 's/\r//g' + else + curl --request GET -sL -k $AUTHSTRING -H "X-FromAppId: $XFROMAPPID" -H "X-TransactionId: $XTRANSID" -H "Accept: application/json" $RESTURL$RESOURCE | jq -M '.' | sed 's/\r//g' + fi + RC=$?; +else + echo "usage: $0 resource" + RC=-1 +fi + +echo `date` " Done $0, returning $RC" +exit $RC diff --git a/aai-schema-service/src/main/scripts/updatePem.sh b/aai-schema-service/src/main/scripts/updatePem.sh new file mode 100644 index 0000000..6e6ac6f --- /dev/null +++ b/aai-schema-service/src/main/scripts/updatePem.sh @@ -0,0 +1,38 @@ +#!/bin/ksh + +### +# ============LICENSE_START======================================================= +# org.onap.aai +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +COMMON_ENV_PATH=$( cd "$(dirname "$0")" ; pwd -P ) +. ${COMMON_ENV_PATH}/common_functions.sh + +start_date; +check_user; +source_profile; + +CERTPATH=$PROJECT_HOME/resources/etc/auth/ +KEYNAME=aaiClientPrivateKey.pem +CERTNAME=aaiClientPublicCert.pem + +pw=$(execute_spring_jar org.onap.aai.util.AAIConfigCommandLinePropGetter "" "aai.keystore.passwd" 2> /dev/null | tail -1) +openssl pkcs12 -in ${CERTPATH}/aai-client-cert.p12 -out $CERTPATH$CERTNAME -clcerts -nokeys -passin pass:$pw +openssl pkcs12 -in ${CERTPATH}/aai-client-cert.p12 -out $CERTPATH$KEYNAME -nocerts -nodes -passin pass:$pw +end_date; +exit 0 -- cgit 1.2.3-korg