Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
cf3ff4c1
Unverified
Commit
cf3ff4c1
authored
Mar 13, 2023
by
neil
Committed by
GitHub
Mar 13, 2023
Browse files
Merge pull request #4551 from acmesh-official/dev
sync
parents
799e4020
7fe06adc
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_huaweicloud.sh
View file @
cf3ff4c1
...
@@ -23,7 +23,7 @@ dns_huaweicloud_add() {
...
@@ -23,7 +23,7 @@ dns_huaweicloud_add() {
HUAWEICLOUD_Username
=
"
${
HUAWEICLOUD_Username
:-
$(
_readaccountconf_mutable HUAWEICLOUD_Username
)
}
"
HUAWEICLOUD_Username
=
"
${
HUAWEICLOUD_Username
:-
$(
_readaccountconf_mutable HUAWEICLOUD_Username
)
}
"
HUAWEICLOUD_Password
=
"
${
HUAWEICLOUD_Password
:-
$(
_readaccountconf_mutable HUAWEICLOUD_Password
)
}
"
HUAWEICLOUD_Password
=
"
${
HUAWEICLOUD_Password
:-
$(
_readaccountconf_mutable HUAWEICLOUD_Password
)
}
"
HUAWEICLOUD_DomainName
=
"
${
HUAWEICLOUD_DomainName
:-
$(
_readaccountconf_mutable HUAWEICLOUD_
Usern
ame
)
}
"
HUAWEICLOUD_DomainName
=
"
${
HUAWEICLOUD_DomainName
:-
$(
_readaccountconf_mutable HUAWEICLOUD_
DomainN
ame
)
}
"
# Check information
# Check information
if
[
-z
"
${
HUAWEICLOUD_Username
}
"
]
||
[
-z
"
${
HUAWEICLOUD_Password
}
"
]
||
[
-z
"
${
HUAWEICLOUD_DomainName
}
"
]
;
then
if
[
-z
"
${
HUAWEICLOUD_Username
}
"
]
||
[
-z
"
${
HUAWEICLOUD_Password
}
"
]
||
[
-z
"
${
HUAWEICLOUD_DomainName
}
"
]
;
then
...
@@ -74,7 +74,7 @@ dns_huaweicloud_rm() {
...
@@ -74,7 +74,7 @@ dns_huaweicloud_rm() {
HUAWEICLOUD_Username
=
"
${
HUAWEICLOUD_Username
:-
$(
_readaccountconf_mutable HUAWEICLOUD_Username
)
}
"
HUAWEICLOUD_Username
=
"
${
HUAWEICLOUD_Username
:-
$(
_readaccountconf_mutable HUAWEICLOUD_Username
)
}
"
HUAWEICLOUD_Password
=
"
${
HUAWEICLOUD_Password
:-
$(
_readaccountconf_mutable HUAWEICLOUD_Password
)
}
"
HUAWEICLOUD_Password
=
"
${
HUAWEICLOUD_Password
:-
$(
_readaccountconf_mutable HUAWEICLOUD_Password
)
}
"
HUAWEICLOUD_DomainName
=
"
${
HUAWEICLOUD_DomainName
:-
$(
_readaccountconf_mutable HUAWEICLOUD_
Usern
ame
)
}
"
HUAWEICLOUD_DomainName
=
"
${
HUAWEICLOUD_DomainName
:-
$(
_readaccountconf_mutable HUAWEICLOUD_
DomainN
ame
)
}
"
# Check information
# Check information
if
[
-z
"
${
HUAWEICLOUD_Username
}
"
]
||
[
-z
"
${
HUAWEICLOUD_Password
}
"
]
||
[
-z
"
${
HUAWEICLOUD_DomainName
}
"
]
;
then
if
[
-z
"
${
HUAWEICLOUD_Username
}
"
]
||
[
-z
"
${
HUAWEICLOUD_Password
}
"
]
||
[
-z
"
${
HUAWEICLOUD_DomainName
}
"
]
;
then
...
@@ -98,19 +98,59 @@ dns_huaweicloud_rm() {
...
@@ -98,19 +98,59 @@ dns_huaweicloud_rm() {
fi
fi
_debug
"Zone ID is:"
"
${
zoneid
}
"
_debug
"Zone ID is:"
"
${
zoneid
}
"
record_id
=
"
$(
_get_recordset_id
"
${
token
}
"
"
${
fulldomain
}
"
"
${
zoneid
}
"
)
"
_recursive_rm_record
"
${
token
}
"
"
${
fulldomain
}
"
"
${
zoneid
}
"
"
${
record_id
}
"
ret
=
"
$?
"
if
[
"
${
ret
}
"
!=
"0"
]
;
then
_err
"dns_api(dns_huaweicloud): Error removing record."
return
1
fi
return
0
}
################### Private functions below ##################################
# _recursive_rm_record
# remove all records from the record set
#
# _token=$1
# _domain=$2
# _zoneid=$3
# _record_id=$4
#
# Returns 0 on success
_recursive_rm_record
()
{
_token
=
$1
_domain
=
$2
_zoneid
=
$3
_record_id
=
$4
# Most likely to have problems will huaweicloud side if more than 50 attempts but still cannot fully remove the record set
# Maybe can be removed manually in the dashboard
_retry_cnt
=
50
# Remove all records
# Remove all records
# Therotically HuaweiCloud does not allow more than one record set
# Therotically HuaweiCloud does not allow more than one record set
# But remove them recurringly to increase robusty
# But remove them recurringly to increase robusty
while
[
"
${
record_id
}
"
!=
"0"
]
;
do
while
[
"
${
_record_id
}
"
!=
"0"
]
&&
[
"
${
_retry_cnt
}
"
!=
"0"
]
;
do
_debug
"Removing Record"
_debug
"Removing Record"
_rm_record
"
${
token
}
"
"
${
zoneid
}
"
"
${
record_id
}
"
_retry_cnt
=
$((
_retry_cnt
-
1
))
record_id
=
"
$(
_get_recordset_id
"
${
token
}
"
"
${
fulldomain
}
"
"
${
zoneid
}
"
)
"
_rm_record
"
${
_token
}
"
"
${
_zoneid
}
"
"
${
_record_id
}
"
_record_id
=
"
$(
_get_recordset_id
"
${
_token
}
"
"
${
_domain
}
"
"
${
_zoneid
}
"
)
"
_debug2
"Checking record exists: record_id=
${
_record_id
}
"
done
done
# Check if retry count is reached
if
[
"
${
_retry_cnt
}
"
=
"0"
]
;
then
_debug
"Failed to remove record after 50 attempts, please try removing it manually in the dashboard"
return
1
fi
return
0
return
0
}
}
################### Private functions below ##################################
# _get_zoneid
# _get_zoneid
#
#
# _token=$1
# _token=$1
...
@@ -124,7 +164,7 @@ _get_zoneid() {
...
@@ -124,7 +164,7 @@ _get_zoneid() {
i
=
1
i
=
1
while
true
;
do
while
true
;
do
h
=
$(
printf
"%s"
"
${
_domain_string
}
"
|
cut
-d
.
-f
$i
-100
)
h
=
$(
printf
"%s"
"
${
_domain_string
}
"
|
cut
-d
.
-f
"
$i
"
-100
)
if
[
-z
"
$h
"
]
;
then
if
[
-z
"
$h
"
]
;
then
#not valid
#not valid
return
1
return
1
...
@@ -135,11 +175,11 @@ _get_zoneid() {
...
@@ -135,11 +175,11 @@ _get_zoneid() {
if
_contains
"
${
response
}
"
'"id"'
;
then
if
_contains
"
${
response
}
"
'"id"'
;
then
zoneidlist
=
$(
echo
"
${
response
}
"
| _egrep_o
"
\"
id
\"
: *
\"
[^
\"
]*
\"
"
|
cut
-d
:
-f
2 |
tr
-d
\"
|
tr
-d
" "
)
zoneidlist
=
$(
echo
"
${
response
}
"
| _egrep_o
"
\"
id
\"
: *
\"
[^
\"
]*
\"
"
|
cut
-d
:
-f
2 |
tr
-d
\"
|
tr
-d
" "
)
zonenamelist
=
$(
echo
"
${
response
}
"
| _egrep_o
"
\"
name
\"
: *
\"
[^
\"
]*
\"
"
|
cut
-d
:
-f
2 |
tr
-d
\"
|
tr
-d
" "
)
zonenamelist
=
$(
echo
"
${
response
}
"
| _egrep_o
"
\"
name
\"
: *
\"
[^
\"
]*
\"
"
|
cut
-d
:
-f
2 |
tr
-d
\"
|
tr
-d
" "
)
_debug2
"Return Zone ID(s):"
"
${
zoneidlist
}
"
_debug2
"Return
ed
Zone ID(s):"
"
${
zoneidlist
}
"
_debug2
"Return Zone Name(s):"
"
${
zonenamelist
}
"
_debug2
"Return
ed
Zone Name(s):"
"
${
zonenamelist
}
"
zoneidnum
=
0
zoneidnum
=
0
zoneidcount
=
$(
echo
"
${
zoneidlist
}
"
|
grep
-c
'^'
)
zoneidcount
=
$(
echo
"
${
zoneidlist
}
"
|
grep
-c
'^'
)
_debug
"Retu
n
d Zone ID(s) Count:"
"
${
zoneidcount
}
"
_debug
"Retu
rne
d Zone ID(s) Count:"
"
${
zoneidcount
}
"
while
[
"
${
zoneidnum
}
"
-lt
"
${
zoneidcount
}
"
]
;
do
while
[
"
${
zoneidnum
}
"
-lt
"
${
zoneidcount
}
"
]
;
do
zoneidnum
=
$(
_math
"
$zoneidnum
"
+ 1
)
zoneidnum
=
$(
_math
"
$zoneidnum
"
+ 1
)
_zoneid
=
$(
echo
"
${
zoneidlist
}
"
|
sed
-n
"
${
zoneidnum
}
p"
)
_zoneid
=
$(
echo
"
${
zoneidlist
}
"
|
sed
-n
"
${
zoneidnum
}
p"
)
...
@@ -206,8 +246,7 @@ _add_record() {
...
@@ -206,8 +246,7 @@ _add_record() {
\"
type
\"
:
\"
TXT
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
ttl
\"
: 1,
\"
ttl
\"
: 1,
\"
records
\"
: [
\"
records
\"
: [
${
_exist_record
}
,
${
_exist_record
}
,
\"\\\"
${
_txtvalue
}
\\\"\"
\"\\\"
${
_txtvalue
}
\\\"\"
]
]
}"
}"
fi
fi
...
@@ -215,19 +254,16 @@ _add_record() {
...
@@ -215,19 +254,16 @@ _add_record() {
_record_id
=
"
$(
_get_recordset_id
"
${
_token
}
"
"
${
_domain
}
"
"
${
zoneid
}
"
)
"
_record_id
=
"
$(
_get_recordset_id
"
${
_token
}
"
"
${
_domain
}
"
"
${
zoneid
}
"
)
"
_debug
"Record Set ID is:"
"
${
_record_id
}
"
_debug
"Record Set ID is:"
"
${
_record_id
}
"
# Remove all records
while
[
"
${
_record_id
}
"
!=
"0"
]
;
do
_debug
"Removing Record"
_rm_record
"
${
_token
}
"
"
${
zoneid
}
"
"
${
_record_id
}
"
_record_id
=
"
$(
_get_recordset_id
"
${
_token
}
"
"
${
_domain
}
"
"
${
zoneid
}
"
)
"
done
# Add brand new records with all old and new records
# Add brand new records with all old and new records
export
_H2
=
"Content-Type: application/json"
export
_H2
=
"Content-Type: application/json"
export
_H1
=
"X-Auth-Token:
${
_token
}
"
export
_H1
=
"X-Auth-Token:
${
_token
}
"
_debug2
"
${
_post_body
}
"
_debug2
"
${
_post_body
}
"
_post
"
${
_post_body
}
"
"
${
dns_api
}
/v2/zones/
${
zoneid
}
/recordsets"
>
/dev/null
if
[
-z
"
${
_exist_record
}
"
]
;
then
_post
"
${
_post_body
}
"
"
${
dns_api
}
/v2/zones/
${
zoneid
}
/recordsets"
>
/dev/null
else
_post
"
${
_post_body
}
"
"
${
dns_api
}
/v2/zones/
${
zoneid
}
/recordsets/
${
_record_id
}
"
false
"PUT"
>
/dev/null
fi
_code
=
"
$(
grep
"^HTTP"
"
$HTTP_HEADER
"
| _tail_n 1 |
cut
-d
" "
-f
2 |
tr
-d
"
\\
r
\\
n"
)
"
_code
=
"
$(
grep
"^HTTP"
"
$HTTP_HEADER
"
| _tail_n 1 |
cut
-d
" "
-f
2 |
tr
-d
"
\\
r
\\
n"
)
"
if
[
"
$_code
"
!=
"202"
]
;
then
if
[
"
$_code
"
!=
"202"
]
;
then
_err
"dns_huaweicloud: http code
${
_code
}
"
_err
"dns_huaweicloud: http code
${
_code
}
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment