-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
New Alviy provider #5117
Open
alviy
wants to merge
20
commits into
acmesh-official:dev
Choose a base branch
from
alviy:master
base: dev
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New Alviy provider #5117
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ebaa39b
Merge pull request #5075 from acmesh-official/dev
Neilpang bc90376
Merge pull request #5102 from acmesh-official/dev
Neilpang f44dec2
add new provider - Alviy.com
alviy 78ba205
DNS test init
alviy 2fcda9a
Quotes recomendations
alviy 2e9f159
shfmt
alviy e1acea5
run DNS test
alviy d1df5f3
test DNS
alviy 4a8c225
4th+ level domain
alviy c0b87ad
shfmt
alviy 7ef1340
Update dns_alviy.sh
alviy 03b53cb
run DNS test
alviy 4bf4259
Update _get_root logic
alviy 1078fdc
fix Shellcheck
alviy e814ccc
Update dns_alviy.sh
alviy dbe7cb8
remove rev command
alviy dab244a
shfmt
alviy 54eec82
spellcheck
alviy d73953a
spellcheck
alviy aa41df4
run test
alviy File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
#!/usr/bin/env sh | ||
# Alviy domain api | ||
# | ||
# Get API key and secret from https://cloud.alviy.com/token | ||
# | ||
# Alviy_token="some-secret-key" | ||
# | ||
# Ex.: acme.sh --issue --staging --dns dns_alviy -d "*.s.example.com" -d "s.example.com" | ||
|
||
Alviy_Api="https://cloud.alviy.com/api/v1" | ||
|
||
######## Public functions ##################### | ||
|
||
#Usage: dns_alviy_add _acme-challenge.www.domain.com "content" | ||
dns_alviy_add() { | ||
fulldomain=$1 | ||
txtvalue=$2 | ||
|
||
Alviy_token="${Alviy_token:-$(_readaccountconf_mutable Alviy_token)}" | ||
if [ -z "$Alviy_token" ]; then | ||
Alviy_token="" | ||
_err "Please specify Alviy token." | ||
return 1 | ||
fi | ||
|
||
#save the api key and email to the account conf file. | ||
_saveaccountconf_mutable Alviy_token "$Alviy_token" | ||
|
||
_debug "First detect the root zone" | ||
if ! _get_root "$fulldomain"; then | ||
_err "invalid domain" | ||
return 1 | ||
fi | ||
|
||
_debug _sub_domain "$_sub_domain" | ||
_debug _domain "$_domain" | ||
|
||
_debug "Getting existing records" | ||
if _alviy_txt_exists "$_domain" "$fulldomain" "$txtvalue"; then | ||
_info "This record already exists, skipping" | ||
return 0 | ||
fi | ||
|
||
_add_data="{\"content\":\"$txtvalue\",\"type\":\"TXT\"}" | ||
_debug2 _add_data "$_add_data" | ||
_info "Adding record" | ||
if _alviy_rest POST "zone/$_domain/domain/$fulldomain/" "$_add_data"; then | ||
_debug "Checking updated records of '${fulldomain}'" | ||
|
||
if ! _alviy_txt_exists "$_domain" "$fulldomain" "$txtvalue"; then | ||
_err "TXT record '${txtvalue}' for '${fulldomain}', value wasn't set!" | ||
return 1 | ||
fi | ||
|
||
else | ||
_err "Add txt record error, value '${txtvalue}' for '${fulldomain}' was not set." | ||
return 1 | ||
fi | ||
|
||
_sleep 10 | ||
_info "Added TXT record '${txtvalue}' for '${fulldomain}'." | ||
return 0 | ||
} | ||
|
||
#fulldomain | ||
dns_alviy_rm() { | ||
fulldomain=$1 | ||
txtvalue=$2 | ||
|
||
Alviy_token="${Alviy_token:-$(_readaccountconf_mutable Alviy_token)}" | ||
|
||
_debug "First detect the root zone" | ||
if ! _get_root "$fulldomain"; then | ||
_err "invalid domain" | ||
return 1 | ||
fi | ||
|
||
_debug _sub_domain "$_sub_domain" | ||
_debug _domain "$_domain" | ||
|
||
if ! _alviy_txt_exists "$_domain" "$fulldomain" "$txtvalue"; then | ||
_info "The record does not exist, skip" | ||
return 0 | ||
fi | ||
|
||
_add_data="" | ||
uuid=$(echo "$response" | tr "{" "\n" | grep "$txtvalue" | tr "," "\n" | grep uuid | cut -d \" -f4) | ||
# delete record | ||
_debug "Delete TXT record for '${fulldomain}'" | ||
if ! _alviy_rest DELETE "zone/$_domain/record/$uuid" "{\"confirm\":1}"; then | ||
_err "Cannot delete empty TXT record for '$fulldomain'" | ||
return 1 | ||
fi | ||
_info "The record '$fulldomain'='$txtvalue' deleted" | ||
} | ||
|
||
#################### Private functions below ################################## | ||
#_acme-challenge.www.domain.com | ||
#returns | ||
# _sub_domain=_acme-challenge.www | ||
# _domain=domain.com | ||
_get_root() { | ||
domain=$1 | ||
i=3 | ||
a="init" | ||
while [ -n "$a" ]; do | ||
a=$(printf "%s" "$domain" | cut -d . -f $i-) | ||
i=$((i + 1)) | ||
done | ||
n=$((i - 3)) | ||
h=$(printf "%s" "$domain" | cut -d . -f $n-) | ||
if [ -z "$h" ]; then | ||
#not valid | ||
_alviy_rest GET "zone/$domain/" | ||
_debug "can't get host from $domain" | ||
return 1 | ||
fi | ||
|
||
if ! _alviy_rest GET "zone/$h/"; then | ||
return 1 | ||
fi | ||
|
||
if _contains "$response" '"code":"NOT_FOUND"'; then | ||
_debug "$h not found" | ||
else | ||
s=$((n - 1)) | ||
_sub_domain=$(printf "%s" "$domain" | cut -d . -f -$s) | ||
_domain="$h" | ||
return 0 | ||
fi | ||
return 1 | ||
} | ||
|
||
_alviy_txt_exists() { | ||
zone=$1 | ||
domain=$2 | ||
content_data=$3 | ||
_debug "Getting existing records" | ||
|
||
if ! _alviy_rest GET "zone/$zone/domain/$domain/TXT/"; then | ||
_info "The record does not exist" | ||
return 1 | ||
fi | ||
|
||
if ! _contains "$response" "$3"; then | ||
_info "The record has other value" | ||
return 1 | ||
fi | ||
# GOOD code return - TRUE function | ||
return 0 | ||
} | ||
|
||
_alviy_rest() { | ||
method=$1 | ||
path="$2" | ||
content_data="$3" | ||
_debug "$path" | ||
|
||
export _H1="Authorization: Bearer $Alviy_token" | ||
export _H2="Content-Type: application/json" | ||
|
||
if [ "$content_data" ] || [ "$method" = "DELETE" ]; then | ||
_debug "data ($method): " "$content_data" | ||
response="$(_post "$content_data" "$Alviy_Api/$path" "" "$method")" | ||
else | ||
response="$(_get "$Alviy_Api/$path")" | ||
fi | ||
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")" | ||
if [ "$_code" = "401" ]; then | ||
_err "It seems that your api key or secret is not correct." | ||
return 1 | ||
fi | ||
|
||
if [ "$_code" != "200" ]; then | ||
_err "API call error ($method): $path Response code $_code" | ||
fi | ||
if [ "$?" != "0" ]; then | ||
_err "error on rest call ($method): $path. Response:" | ||
_err "$response" | ||
return 1 | ||
fi | ||
_debug2 response "$response" | ||
return 0 | ||
} |
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.
why does i start from 3 ?
please start from 1