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.
26 # The script is called with a resource, filepath and an optional argument to
27 # ignore HTTP failure codes which would otherwise indicate a failure.
29 # The script is called with a resource, filepath, an optional argument to
30 # ignore HTTP failure codes which would otherwise indicate a failure,
31 # and an optional argument to display more data.
32 >>>>>>> codecloud/release/1802
33 # It invokes a PUT on the resource with the file using curl
34 # Uses aaiconfig.properties for authorization type and url. The HTTP response
35 # code is checked. Responses between 200 and 299 are considered success.
36 # When the ignore failure code parameter is passed, responses outside of
37 # the 200 to 299 range but matching a sub-string of the parameter are
38 # considered success. For example, a parameter value of 412 will consider
39 # responses in the range of 200 to 299 and 412 successes.
41 # method checking parameter list for two strings, and determine if
42 # the second string is a sub-string of the first
46 if test "${string#*$substring}" != "$string"
48 return 0 # $substring is in $string
50 return 1 # $substring is not in $string
60 1. Usage: putTool.sh <resource-path> <json payload file> <optional HTTP Response code> <optional -display>
61 2. This script requires two arguments, a resource path and a file path to a json file containing the payload.
62 3. Example: query?format=xxxx customquery.json (possible formats are simple, raw, console, count, graphson, id, pathed, resource and resource_and_url)
63 4. Adding the optional HTTP Response code will allow the script to ignore HTTP failure codes that match the input parameter.
64 5. Adding the optional "-display" argument will display all data returned from the request, instead of just a response code.
73 >>>>>>> codecloud/release/1802
74 # remove leading slash when present
75 RESOURCE=`echo $1 | sed "s,^/,,"`
76 if [ -z $RESOURCE ]; then
77 echo "resource parameter is missing"
78 echo "usage: $0 resource file [expected-failure-codes]"
82 if [ -z $JSONFILE ]; then
83 echo "json file parameter is missing"
84 echo "usage: $0 resource file [expected-failure-codes]"
87 echo `date` " Starting $0 for resource $RESOURCE"
90 XFROMAPPID="AAI-TOOLS"
93 userid=$( id | cut -f2 -d"(" | cut -f1 -d")" )
94 if [ "${userid}" != "aaiadmin" ]; then
95 echo "You must be aaiadmin to run $0. The id used $userid."
99 . /etc/profile.d/aai.sh
100 PROJECT_HOME=/opt/app/aai-traversal
101 prop_file=$PROJECT_HOME/bundleconfig/etc/appprops/aaiconfig.properties
102 log_dir=$PROJECT_HOME/logs/misc
103 today=$(date +\%Y-\%m-\%d)
108 if [ ${#} -ne 2 ]; then
109 if [ "$3" = "-display" ]; then
113 if [ ${#} -ne 3 ]; then
114 if [ "$4" = "-display" ]; then
119 >>>>>>> codecloud/release/1802
121 RESTURL=`grep ^aai.server.url= $prop_file |cut -d'=' -f2 |tr -d "\015"`
122 if [ -z $RESTURL ]; then
123 echo "Property [aai.server.url] not found in file $prop_file"
127 BASICENABLE=`grep ^aai.tools.enableBasicAuth $prop_file |cut -d'=' -f2 |tr -d "\015"`
128 if [ -z $BASICENABLE ]; then
132 CURLUSER=`grep ^aai.tools.username $prop_file |cut -d'=' -f2 |tr -d "\015"`
133 if [ -z $CURLUSER ]; then
134 echo "Property [aai.tools.username] not found in file $prop_file"
137 CURLPASSWORD=`grep ^aai.tools.password $prop_file |cut -d'=' -f2 |tr -d "\015"`
138 if [ -z $CURLPASSWORD ]; then
139 echo "Property [aai.tools.password] not found in file $prop_file"
144 if [ $MISSING_PROP = false ]; then
145 if [ $USEBASICAUTH = false ]; then
146 AUTHSTRING="--cert $PROJECT_HOME/bundleconfig/etc/auth/aaiClientPublicCert.pem --key $PROJECT_HOME/bundleconfig/etc/auth/aaiClientPrivateKey.pem"
148 AUTHSTRING="-u $CURLUSER:$CURLPASSWORD"
151 result=`curl --request PUT -sL -w "%{http_code}" -o /dev/null -k $AUTHSTRING -H "X-FromAppId: $XFROMAPPID" -H "X-TransactionId: $XTRANSID" -H "Accept: application/json" -T $JSONFILE $RESTURL$RESOURCE`
152 #echo "result is $result."
154 if [ $? -eq 0 ]; then
157 if [ $RETURNRESPONSE = true ]; then
158 curl --request PUT -sL -k $AUTHSTRING -H "X-FromAppId: $XFROMAPPID" -H "X-TransactionId: $XTRANSID" -H "Accept: application/json" -T $JSONFILE $RESTURL$RESOURCE | python -mjson.tool
161 result=`curl --request PUT -sL -w "%{http_code}" -o /dev/null -k $AUTHSTRING -H "X-FromAppId: $XFROMAPPID" -H "X-TransactionId: $XTRANSID" -H "Accept: application/json" -T $JSONFILE $RESTURL$RESOURCE`
162 #echo "result is $result."
164 if [ $? -eq 0 ]; then
165 >>>>>>> codecloud/release/1802
168 #if [[ "$result" -eq 412 || "$result" -ge 200 && $result -lt 300 ]]
169 if [[ "$result" -ge 200 && $result -lt 300 ]]
171 echo "PUT result is OK, $result"
173 if [ -z $ALLOWHTTPRESPONSES ]; then
174 echo "PUT request failed, response code was $result"
177 contains $ALLOWHTTPRESPONSES $result
180 echo "PUT request failed, unexpected response code was $result"
183 echo "PUT result is expected, $result"
189 echo "PUT request failed, response was $result"
196 echo "FAILED to send request to $RESTURL"
201 echo "FAILED to send request to $RESTURL"
205 >>>>>>> codecloud/release/1802
207 echo "usage: $0 resource file [expected-failure-codes]"
211 echo `date` " Done $0, returning $RC"