2424get_token () {
2525
2626 tokenFile=" $HOME /.blueXP_token"
27- tmpfile=$( mktemp -t get_token.XXXXXX)
28- trap ' rm -f "$tmpfile"' RETURN
2927
3028 if [ -z " $REFRESH_TOKEN " ]; then
3129 echo " Error: The REFRESH_TOKEN environment variable has not been set." >&2
@@ -55,14 +53,13 @@ get_token() {
5553 fi
5654
5755 if [ $createToken == " true" ]; then
58- curl -s -X POST ' https://netapp-cloud-account.auth0.com/oauth/token' \
56+ token= $( curl -s -X POST ' https://netapp-cloud-account.auth0.com/oauth/token' \
5957 -H ' Content-Type: application/json' \
6058 --data-raw ' {
6159 "grant_type": "refresh_token",
6260 "refresh_token": "' $REFRESH_TOKEN ' ",
6361 "client_id": "Mu0V1ywgYteI6w1MbD15fKfVIUrNXGWC"
64- }' > $tmpfile 2>&1
65- token=$( sed -ne ' s/."access_token":"\([^"]*\).*/\1/p' < $tmpfile )
62+ }' | sed -ne ' s/."access_token":"\([^"]*\).*/\1/p' )
6663
6764 if [ -z " $token " ]; then
6865 echo " Error: Unable to obtain a bearer token. Error message:" >&2
@@ -97,7 +94,13 @@ run_curl () {
9794 errorOutput=" $5 "
9895 data=" $6 "
9996 accept=" $7 "
100- shift 7
97+
98+ if [ -z " $accept " ]; then
99+ accept=" application/json, text/plain, */*"
100+ shift 6
101+ else
102+ shift 7
103+ fi
101104
102105 declare -a extraHeaders
103106 while [ $# -gt 0 ]; do
@@ -112,27 +115,27 @@ run_curl () {
112115 echo " Error: Missing required parameters for run_curl function." >&2
113116 exit 1
114117 fi
115- if [ -z " $accept " ] ; then
116- accept= " application/json, text/plain, */* "
117- fi
118+ #
119+ # Since older versions of curl don't support the %{stderr} variable, using the -o option
120+ # to redirect output to the $output file and getting the http_code from standard out.
118121 case " $method " in
119122 GET)
120- curl -sw " %{stderr}%{ http_code},%{errormsg}" " $url " \
123+ curl -sw " %{http_code},%{errormsg}" " $url " \
121124 -H " Accept: $accept " " ${extraHeaders[@]} " \
122- -H " Authorization: Bearer $token " > $output 2 > $errorOutput
125+ -H " Authorization: Bearer $token " -o $output > $errorOutput
123126 exitCode=$?
124127 ;;
125128 POST|PUT)
126- curl -X " $method " -sw " %{stderr}%{ http_code},%{errormsg}" " $url " \
129+ curl -X " $method " -sw " %{http_code},%{errormsg}" " $url " \
127130 -H " Accept: $accept " " ${extraHeaders[@]} " \
128131 -H " Content-Type:application/json" \
129- -H " Authorization: Bearer $token " --data " $data " > $output 2 > $errorOutput
132+ -H " Authorization: Bearer $token " --data " $data " -o $output > $errorOutput
130133 exitCode=$?
131134 ;;
132135 DELETE)
133- curl -X DELETE -sw " %{stderr}%{ http_code},%{errormsg}" " $url " \
136+ curl -X DELETE -sw " %{http_code},%{errormsg}" " $url " \
134137 -H " Accept: $accept " " ${extraHeaders[@]} " \
135- -H " Authorization: Bearer $token " > $output 2 > $errorOutput
138+ -H " Authorization: Bearer $token " -o $output > $errorOutput
136139 exitCode=$?
137140 ;;
138141 * )
0 commit comments