Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
c41de8f2
Unverified
Commit
c41de8f2
authored
Jan 15, 2022
by
neil
Committed by
GitHub
Jan 15, 2022
Browse files
Merge pull request #3891 from tutugreen/dev
dns_huaweicloud.sh minor bug fixes
parents
18827427
9d2ee212
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_huaweicloud.sh
View file @
c41de8f2
...
@@ -35,7 +35,7 @@ dns_huaweicloud_add() {
...
@@ -35,7 +35,7 @@ dns_huaweicloud_add() {
_err
"dns_api(dns_huaweicloud): Error getting token."
_err
"dns_api(dns_huaweicloud): Error getting token."
return
1
return
1
fi
fi
_debug
"Access token is:
${
token
}
"
_secure
_debug
"Access token is:
"
"
${
token
}
"
unset
zoneid
unset
zoneid
zoneid
=
"
$(
_get_zoneid
"
${
token
}
"
"
${
fulldomain
}
"
)
"
zoneid
=
"
$(
_get_zoneid
"
${
token
}
"
"
${
fulldomain
}
"
)
"
...
@@ -43,7 +43,7 @@ dns_huaweicloud_add() {
...
@@ -43,7 +43,7 @@ dns_huaweicloud_add() {
_err
"dns_api(dns_huaweicloud): Error getting zone id."
_err
"dns_api(dns_huaweicloud): Error getting zone id."
return
1
return
1
fi
fi
_debug
"Zone ID is:
${
zoneid
}
"
_debug
"Zone ID is:
"
"
${
zoneid
}
"
_debug
"Adding Record"
_debug
"Adding Record"
_add_record
"
${
token
}
"
"
${
fulldomain
}
"
"
${
txtvalue
}
"
_add_record
"
${
token
}
"
"
${
fulldomain
}
"
"
${
txtvalue
}
"
...
@@ -86,7 +86,7 @@ dns_huaweicloud_rm() {
...
@@ -86,7 +86,7 @@ dns_huaweicloud_rm() {
_err
"dns_api(dns_huaweicloud): Error getting token."
_err
"dns_api(dns_huaweicloud): Error getting token."
return
1
return
1
fi
fi
_debug
"Access token is:
${
token
}
"
_secure
_debug
"Access token is:
"
"
${
token
}
"
unset
zoneid
unset
zoneid
zoneid
=
"
$(
_get_zoneid
"
${
token
}
"
"
${
fulldomain
}
"
)
"
zoneid
=
"
$(
_get_zoneid
"
${
token
}
"
"
${
fulldomain
}
"
)
"
...
@@ -94,7 +94,7 @@ dns_huaweicloud_rm() {
...
@@ -94,7 +94,7 @@ dns_huaweicloud_rm() {
_err
"dns_api(dns_huaweicloud): Error getting zone id."
_err
"dns_api(dns_huaweicloud): Error getting zone id."
return
1
return
1
fi
fi
_debug
"Zone ID is:
${
zoneid
}
"
_debug
"Zone ID is:
"
"
${
zoneid
}
"
# 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
...
@@ -129,14 +129,25 @@ _get_zoneid() {
...
@@ -129,14 +129,25 @@ _get_zoneid() {
fi
fi
_debug
"
$h
"
_debug
"
$h
"
response
=
$(
_get
"
${
dns_api
}
/v2/zones?name=
${
h
}
"
)
response
=
$(
_get
"
${
dns_api
}
/v2/zones?name=
${
h
}
"
)
_debug2
"
$response
"
if
_contains
"
${
response
}
"
"id"
;
then
if
_contains
"
${
response
}
"
'"id"'
;
then
_debug
"Get Zone ID Success."
zoneidlist
=
$(
echo
"
${
response
}
"
| _egrep_o
"
\"
id
\"
: *
\"
[^
\"
]*
\"
"
|
cut
-d
:
-f
2 |
tr
-d
\"
|
tr
-d
" "
)
_zoneid
=
$(
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
" "
)
printf
"%s"
"
${
_zoneid
}
"
_debug2
"Return Zone ID(s):"
"
${
zoneidlist
}
"
return
0
_debug2
"Return Zone Name(s):"
"
${
zonenamelist
}
"
zoneidnum
=
0
echo
"
${
zonenamelist
}
"
|
while
read
-r
zonename
;
do
zoneidnum
=
$(
_math
"
$zoneidnum
"
+ 1
)
_debug
"Check Zone Name"
"
${
zonename
}
"
if
[
"
${
zonename
}
"
=
"
${
h
}
."
]
;
then
_debug
"Get Zone ID Success."
_zoneid
=
$(
echo
"
${
zoneidlist
}
"
|
sed
-n
"
${
zoneidnum
}
p"
)
_debug2
"ZoneID:"
"
${
_zoneid
}
"
printf
"%s"
"
${
_zoneid
}
"
return
0
fi
done
fi
fi
i
=
$(
_math
"
$i
"
+ 1
)
i
=
$(
_math
"
$i
"
+ 1
)
done
done
return
1
return
1
...
@@ -149,7 +160,7 @@ _get_recordset_id() {
...
@@ -149,7 +160,7 @@ _get_recordset_id() {
export
_H1
=
"X-Auth-Token:
${
_token
}
"
export
_H1
=
"X-Auth-Token:
${
_token
}
"
response
=
$(
_get
"
${
dns_api
}
/v2/zones/
${
_zoneid
}
/recordsets?name=
${
_domain
}
"
)
response
=
$(
_get
"
${
dns_api
}
/v2/zones/
${
_zoneid
}
/recordsets?name=
${
_domain
}
"
)
if
_contains
"
${
response
}
"
"id"
;
then
if
_contains
"
${
response
}
"
'
"id"
'
;
then
_id
=
"
$(
echo
"
${
response
}
"
| _egrep_o
"
\"
id
\"
: *
\"
[^
\"
]*
\"
"
|
cut
-d
:
-f
2 |
tr
-d
\"
|
tr
-d
" "
)
"
_id
=
"
$(
echo
"
${
response
}
"
| _egrep_o
"
\"
id
\"
: *
\"
[^
\"
]*
\"
"
|
cut
-d
:
-f
2 |
tr
-d
\"
|
tr
-d
" "
)
"
printf
"%s"
"
${
_id
}
"
printf
"%s"
"
${
_id
}
"
return
0
return
0
...
@@ -197,7 +208,7 @@ _add_record() {
...
@@ -197,7 +208,7 @@ _add_record() {
fi
fi
_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
# Remove all records
while
[
"
${
_record_id
}
"
!=
"0"
]
;
do
while
[
"
${
_record_id
}
"
!=
"0"
]
;
do
...
@@ -269,7 +280,7 @@ _get_token() {
...
@@ -269,7 +280,7 @@ _get_token() {
_post
"
${
body
}
"
"
${
iam_api
}
/v3/auth/tokens"
>
/dev/null
_post
"
${
body
}
"
"
${
iam_api
}
/v3/auth/tokens"
>
/dev/null
_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"
)
_token
=
$(
grep
"^X-Subject-Token"
"
$HTTP_HEADER
"
|
cut
-d
" "
-f
2-
)
_token
=
$(
grep
"^X-Subject-Token"
"
$HTTP_HEADER
"
|
cut
-d
" "
-f
2-
)
_debug
2
"
${
_code
}
"
_secure
_debug
"
${
_code
}
"
printf
"%s"
"
${
_token
}
"
printf
"%s"
"
${
_token
}
"
return
0
return
0
}
}
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