Browse Source

remove unused code and fix error handling

martgras 7 years ago
parent
commit
d51c383866
1 changed files with 5 additions and 8 deletions
  1. 5 8
      dnsapi/dns_azure.sh

+ 5 - 8
dnsapi/dns_azure.sh

@@ -77,6 +77,7 @@ dns_azure_add()
         _info "validation record added"
         _info "validation record added"
    else
    else
         _err "error adding validation record ($_code)"
         _err "error adding validation record ($_code)"
+        return 1
    fi   
    fi   
 }
 }
 
 
@@ -149,6 +150,7 @@ dns_azure_rm()
         _info "validation record removed"
         _info "validation record removed"
     else
     else
         _err "error removing validation record ($_code)"
         _err "error removing validation record ($_code)"
+        return 1
     fi   
     fi   
 }
 }
 
 
@@ -160,15 +162,11 @@ _azure_rest() {
    data="$3"
    data="$3"
    accesstoken="$4"
    accesstoken="$4"
 
 
-   _debug "$ep"
-
    export _H1="authorization: Bearer $accesstoken"
    export _H1="authorization: Bearer $accesstoken"
    export _H2="accept: application/json"
    export _H2="accept: application/json"
    export _H3="Content-Type: application/json"
    export _H3="Content-Type: application/json"
-   _H1="authorization: Bearer $accesstoken"
-   _H2="accept: application/json"
-   _H3="Content-Type: application/json"
-
+   
+   _debug "$ep"
    if [ "$m" != "GET" ]; then
    if [ "$m" != "GET" ]; then
     _debug data "$data"
     _debug data "$data"
     response="$(_post "$data" "$ep" "" "$m")"
     response="$(_post "$data" "$ep" "" "$m")"
@@ -195,7 +193,6 @@ _azure_getaccess_token() {
 
 
    export _H1="accept: application/json"
    export _H1="accept: application/json"
    export _H2="Content-Type: application/x-www-form-urlencoded"
    export _H2="Content-Type: application/x-www-form-urlencoded"
-   export _H3=""
 
 
    body="resource=$(printf "%s" 'https://management.core.windows.net/'| _url_encode)&client_id=$(printf "%s" $clientID | _url_encode)&client_secret=$(printf "%s" $clientSecret| _url_encode)&grant_type=client_credentials"
    body="resource=$(printf "%s" 'https://management.core.windows.net/'| _url_encode)&client_id=$(printf "%s" $clientID | _url_encode)&client_secret=$(printf "%s" $clientSecret| _url_encode)&grant_type=client_credentials"
    _debug data "$body"
    _debug data "$body"
@@ -203,7 +200,7 @@ _azure_getaccess_token() {
    accesstoken=$(printf "%s\n" "$response" | _egrep_o "\"access_token\":\"[^\"]*\"" | head -n 1 | cut -d : -f 2 | tr -d \")
    accesstoken=$(printf "%s\n" "$response" | _egrep_o "\"access_token\":\"[^\"]*\"" | head -n 1 | cut -d : -f 2 | tr -d \")
    _debug2 "response $response"
    _debug2 "response $response"
    
    
-   if [ -Z "$accesstoken" ] ; then 
+   if [ -z "$accesstoken" ] ; then 
      _err "no acccess token received"
      _err "no acccess token received"
      return 1    
      return 1    
    fi
    fi