39d4e8782e94cf6d767660a93b84ebc31ece0390
[aai/traversal.git] / aai-traversal / src / main / scripts / getTool.sh
1 #!/bin/ksh
2 #
3 # ============LICENSE_START=======================================================
4 # org.onap.aai
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
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 #
21 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 #
23
24 #
25 # The script is called with a resource.
26 # It invokes a GET on the resource using curl
27 # Uses aaiconfig.properties for authorization type and url.
28
29 # remove leading slash when present
30 RESOURCE=`echo $1 | sed "s,^/,,"`
31 if [ -z $RESOURCE ]; then
32         echo "resource parameter is missing"
33         echo "usage: $0 resource file [expected-failure-codes]"
34         exit 1
35 fi
36 echo `date` "   Starting $0 for resource $RESOURCE"
37
38 XFROMAPPID="AAI-TOOLS"
39 XTRANSID=`uuidgen`
40
41 userid=$( id | cut -f2 -d"(" | cut -f1 -d")" )
42 if [ "${userid}" != "aaiadmin" ]; then
43     echo "You must be aaiadmin to run $0. The id used $userid."
44     exit 1
45 fi
46
47 . /etc/profile.d/aai.sh
48 PROJECT_HOME=/opt/app/aai-traversal
49 prop_file=$PROJECT_HOME/bundleconfig/etc/appprops/aaiconfig.properties
50 log_dir=$PROJECT_HOME/logs/misc
51 today=$(date +\%Y-\%m-\%d)
52
53 MISSING_PROP=false
54 RESTURL=`grep ^aai.server.url= $prop_file |cut -d'=' -f2 |tr -d "\015"`
55 if [ -z $RESTURL ]; then
56         echo "Property [aai.server.url] not found in file $prop_file"
57         MISSING_PROP=true
58 fi
59 USEBASICAUTH=false
60 BASICENABLE=`grep ^aai.tools.enableBasicAuth $prop_file |cut -d'=' -f2 |tr -d "\015"`
61 if [ -z $BASICENABLE ]; then
62         USEBASICAUTH=false
63 else
64         USEBASICAUTH=true
65         CURLUSER=`grep ^aai.tools.username $prop_file |cut -d'=' -f2 |tr -d "\015"`
66         if [ -z $CURLUSER ]; then
67                 echo "Property [aai.tools.username] not found in file $prop_file"
68                 MISSING_PROP=true
69         fi
70         CURLPASSWORD=`grep ^aai.tools.password $prop_file |cut -d'=' -f2 |tr -d "\015"`
71         if [ -z $CURLPASSWORD ]; then
72                 echo "Property [aai.tools.password] not found in file $prop_file"
73                 MISSING_PROP=true
74         fi
75 fi
76
77 if [ $MISSING_PROP = false ]; then
78         if [ $USEBASICAUTH = false ]; then
79                 AUTHSTRING="--cert $PROJECT_HOME/bundleconfig/etc/auth/aaiClientPublicCert.pem --key $PROJECT_HOME/bundleconfig/etc/auth/aaiClientPrivateKey.pem"
80         else
81                 AUTHSTRING="-u $CURLUSER:$CURLPASSWORD"
82         fi
83         curl --request GET -sL -k $AUTHSTRING -H "X-FromAppId: $XFROMAPPID" -H "X-TransactionId: $XTRANSID" -H "Accept: application/json" $RESTURL$RESOURCE
84         RC=$?;
85 else
86         echo "usage: $0 resource"
87         RC=-1
88 fi
89
90 echo `date` "   Done $0, returning $RC"
91 exit $RC