-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdeploy-apis.sh
More file actions
150 lines (115 loc) · 4.58 KB
/
Copy pathdeploy-apis.sh
File metadata and controls
150 lines (115 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#! /bin/sh
nice_echo() {
echo "\n\033[1;36m >>>>>>>>>> $1 <<<<<<<<<< \033[0m\n"
}
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# no parameters passed, using default config file
if [ $# -eq 0 ]; then
#using default config file
if [ -e config.cfg ]; then
source config.cfg
echo 'Using default config file at ' ${CURRENT_DIR}/config.cfg
else
echo 'No config file passed and default config file is not available at ' ${CURRENT_DIR}/config.cfg
exit
fi
# usage function
elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "Usage: `basename $0` [OPTION] [FILE]...
Options:
-h, --help Display this help and exit
"
exit 0
# config file passed as argument
else
FILENAME=$1 #get filename
if [ -e $FILENAME ]; then
source $FILENAME; # load the file
echo 'Using config file located at ' $FILENAME
else
echo 'Bad config file passed at ' $FILENAME
exit
fi
fi
RED='\n\033[1;31m'
GREEN='\n\033[1;32m'
END_COLOR='\033[0m'
# ******************** Step 9. Obtain API document #1 ********************
nice_echo "Step 9. Obtain API document #1"
RESPONSE=`curl -s -k -H "Content-Type: application/json" -H "Accept: application/json" $API_DEFINITION_URL`
if [[ $RESPONSE == null ]]; #call failed
then
echo 'Failed call with error' $RESPONSE
#exit
else
echo 'Sucessfully retrieved API.'
fi
# ******************** Step 10. Create API #1 ********************
nice_echo "Step 10. Create API #1"
CURL_BODY='{"type":"draft_api","draft_api":'${RESPONSE}'}'
RESPONSE=`curl -s -k -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer $TOKEN_RESPONSE" -d "$CURL_BODY" ${APIM_SERVER}/api/orgs/${pORG_NAME}/drafts/draft-apis --silent`
RESPONSE_URL=`echo "$RESPONSE" | jq -r '.url'`
if [[ $RESPONSE_URL == null ]]; #call failed
then
echo 'Failed call with error' $RESPONSE
#exit
else
echo 'Sucessfully created API in Drafts ' $RESPONSE_URL
fi
# ******************** Step 11. Obtain API document #1 ********************
nice_echo "Step 11. Obtain API document #2"
RESPONSE=`curl -s -k -H "Content-Type: application/json" -H "Accept: application/json" $API_DEFINITION_URL2`
if [[ $RESPONSE == null ]]; #call failed
then
echo 'Failed call with error' $RESPONSE
#exit
else
echo 'Sucessfully retrieved API.'
fi
# ******************** Step 12. Create API #2 ********************
nice_echo "Step 12. Create API #2"
CURL_BODY='{"type":"draft_api","draft_api":'${RESPONSE}'}'
RESPONSE=`curl -s -k -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer $TOKEN_RESPONSE" -d "$CURL_BODY" ${APIM_SERVER}/api/orgs/${pORG_NAME}/drafts/draft-apis --silent`
RESPONSE_URL=`echo "$RESPONSE" | jq -r '.url'`
if [[ $RESPONSE_URL == null ]]; #call failed
then
echo 'Failed call with error' $RESPONSE
#exit
else
echo 'Sucessfully created API in Drafts ' $RESPONSE_URL
fi
# ******************** Step 13. Obtain API product ********************
nice_echo "Step 13. Obtain API product"
RESPONSE=`curl -s -k -H "Content-Type: application/json" -H "Accept: application/json" $API_PRODUCT_DEFINITION_URL`
if [[ $RESPONSE == null ]]; #call failed
then
echo 'Failed call with error' $RESPONSE
#exit
else
echo 'Sucessfully retrieved API.'
fi
# ******************** Step 14. Create API Product ********************
nice_echo "Step 14. Create API Product"
CURL_BODY='{"type":"draft_product","draft_product":'${RESPONSE}'}'
RESPONSE=`curl -s -k -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer $TOKEN_RESPONSE" -d "$CURL_BODY" ${APIM_SERVER}/api/orgs/${pORG_NAME}/drafts/draft-products`
RESPONSE_URL=`echo "$RESPONSE" | jq -r '.url'`
if [[ $RESPONSE_URL == null ]]; #call failed
then
echo 'Failed call with error' $RESPONSE
#exit
else
echo 'Sucessfully created API product in Drafts ' $RESPONSE_URL
fi
# ******************** Step 15. Publish API Product ********************
nice_echo "Step 15. Publish API Product"
CURL_BODY='{"draft_product_url":"'"${RESPONSE_URL}"'"}'
RESPONSE=`curl -s -k -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer $TOKEN_RESPONSE" -d "$CURL_BODY" ${APIM_SERVER}/api/catalogs/${pORG_NAME}/sandbox/publish-draft-product`
RESPONSE_URL=`echo "$RESPONSE" | jq -r '.url'`
if [[ $RESPONSE_URL == null ]]; #call failed
then
echo 'Failed call with error' $RESPONSE
#exit
else
echo 'Sucessfully published API product in Drafts ' $RESPONSE_URL
fi
nice_echo "Script actions completed. Check logs for more details."