From 92dd11f46b20e4b0f5132fcaab0f713ee4261ac8 Mon Sep 17 00:00:00 2001 From: Alexey Belyaev Date: Sun, 17 Jul 2022 11:34:47 +0600 Subject: [PATCH] shfmt patch --- dnsapi/dns_fastvps.sh | 72 +++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/dnsapi/dns_fastvps.sh b/dnsapi/dns_fastvps.sh index 90adaccc..331ff0d7 100644 --- a/dnsapi/dns_fastvps.sh +++ b/dnsapi/dns_fastvps.sh @@ -18,46 +18,46 @@ FastVps_EndPoint="https://fastdns.fv.ee" dns_fastvps_add() { fulldomain=$1 txtvalue=$2 - + FastVps_Secret="${FastVps_Secret:-$(_readaccountconf_mutable FastVps_Secret)}" FastVps_Token="${FastVps_Token:-$(_readaccountconf_mutable FastVps_Token)}" - + if [ -z "$FastVps_Secret" ]; then FastVps_Secret="" _err "FastVps secret is not specified." _err "Please create secret https://bill2fast.com/dns and try again." return 1 fi - + #save the secret to the account conf file. _saveaccountconf_mutable FastVps_Secret "$FastVps_Secret" - + if [ -z "$FastVps_Token" ]; then _info "Getting FastVps token." if ! _fastvps_authentication; then _err "Can not get token." fi fi - + _debug "Detect root zone" if ! _get_root "$fulldomain"; then _err "Invalid domain." return 1 fi - + _debug _node "$_node" _debug _domain_name "$_domain_name" - + _info "Creating TXT record." if ! _fastvps_rest POST "api/domains/$dnsId/records" "{\"name\":\"$_node\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"ttl\":90}"; then return 1 fi - + if _contains "$response" "errors"; then _err "Could not add TXT record." return 1 fi - + return 0 } @@ -65,51 +65,51 @@ dns_fastvps_add() { dns_fastvps_rm() { fulldomain=$1 txtvalue=$2 - + FastVps_Secret="${FastVps_Secret:-$(_readaccountconf_mutable FastVps_Secret)}" FastVps_Token="${FastVps_Token:-$(_readaccountconf_mutable FastVps_Token)}" - + if [ -z "$FastVps_Secret" ]; then FastVps_Secret="" _err "Please create you API secret and try again." return 1 fi - + #save the secret to the account conf file. _saveaccountconf_mutable FastVps_Secret "$FastVps_Secret" - + if [ -z "$FastVps_Token" ]; then _info "Getting FastVps token." if ! _fastvps_authentication; then _err "Can not get token." fi fi - + _debug "Detect root zone." if ! _get_root "$fulldomain"; then _err "Invalid domain." return 1 fi - + _debug _node "$_node" _debug _domain_name "$_domain_name" - + _info "Checking for TXT record." if ! _get_recordid "$fulldomain" "$txtvalue"; then _err "Could not get TXT record id." return 1 fi - + if [ "$_dns_record_id" = "" ]; then _err "TXT record not found." return 1 fi - + _info "Removing TXT record." if ! _delete_txt_record "$_dns_record_id"; then _err "Could not remove TXT record $_dns_record_id." fi - + return 0 } @@ -129,11 +129,11 @@ _get_root() { #not valid return 1 fi - + if ! _fastvps_rest GET "api/domains/$h/name"; then return 1 fi - + if _contains "$response" "\"name\":\"$h\"" >/dev/null; then dnsId=$(printf "%s" "$response" | grep -Po '(?<="id":)[^,"\\]*(?:\\.[^"\\]*)*') _domain_name=$h @@ -144,37 +144,37 @@ _get_root() { i=$(_math "$i" + 1) done return 1 - + } _get_recordid() { fulldomain=$1 txtvalue=$2 - + if ! _fastvps_rest GET "api/domains/$dnsId/records"; then return 1 fi - + if ! _contains "$response" "$txtvalue"; then _dns_record_id=0 return 0 fi - + _dns_record_id=$(printf "%s" "$response" | sed -e 's/[^{]*\({[^}]*}\)[^{]*/\1\n/g' | grep "\"content\":\"$txtvalue\"" | sed -e 's/.*"id":"\([^",]*\).*/\1/') return 0 } _delete_txt_record() { _dns_record_id=$1 - + if ! _fastvps_rest DELETE "api/domains/$dnsId/records/$_dns_record_id"; then return 1 fi - + if _contains "$response" "errors"; then return 1 fi - + return 0 } @@ -183,10 +183,10 @@ _fastvps_rest() { ep="$2" data="$3" _debug "$ep" - + export _H1="Authorization: Bearer $FastVps_Token" export _H2="Content-Type: application/json" - + if [ "$data" ] || [ "$m" = "DELETE" ]; then _debug data "$data" response="$(_post "$data" "$FastVps_EndPoint/$ep" "" "$m")" @@ -194,7 +194,7 @@ _fastvps_rest() { _info "Getting $FastVps_EndPoint/$ep" response="$(_get "$FastVps_EndPoint/$ep")" fi - + # shellcheck disable=SC2181 if [ "$?" != "0" ]; then _err "error $ep" @@ -205,12 +205,12 @@ _fastvps_rest() { } _fastvps_authentication() { - + export _H1="Authenticate: $FastVps_Secret" export _H2="Content-Type: application/json" - + response="$(_post "" "$FastVps_EndPoint/login_token" "" "")" - + # shellcheck disable=SC2181 if [ "$?" != "0" ]; then _err "Authentication failed." @@ -223,7 +223,7 @@ _fastvps_authentication() { FastVps_Token="" fi _info "Authentication success" - + _debug2 response "$response" return 0 -} \ No newline at end of file +}