-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Alibaba Cloud API #5294
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fca6e9b
refactor: Alibaba Cloud API
PMExtra 610bb2b
refactor(ali): set API endpoint for each action
PMExtra ea2330b
refactor(ali): move the loading script into ali_cdn_deploy
PMExtra 2ea37e6
refactor(ali): check the result of prepare_ali_credentials
PMExtra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,25 +9,19 @@ Options: | |
Ali_Secret API Secret | ||
' | ||
|
||
Ali_API="https://alidns.aliyuncs.com/" | ||
# NOTICE: | ||
# This file is referenced by Alibaba Cloud Services deploy hooks | ||
# https://github.com/acmesh-official/acme.sh/pull/5205#issuecomment-2357867276 | ||
# Be careful when modifying this file, especially when making breaking changes for common functions | ||
|
||
Ali_DNS_API="https://alidns.aliyuncs.com/" | ||
|
||
#Usage: dns_ali_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" | ||
dns_ali_add() { | ||
fulldomain=$1 | ||
txtvalue=$2 | ||
|
||
Ali_Key="${Ali_Key:-$(_readaccountconf_mutable Ali_Key)}" | ||
Ali_Secret="${Ali_Secret:-$(_readaccountconf_mutable Ali_Secret)}" | ||
if [ -z "$Ali_Key" ] || [ -z "$Ali_Secret" ]; then | ||
Ali_Key="" | ||
Ali_Secret="" | ||
_err "You don't specify aliyun api key and secret yet." | ||
return 1 | ||
fi | ||
|
||
#save the api key and secret to the account conf file. | ||
_saveaccountconf_mutable Ali_Key "$Ali_Key" | ||
_saveaccountconf_mutable Ali_Secret "$Ali_Secret" | ||
_prepare_ali_credentials | ||
|
||
_debug "First detect the root zone" | ||
if ! _get_root "$fulldomain"; then | ||
|
@@ -52,7 +46,67 @@ dns_ali_rm() { | |
_clean | ||
} | ||
|
||
#################### Private functions below ################################## | ||
#################### Alibaba Cloud common functions below #################### | ||
|
||
_prepare_ali_credentials() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个函数的所有调用地方, 都没有判返回值. 如果出错了,没法中止 |
||
Ali_Key="${Ali_Key:-$(_readaccountconf_mutable Ali_Key)}" | ||
Ali_Secret="${Ali_Secret:-$(_readaccountconf_mutable Ali_Secret)}" | ||
if [ -z "$Ali_Key" ] || [ -z "$Ali_Secret" ]; then | ||
Ali_Key="" | ||
Ali_Secret="" | ||
_err "You don't specify aliyun api key and secret yet." | ||
return 1 | ||
fi | ||
|
||
#save the api key and secret to the account conf file. | ||
_saveaccountconf_mutable Ali_Key "$Ali_Key" | ||
_saveaccountconf_mutable Ali_Secret "$Ali_Secret" | ||
} | ||
|
||
# act ign mtd | ||
_ali_rest() { | ||
act="$1" | ||
ign="$2" | ||
mtd="${3:-GET}" | ||
|
||
signature=$(printf "%s" "$mtd&%2F&$(printf "%s" "$query" | _url_encode upper-hex)" | _hmac "sha1" "$(printf "%s" "$Ali_Secret&" | _hex_dump | tr -d " ")" | _base64) | ||
signature=$(printf "%s" "$signature" | _url_encode upper-hex) | ||
url="$endpoint?Signature=$signature" | ||
|
||
if [ "$mtd" = "GET" ]; then | ||
url="$url&$query" | ||
response="$(_get "$url")" | ||
else | ||
response="$(_post "$query" "$url" "" "$mtd" "application/x-www-form-urlencoded")" | ||
fi | ||
|
||
_ret="$?" | ||
_debug2 response "$response" | ||
if [ "$_ret" != "0" ]; then | ||
_err "Error <$act>" | ||
return 1 | ||
fi | ||
|
||
if [ -z "$ign" ]; then | ||
message="$(echo "$response" | _egrep_o "\"Message\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")" | ||
if [ "$message" ]; then | ||
_err "$message" | ||
return 1 | ||
fi | ||
fi | ||
} | ||
|
||
_ali_nonce() { | ||
#_head_n 1 </dev/urandom | _digest "sha256" hex | cut -c 1-31 | ||
#Not so good... | ||
date +"%s%N" | sed 's/%N//g' | ||
} | ||
|
||
_timestamp() { | ||
date -u +"%Y-%m-%dT%H%%3A%M%%3A%SZ" | ||
} | ||
|
||
#################### Private functions below #################### | ||
|
||
_get_root() { | ||
domain=$1 | ||
|
@@ -83,52 +137,10 @@ _get_root() { | |
return 1 | ||
} | ||
|
||
_ali_rest() { | ||
signature=$(printf "%s" "GET&%2F&$(_ali_urlencode "$query")" | _hmac "sha1" "$(printf "%s" "$Ali_Secret&" | _hex_dump | tr -d " ")" | _base64) | ||
signature=$(_ali_urlencode "$signature") | ||
url="$Ali_API?$query&Signature=$signature" | ||
|
||
if ! response="$(_get "$url")"; then | ||
_err "Error <$1>" | ||
return 1 | ||
fi | ||
|
||
_debug2 response "$response" | ||
if [ -z "$2" ]; then | ||
message="$(echo "$response" | _egrep_o "\"Message\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")" | ||
if [ "$message" ]; then | ||
_err "$message" | ||
return 1 | ||
fi | ||
fi | ||
} | ||
|
||
_ali_urlencode() { | ||
_str="$1" | ||
_str_len=${#_str} | ||
_u_i=1 | ||
while [ "$_u_i" -le "$_str_len" ]; do | ||
_str_c="$(printf "%s" "$_str" | cut -c "$_u_i")" | ||
case $_str_c in [a-zA-Z0-9.~_-]) | ||
printf "%s" "$_str_c" | ||
;; | ||
*) | ||
printf "%%%02X" "'$_str_c" | ||
;; | ||
esac | ||
_u_i="$(_math "$_u_i" + 1)" | ||
done | ||
} | ||
|
||
_ali_nonce() { | ||
#_head_n 1 </dev/urandom | _digest "sha256" hex | cut -c 1-31 | ||
#Not so good... | ||
date +"%s%N" | sed 's/%N//g' | ||
} | ||
|
||
_check_exist_query() { | ||
_qdomain="$1" | ||
_qsubdomain="$2" | ||
endpoint=$Ali_DNS_API | ||
query='' | ||
query=$query'AccessKeyId='$Ali_Key | ||
query=$query'&Action=DescribeDomainRecords' | ||
|
@@ -144,6 +156,7 @@ _check_exist_query() { | |
} | ||
|
||
_add_record_query() { | ||
endpoint=$Ali_DNS_API | ||
query='' | ||
query=$query'AccessKeyId='$Ali_Key | ||
query=$query'&Action=AddDomainRecord' | ||
|
@@ -160,6 +173,7 @@ _add_record_query() { | |
} | ||
|
||
_delete_record_query() { | ||
endpoint=$Ali_DNS_API | ||
query='' | ||
query=$query'AccessKeyId='$Ali_Key | ||
query=$query'&Action=DeleteDomainRecord' | ||
|
@@ -173,6 +187,7 @@ _delete_record_query() { | |
} | ||
|
||
_describe_records_query() { | ||
endpoint=$Ali_DNS_API | ||
query='' | ||
query=$query'AccessKeyId='$Ali_Key | ||
query=$query'&Action=DescribeDomainRecords' | ||
|
@@ -203,7 +218,3 @@ _clean() { | |
fi | ||
|
||
} | ||
|
||
_timestamp() { | ||
date -u +"%Y-%m-%dT%H%%3A%M%%3A%SZ" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把这段加载代码放到 ali_cdn_deploy 函数里面去, 这样 _findHook 第一个参数可以传 "$_cdomain"