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
952e2819
Unverified
Commit
952e2819
authored
Feb 11, 2019
by
neil
Committed by
GitHub
Feb 11, 2019
Browse files
Merge pull request #2077 from hosting-de/fix/better-parsing-of-responses
hosting.de: better parsing of json responses
parents
e8c91e6e
1fa026b9
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_hostingde.sh
View file @
952e2819
...
@@ -13,6 +13,7 @@ dns_hostingde_add() {
...
@@ -13,6 +13,7 @@ dns_hostingde_add() {
txtvalue
=
"
${
2
}
"
txtvalue
=
"
${
2
}
"
_debug
"Calling: _hostingde_addRecord() '
${
fulldomain
}
' '
${
txtvalue
}
'"
_debug
"Calling: _hostingde_addRecord() '
${
fulldomain
}
' '
${
txtvalue
}
'"
_hostingde_apiKey
&&
_hostingde_getZoneConfig
&&
_hostingde_addRecord
_hostingde_apiKey
&&
_hostingde_getZoneConfig
&&
_hostingde_addRecord
return
$?
}
}
dns_hostingde_rm
()
{
dns_hostingde_rm
()
{
...
@@ -20,6 +21,7 @@ dns_hostingde_rm() {
...
@@ -20,6 +21,7 @@ dns_hostingde_rm() {
txtvalue
=
"
${
2
}
"
txtvalue
=
"
${
2
}
"
_debug
"Calling: _hostingde_removeRecord() '
${
fulldomain
}
' '
${
txtvalue
}
'"
_debug
"Calling: _hostingde_removeRecord() '
${
fulldomain
}
' '
${
txtvalue
}
'"
_hostingde_apiKey
&&
_hostingde_getZoneConfig
&&
_hostingde_removeRecord
_hostingde_apiKey
&&
_hostingde_getZoneConfig
&&
_hostingde_removeRecord
return
$?
}
}
#################### own Private functions below ##################################
#################### own Private functions below ##################################
...
@@ -38,6 +40,18 @@ _hostingde_apiKey() {
...
@@ -38,6 +40,18 @@ _hostingde_apiKey() {
_saveaccountconf_mutable HOSTINGDE_ENDPOINT
"
$HOSTINGDE_ENDPOINT
"
_saveaccountconf_mutable HOSTINGDE_ENDPOINT
"
$HOSTINGDE_ENDPOINT
"
}
}
_hostingde_parse
()
{
find
=
"
${
1
}
"
if
[
"
${
2
}
"
]
;
then
notfind
=
"
${
2
}
"
fi
if
[
"
${
notfind
}
"
]
;
then
_egrep_o
\"
"
${
find
}
\"
:.*"
|
grep
-v
"
${
notfind
}
"
|
cut
-d
':'
-f
2 |
cut
-d
','
-f
1 |
tr
-d
' '
else
_egrep_o
\"
"
${
find
}
\"
:.*"
|
cut
-d
':'
-f
2 |
cut
-d
','
-f
1 |
tr
-d
' '
fi
}
_hostingde_getZoneConfig
()
{
_hostingde_getZoneConfig
()
{
_info
"Getting ZoneConfig"
_info
"Getting ZoneConfig"
curZone
=
"
${
fulldomain
#*.
}
"
curZone
=
"
${
fulldomain
#*.
}
"
...
@@ -59,18 +73,18 @@ _hostingde_getZoneConfig() {
...
@@ -59,18 +73,18 @@ _hostingde_getZoneConfig() {
if
_contains
"
${
curResult
}
"
'"totalEntries": 1'
;
then
if
_contains
"
${
curResult
}
"
'"totalEntries": 1'
;
then
_info
"Retrieved zone data."
_info
"Retrieved zone data."
_debug
"Zone data: '
${
curResult
}
'"
_debug
"Zone data: '
${
curResult
}
'"
zoneConfigId
=
$(
echo
"
${
curResult
}
"
| _
egrep_o
'"id":.*'
|
cut
-d
':'
-f
2 |
cut
-d
'"'
-f
2
)
zoneConfigId
=
$(
echo
"
${
curResult
}
"
| _
hostingde_parse
"id"
)
zoneConfigName
=
$(
echo
"
${
curResult
}
"
| _
egrep_o
'"name":.*'
|
cut
-d
':'
-f
2 |
cut
-d
'"'
-f
2
)
zoneConfigName
=
$(
echo
"
${
curResult
}
"
| _
hostingde_parse
"name"
)
zoneConfigType
=
$(
echo
"
${
curResult
}
"
|
grep
-v
"FindZoneConfigsResult"
| _egrep_o
'"type":.*'
|
cut
-d
':'
-f
2 |
cut
-d
'"'
-f
2
)
zoneConfigType
=
$(
echo
"
${
curResult
}
"
|
_hostingde_parse
"type"
"FindZoneConfigsResult"
)
zoneConfigExpire
=
$(
echo
"
${
curResult
}
"
| _
egrep_o
'"expire":.*'
|
cut
-d
':'
-f
2 |
cut
-d
'"'
-f
2 |
cut
-d
','
-f
1
)
zoneConfigExpire
=
$(
echo
"
${
curResult
}
"
| _
hostingde_parse
"expire"
)
zoneConfigNegativeTtl
=
$(
echo
"
${
curResult
}
"
| _
egrep_o
'"negativeTtl":.*'
|
cut
-d
':'
-f
2 |
cut
-d
'"'
-f
2 |
cut
-d
','
-f
1
)
zoneConfigNegativeTtl
=
$(
echo
"
${
curResult
}
"
| _
hostingde_parse
"negativeTtl"
)
zoneConfigRefresh
=
$(
echo
"
${
curResult
}
"
| _
egrep_o
'"refresh":.*'
|
cut
-d
':'
-f
2 |
cut
-d
'"'
-f
2 |
cut
-d
','
-f
1
)
zoneConfigRefresh
=
$(
echo
"
${
curResult
}
"
| _
hostingde_parse
"refresh"
)
zoneConfigRetry
=
$(
echo
"
${
curResult
}
"
| _
egrep_o
'"retry":.*'
|
cut
-d
':'
-f
2 |
cut
-d
'"'
-f
2 |
cut
-d
','
-f
1
)
zoneConfigRetry
=
$(
echo
"
${
curResult
}
"
| _
hostingde_parse
"retry"
)
zoneConfigTtl
=
$(
echo
"
${
curResult
}
"
| _
egrep_o
'"ttl":.*'
|
cut
-d
':'
-f
2 |
cut
-d
'"'
-f
2 |
cut
-d
','
-f
1
)
zoneConfigTtl
=
$(
echo
"
${
curResult
}
"
| _
hostingde_parse
"ttl"
)
zoneConfigDnsServerGroupId
=
$(
echo
"
${
curResult
}
"
| _
egrep_o
'
"dnsServerGroupId"
:.*'
|
cut
-d
':'
-f
2 |
cut
-d
'"'
-f
2
)
zoneConfigDnsServerGroupId
=
$(
echo
"
${
curResult
}
"
| _
hostingde_parse
"dnsServerGroupId"
)
zoneConfigEmailAddress
=
$(
echo
"
${
curResult
}
"
| _
egrep_o
'"emailAddress":.*'
|
cut
-d
':'
-f
2 |
cut
-d
'"'
-f
2
)
zoneConfigEmailAddress
=
$(
echo
"
${
curResult
}
"
| _
hostingde_parse
"emailAddress"
)
zoneConfigDnsSecMode
=
$(
echo
"
${
curResult
}
"
| _
egrep_o
'"dnsSecMode":.*'
|
cut
-d
':'
-f
2 |
cut
-d
'"'
-f
2
)
zoneConfigDnsSecMode
=
$(
echo
"
${
curResult
}
"
| _
hostingde_parse
"dnsSecMode"
)
if
[
"
${
zoneConfigType
}
"
!=
"NATIVE"
]
;
then
if
[
"
${
zoneConfigType
}
"
!=
"
\
"
NATIVE
\"
"
]
;
then
_err
"Zone is not native"
_err
"Zone is not native"
returnCode
=
1
returnCode
=
1
break
break
...
@@ -89,11 +103,11 @@ _hostingde_getZoneConfig() {
...
@@ -89,11 +103,11 @@ _hostingde_getZoneConfig() {
_hostingde_getZoneStatus
()
{
_hostingde_getZoneStatus
()
{
_debug
"Checking Zone status"
_debug
"Checking Zone status"
curData
=
"{
\"
filter
\"
:{
\"
field
\"
:
\"
zoneConfigId
\"
,
\"
value
\"
:
\"
${
zoneConfigId
}
\"
},
\"
limit
\"
:1,
\"
authToken
\"
:
\"
${
HOSTINGDE_APIKEY
}
\"
}"
curData
=
"{
\"
filter
\"
:{
\"
field
\"
:
\"
zoneConfigId
\"
,
\"
value
\"
:
${
zoneConfigId
}
},
\"
limit
\"
:1,
\"
authToken
\"
:
\"
${
HOSTINGDE_APIKEY
}
\"
}"
curResult
=
"
$(
_post
"
${
curData
}
"
"
${
HOSTINGDE_ENDPOINT
}
/api/dns/v1/json/zonesFind"
)
"
curResult
=
"
$(
_post
"
${
curData
}
"
"
${
HOSTINGDE_ENDPOINT
}
/api/dns/v1/json/zonesFind"
)
"
_debug
"Calling zonesFind '
${
curData
}
' '
${
HOSTINGDE_ENDPOINT
}
/api/dns/v1/json/zonesFind'"
_debug
"Calling zonesFind '
${
curData
}
' '
${
HOSTINGDE_ENDPOINT
}
/api/dns/v1/json/zonesFind'"
_debug
"Result of zonesFind '
$curResult
'"
_debug
"Result of zonesFind '
$curResult
'"
zoneStatus
=
$(
echo
"
${
curResult
}
"
|
grep
-v
success | _egrep_o
'"status":.*'
|
cut
-d
':'
-f
2 |
cut
-d
'"'
-f
2
)
zoneStatus
=
$(
echo
"
${
curResult
}
"
|
_hostingde_parse
"status"
"success"
)
_debug
"zoneStatus '
${
zoneStatus
}
'"
_debug
"zoneStatus '
${
zoneStatus
}
'"
return
0
return
0
}
}
...
@@ -102,12 +116,12 @@ _hostingde_addRecord() {
...
@@ -102,12 +116,12 @@ _hostingde_addRecord() {
_info
"Adding record to zone"
_info
"Adding record to zone"
_hostingde_getZoneStatus
_hostingde_getZoneStatus
_debug
"Result of zoneStatus: '
${
zoneStatus
}
'"
_debug
"Result of zoneStatus: '
${
zoneStatus
}
'"
while
[
"
${
zoneStatus
}
"
!=
"active"
]
;
do
while
[
"
${
zoneStatus
}
"
!=
"
\
"
active
\"
"
]
;
do
_sleep 5
_sleep 5
_hostingde_getZoneStatus
_hostingde_getZoneStatus
_debug
"Result of zoneStatus: '
${
zoneStatus
}
'"
_debug
"Result of zoneStatus: '
${
zoneStatus
}
'"
done
done
curData
=
"{
\"
authToken
\"
:
\"
${
HOSTINGDE_APIKEY
}
\"
,
\"
zoneConfig
\"
:{
\"
id
\"
:
\"
${
zoneConfigId
}
\"
,
\"
name
\"
:
\"
${
zoneConfigName
}
\"
,
\"
type
\"
:
\"
${
zoneConfigType
}
\"
,
\"
dnsServerGroupId
\"
:
\"
${
zoneConfigDnsServerGroupId
}
\"
,
\"
dnsSecMode
\"
:
\"
${
zoneConfigDnsSecMode
}
\"
,
\"
emailAddress
\"
:
\"
${
zoneConfigEmailAddress
}
\"
,
\"
soaValues
\"
:{
\"
expire
\"
:
${
zoneConfigExpire
}
,
\"
negativeTtl
\"
:
${
zoneConfigNegativeTtl
}
,
\"
refresh
\"
:
${
zoneConfigRefresh
}
,
\"
retry
\"
:
${
zoneConfigRetry
}
,
\"
ttl
\"
:
${
zoneConfigTtl
}
}},
\"
recordsToAdd
\"
:[{
\"
name
\"
:
\"
${
fulldomain
}
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
content
\"
:
\"\\\"
${
txtvalue
}
\\\"\"
,
\"
ttl
\"
:3600}]}"
curData
=
"{
\"
authToken
\"
:
\"
${
HOSTINGDE_APIKEY
}
\"
,
\"
zoneConfig
\"
:{
\"
id
\"
:
${
zoneConfigId
}
,
\"
name
\"
:
${
zoneConfigName
}
,
\"
type
\"
:
${
zoneConfigType
}
,
\"
dnsServerGroupId
\"
:
${
zoneConfigDnsServerGroupId
}
,
\"
dnsSecMode
\"
:
${
zoneConfigDnsSecMode
}
,
\"
emailAddress
\"
:
${
zoneConfigEmailAddress
}
,
\"
soaValues
\"
:{
\"
expire
\"
:
${
zoneConfigExpire
}
,
\"
negativeTtl
\"
:
${
zoneConfigNegativeTtl
}
,
\"
refresh
\"
:
${
zoneConfigRefresh
}
,
\"
retry
\"
:
${
zoneConfigRetry
}
,
\"
ttl
\"
:
${
zoneConfigTtl
}
}},
\"
recordsToAdd
\"
:[{
\"
name
\"
:
\"
${
fulldomain
}
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
content
\"
:
\"\\\"
${
txtvalue
}
\\\"\"
,
\"
ttl
\"
:3600}]}"
curResult
=
"
$(
_post
"
${
curData
}
"
"
${
HOSTINGDE_ENDPOINT
}
/api/dns/v1/json/zoneUpdate"
)
"
curResult
=
"
$(
_post
"
${
curData
}
"
"
${
HOSTINGDE_ENDPOINT
}
/api/dns/v1/json/zoneUpdate"
)
"
_debug
"Calling zoneUpdate: '
${
curData
}
' '
${
HOSTINGDE_ENDPOINT
}
/api/dns/v1/json/zoneUpdate'"
_debug
"Calling zoneUpdate: '
${
curData
}
' '
${
HOSTINGDE_ENDPOINT
}
/api/dns/v1/json/zoneUpdate'"
_debug
"Result of zoneUpdate: '
$curResult
'"
_debug
"Result of zoneUpdate: '
$curResult
'"
...
@@ -126,12 +140,12 @@ _hostingde_removeRecord() {
...
@@ -126,12 +140,12 @@ _hostingde_removeRecord() {
_info
"Removing record from zone"
_info
"Removing record from zone"
_hostingde_getZoneStatus
_hostingde_getZoneStatus
_debug
"Result of zoneStatus: '
$zoneStatus
'"
_debug
"Result of zoneStatus: '
$zoneStatus
'"
while
[
"
$zoneStatus
"
!=
"active"
]
;
do
while
[
"
$zoneStatus
"
!=
"
\
"
active
\"
"
]
;
do
_sleep 5
_sleep 5
_hostingde_getZoneStatus
_hostingde_getZoneStatus
_debug
"Result of zoneStatus: '
$zoneStatus
'"
_debug
"Result of zoneStatus: '
$zoneStatus
'"
done
done
curData
=
"{
\"
authToken
\"
:
\"
${
HOSTINGDE_APIKEY
}
\"
,
\"
zoneConfig
\"
:{
\"
id
\"
:
\"
${
zoneConfigId
}
\"
,
\"
name
\"
:
\"
${
zoneConfigName
}
\"
,
\"
type
\"
:
\"
${
zoneConfigType
}
\"
,
\"
dnsServerGroupId
\"
:
\"
${
zoneConfigDnsServerGroupId
}
\"
,
\"
dnsSecMode
\"
:
\"
${
zoneConfigDnsSecMode
}
\"
,
\"
emailAddress
\"
:
\"
${
zoneConfigEmailAddress
}
\"
,
\"
soaValues
\"
:{
\"
expire
\"
:
${
zoneConfigExpire
}
,
\"
negativeTtl
\"
:
${
zoneConfigNegativeTtl
}
,
\"
refresh
\"
:
${
zoneConfigRefresh
}
,
\"
retry
\"
:
${
zoneConfigRetry
}
,
\"
ttl
\"
:
${
zoneConfigTtl
}
}},
\"
recordsToDelete
\"
:[{
\"
name
\"
:
\"
${
fulldomain
}
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
content
\"
:
\"\\\"
${
txtvalue
}
\\\"\"
}]}"
curData
=
"{
\"
authToken
\"
:
\"
${
HOSTINGDE_APIKEY
}
\"
,
\"
zoneConfig
\"
:{
\"
id
\"
:
${
zoneConfigId
}
,
\"
name
\"
:
${
zoneConfigName
}
,
\"
type
\"
:
${
zoneConfigType
}
,
\"
dnsServerGroupId
\"
:
${
zoneConfigDnsServerGroupId
}
,
\"
dnsSecMode
\"
:
${
zoneConfigDnsSecMode
}
,
\"
emailAddress
\"
:
${
zoneConfigEmailAddress
}
,
\"
soaValues
\"
:{
\"
expire
\"
:
${
zoneConfigExpire
}
,
\"
negativeTtl
\"
:
${
zoneConfigNegativeTtl
}
,
\"
refresh
\"
:
${
zoneConfigRefresh
}
,
\"
retry
\"
:
${
zoneConfigRetry
}
,
\"
ttl
\"
:
${
zoneConfigTtl
}
}},
\"
recordsToDelete
\"
:[{
\"
name
\"
:
\"
${
fulldomain
}
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
content
\"
:
\"\\\"
${
txtvalue
}
\\\"\"
}]}"
curResult
=
"
$(
_post
"
${
curData
}
"
"
${
HOSTINGDE_ENDPOINT
}
/api/dns/v1/json/zoneUpdate"
)
"
curResult
=
"
$(
_post
"
${
curData
}
"
"
${
HOSTINGDE_ENDPOINT
}
/api/dns/v1/json/zoneUpdate"
)
"
_debug
"Calling zoneUpdate: '
${
curData
}
' '
${
HOSTINGDE_ENDPOINT
}
/api/dns/v1/json/zoneUpdate'"
_debug
"Calling zoneUpdate: '
${
curData
}
' '
${
HOSTINGDE_ENDPOINT
}
/api/dns/v1/json/zoneUpdate'"
_debug
"Result of zoneUpdate: '
$curResult
'"
_debug
"Result of zoneUpdate: '
$curResult
'"
...
...
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