3 # ============LICENSE_START=======================================================
5 # ================================================================================
6 # Copyright © 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 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
25 # The script is called with a resource to be deleted.
26 # Uses aaiconfig.properties for authorization type and url.
27 # It invokes a GET on the resource using curl and parses the resource-version.
28 # If found, prompts the user to continue and invokes DELETE using curl.
29 # responses in the range of 200 to 299 are considered successful
32 # remove leading slash when present
33 RESOURCE=`echo $1 | sed "s,^/,,"`
34 if [ -z $RESOURCE ]; then
35 echo "resource parameter is missing"
36 echo "usage: $0 resource"
39 echo `date` " Starting $0 for resource $RESOURCE"
41 XFROMAPPID="AAI-TOOLS"
45 userid=$( id | cut -f2 -d"(" | cut -f1 -d")" )
46 if [ "${userid}" != "aaiadmin" ]; then
47 echo "You must be aaiadmin to run $0. The id used $userid."
51 . /etc/profile.d/aai.sh
52 PROJECT_HOME=/opt/app/aai-traversal
53 prop_file=$PROJECT_HOME/bundleconfig/etc/appprops/aaiconfig.properties
54 log_dir=$PROJECT_HOME/logs/misc
55 today=$(date +\%Y-\%m-\%d)
58 RESTURL=`grep ^aai.server.url= $prop_file |cut -d'=' -f2 |tr -d "\015"`
59 if [ -z $RESTURL ]; then
60 echo "Property [aai.server.url] not found in file $prop_file"
64 BASICENABLE=`grep ^aai.tools.enableBasicAuth $prop_file |cut -d'=' -f2 |tr -d "\015"`
65 if [ -z $BASICENABLE ]; then
69 CURLUSER=`grep ^aai.tools.username $prop_file |cut -d'=' -f2 |tr -d "\015"`
70 if [ -z $CURLUSER ]; then
71 echo "Property [aai.tools.username] not found in file $prop_file"
74 CURLPASSWORD=`grep ^aai.tools.password $prop_file |cut -d'=' -f2 |tr -d "\015"`
75 if [ -z $CURLPASSWORD ]; then
76 echo "Property [aai.tools.password] not found in file $prop_file"
81 if [ $MISSING_PROP = false ]; then
82 if [ $USEBASICAUTH = false ]; then
83 AUTHSTRING="--cert $PROJECT_HOME/bundleconfig/etc/auth/aaiClientPublicCert.pem --key $PROJECT_HOME/bundleconfig/etc/auth/aaiClientPrivateKey.pem"
85 AUTHSTRING="-u $CURLUSER:$CURLPASSWORD"
87 RESOURCEVERSION=`curl --request GET -sL -k $AUTHSTRING -H "X-FromAppId: $XFROMAPPID" -H "X-TransactionId: $XTRANSID1" -H "Accept: application/json" $RESTURL$RESOURCE|awk -F"\"resource-version\":\"" '{print $2}' | cut -d\" -f1`
88 echo "resource-version is" $RESOURCEVERSION
89 if [ -z $RESOURCEVERSION ]; then
90 echo "failed to get resource-version for $RESOURCE"
91 echo `date` " Done $0, returning -1"
94 echo "Are you sure you would like to delete $RESOURCE? (y, n)"
96 if [ "$USERINPUT" != "y" ]; then
97 echo "user chose to exit before delete"
98 echo `date` " Done $0, returning -1"
102 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`
103 echo "result is $result."
105 if [ $? -eq 0 ]; then
108 if [[ "$result" -ge 200 && $result -lt 300 ]]
110 echo "DELETE result is OK, $result"
112 echo "failed DELETE request, response code was $result"
117 echo "DELETE request failed, response was $result"
123 echo "FAILED to send request to $RESTURL"
127 echo "usage: $0 resource"
132 echo `date` " Done $0, returning $RC"