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
f6f6550b
Commit
f6f6550b
authored
Nov 23, 2020
by
Easton Man
Browse files
feat: add very tricky method to adapt to non-intuitive huaweicloud api
parent
e01fb503
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_huaweicloud.sh
View file @
f6f6550b
...
@@ -23,6 +23,11 @@ dns_huaweicloud_add() {
...
@@ -23,6 +23,11 @@ dns_huaweicloud_add() {
HUAWEICLOUD_Password
=
"
${
HUAWEICLOUD_Password
:-
$(
_readaccountconf_mutable HUAWEICLOUD_Password
)
}
"
HUAWEICLOUD_Password
=
"
${
HUAWEICLOUD_Password
:-
$(
_readaccountconf_mutable HUAWEICLOUD_Password
)
}
"
HUAWEICLOUD_ProjectID
=
"
${
HUAWEICLOUD_ProjectID
:-
$(
_readaccountconf_mutable HUAWEICLOUD_ProjectID
)
}
"
HUAWEICLOUD_ProjectID
=
"
${
HUAWEICLOUD_ProjectID
:-
$(
_readaccountconf_mutable HUAWEICLOUD_ProjectID
)
}
"
if
[
-z
"
${
HUAWEICLOUD_Username
}
"
]
||
[
-z
"
${
HUAWEICLOUD_Username
}
"
]
||
[
-z
"
${
HUAWEICLOUD_Username
}
"
]
;
then
_err
"Not enough info provided to dns_huaweicloud!"
return
1
fi
token
=
"
$(
_get_token
"
${
HUAWEICLOUD_Username
}
"
"
${
HUAWEICLOUD_Password
}
"
"
${
HUAWEICLOUD_ProjectID
}
"
)
"
token
=
"
$(
_get_token
"
${
HUAWEICLOUD_Username
}
"
"
${
HUAWEICLOUD_Password
}
"
"
${
HUAWEICLOUD_ProjectID
}
"
)
"
_debug2
"
${
token
}
"
_debug2
"
${
token
}
"
zoneid
=
"
$(
_get_zoneid
"
${
token
}
"
"
${
fulldomain
}
"
)
"
zoneid
=
"
$(
_get_zoneid
"
${
token
}
"
"
${
fulldomain
}
"
)
"
...
@@ -133,15 +138,36 @@ _add_record() {
...
@@ -133,15 +138,36 @@ _add_record() {
_token
=
$1
_token
=
$1
_domain
=
$2
_domain
=
$2
_txtvalue
=
$3
_txtvalue
=
$3
# Get Existing Records
export
_H1
=
"X-Auth-Token:
${
_token
}
"
response
=
$(
_get
"
${
dns_api
}
/v2/zones/
${
_zoneid
}
/recordsets?name=
${
_domain
}
"
)
_exist_record
=
$(
echo
"
${
response
}
"
|
sed
':a;N;$!ba;s/\n/ /g'
|
grep
-o
'"records":[^]]*'
|
sed
's/\"records\"\: \[//g'
)
_debug
"
${
_exist_record
}
"
# Check if record exist
# Generate body data
body
=
"{
body
=
"{
\"
name
\"
:
\"
${
_domain
}
.
\"
,
\"
name
\"
:
\"
${
_domain
}
.
\"
,
\"
description
\"
:
\"
ACME Challenge
\"
,
\"
description
\"
:
\"
ACME Challenge
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
ttl
\"
: 1,
\"
ttl
\"
: 1,
\"
records
\"
: [
\"
records
\"
: [
${
_exist_record
}
,
\"\\\"
${
_txtvalue
}
\\\"\"
\"\\\"
${
_txtvalue
}
\\\"\"
]
]
}"
}"
if
[
-z
"
${
_exist_record
}
"
]
;
then
body
=
"{
\"
name
\"
:
\"
${
_domain
}
.
\"
,
\"
description
\"
:
\"
ACME Challenge
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
ttl
\"
: 1,
\"
records
\"
: [
\"\\\"
${
_txtvalue
}
\\\"\"
]
}"
fi
_debug2
"
${
body
}
"
_debug2
"
${
body
}
"
export
_H2
=
"Content-Type: application/json"
export
_H2
=
"Content-Type: application/json"
export
_H1
=
"X-Auth-Token:
${
_token
}
"
export
_H1
=
"X-Auth-Token:
${
_token
}
"
...
...
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