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
0717f859
Commit
0717f859
authored
Jul 17, 2022
by
Aleksandr Kunin
Browse files
Update to Vultr Api v2
- change endpoints - change Api-Key header to Authorization: Bearer
parent
1b59b0b7
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_vultr.sh
View file @
0717f859
...
...
@@ -3,10 +3,10 @@
#
#VULTR_API_KEY=000011112222333344445555666677778888
VULTR_Api
=
"https://api.vultr.com/v
1
"
VULTR_Api
=
"https://api.vultr.com/v
2
"
######## Public functions #####################
#
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_vultr_add
()
{
fulldomain
=
$1
...
...
@@ -31,14 +31,14 @@ dns_vultr_add() {
_debug _domain
"
$_domain
"
_debug
'Getting txt records'
_vultr_rest GET
"
dns/records?
domain
=
$_domain
"
_vultr_rest GET
"domain
s/
$_domain
/records
"
if
printf
"%s
\n
"
"
$response
"
|
grep
--
"
\"
type
\"
:
\"
TXT
\"
,
\"
name
\"
:
\"
$fulldomain
\"
"
>
/dev/null
;
then
_err
'Error'
return
1
fi
if
!
_vultr_rest POST
'dns/create_record'
"domain
=
$_domain
&name=
$_sub_domain
&
data
=
\"
$txtvalue
\"
&
type
=TXT
"
;
then
if
!
_vultr_rest POST
"domain
s/
$_domain
/records"
"{
\"
name
\"
:
\"
$_sub_domain
\"
,
\"
data
\"
:
\"
$txtvalue
\"
,
\"
type
\"
:
\"
TXT
\"
}
"
;
then
_err
"
$response
"
return
1
fi
...
...
@@ -71,14 +71,14 @@ dns_vultr_rm() {
_debug _domain
"
$_domain
"
_debug
'Getting txt records'
_vultr_rest GET
"
dns/records?
domain
=
$_domain
"
_vultr_rest GET
"domain
s/
$_domain
/records
"
if
printf
"%s
\n
"
"
$response
"
|
grep
--
"
\"
type
\"
:
\"
TXT
\"
,
\"
name
\"
:
\"
$fulldomain
\"
"
>
/dev/null
;
then
_err
'Error'
return
1
fi
_record_id
=
"
$(
echo
"
$response
"
|
tr
'{}'
'\n'
|
grep
'"TXT"'
|
grep
--
"
$txtvalue
"
|
tr
','
'\n'
|
grep
-i
'
RECORDID
'
|
cut
-d
:
-f
2
)
"
_record_id
=
"
$(
echo
"
$response
"
|
tr
'{}'
'\n'
|
grep
'"TXT"'
|
grep
--
"
$txtvalue
"
|
tr
','
'\n'
|
grep
-i
'
id
'
|
cut
-d
:
-f
2
)
"
_debug _record_id
"
$_record_id
"
if
[
"
$_record_id
"
]
;
then
_info
"Successfully retrieved the record id for ACME challenge."
...
...
@@ -87,7 +87,7 @@ dns_vultr_rm() {
return
0
fi
if
!
_vultr_rest
POST
'dns/delete_record'
"domain
=
$_domain
&RECORDID=
$_record_id
"
;
then
if
!
_vultr_rest
DELETE
"domain
s/
$_domain
/records/
$_record_id
"
;
then
_err
"
$response
"
return
1
fi
...
...
@@ -112,11 +112,11 @@ _get_root() {
return
1
fi
if
!
_vultr_rest GET
"d
ns/list
"
;
then
if
!
_vultr_rest GET
"d
omains
"
;
then
return
1
fi
if
printf
"%s
\n
"
"
$response
"
|
grep
'^\
[
.*\
]
'
>
/dev/null
;
then
if
printf
"%s
\n
"
"
$response
"
|
grep
'^\
{
.*\
}
'
>
/dev/null
;
then
if
_contains
"
$response
"
"
\"
domain
\"
:
\"
$_domain
\"
"
;
then
_sub_domain
=
"
$(
echo
"
$fulldomain
"
|
sed
"s/
\\
.
$_domain
\$
//"
)
"
return
0
...
...
@@ -141,8 +141,8 @@ _vultr_rest() {
api_key_trimmed
=
$(
echo
$VULTR_API_KEY
|
tr
-d
'"'
)
export
_H1
=
"A
pi-Key:
$api_key_trimmed
"
export
_H2
=
'Content-Type: application/
x-www-form-urlencoded
'
export
_H1
=
"A
uthorization: Bearer
$api_key_trimmed
"
export
_H2
=
'Content-Type: application/
json
'
if
[
"
$m
"
!=
"GET"
]
;
then
_debug data
"
$data
"
...
...
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