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
a88622c1
Commit
a88622c1
authored
Jan 06, 2020
by
Sergey Zorin
Browse files
#2547 replace NIC_Token to NIC_ClientID&NIC_ClientSecret with backward compatibility
parent
c3fbc36c
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_nic.sh
View file @
a88622c1
...
...
@@ -13,22 +13,8 @@ dns_nic_add() {
fulldomain
=
"
${
1
}
"
txtvalue
=
"
${
2
}
"
NIC_Token
=
"
${
NIC_Token
:-
$(
_readaccountconf_mutable NIC_Token
)
}
"
NIC_Username
=
"
${
NIC_Username
:-
$(
_readaccountconf_mutable NIC_Username
)
}
"
NIC_Password
=
"
${
NIC_Password
:-
$(
_readaccountconf_mutable NIC_Password
)
}
"
if
[
-z
"
$NIC_Token
"
]
||
[
-z
"
$NIC_Username
"
]
||
[
-z
"
$NIC_Password
"
]
;
then
NIC_Token
=
""
NIC_Username
=
""
NIC_Password
=
""
_err
"You must export variables: NIC_Token, NIC_Username and NIC_Password"
return
1
fi
_saveaccountconf_mutable NIC_Token
"
$NIC_Token
"
_saveaccountconf_mutable NIC_Username
"
$NIC_Username
"
_saveaccountconf_mutable NIC_Password
"
$NIC_Password
"
if
!
_nic_get_authtoken
"
$NIC_Username
"
"
$NIC_Password
"
"
$NIC_Token
"
;
then
if
!
_nic_get_authtoken
save
;
then
_err
"get NIC auth token failed"
return
1
fi
...
...
@@ -59,18 +45,7 @@ dns_nic_rm() {
fulldomain
=
"
${
1
}
"
txtvalue
=
"
${
2
}
"
NIC_Token
=
"
${
NIC_Token
:-
$(
_readaccountconf_mutable NIC_Token
)
}
"
NIC_Username
=
"
${
NIC_Username
:-
$(
_readaccountconf_mutable NIC_Username
)
}
"
NIC_Password
=
"
${
NIC_Password
:-
$(
_readaccountconf_mutable NIC_Password
)
}
"
if
[
-z
"
$NIC_Token
"
]
||
[
-z
"
$NIC_Username
"
]
||
[
-z
"
$NIC_Password
"
]
;
then
NIC_Token
=
""
NIC_Username
=
""
NIC_Password
=
""
_err
"You must export variables: NIC_Token, NIC_Username and NIC_Password"
return
1
fi
if
!
_nic_get_authtoken
"
$NIC_Username
"
"
$NIC_Password
"
"
$NIC_Token
"
;
then
if
!
_nic_get_authtoken
;
then
_err
"get NIC auth token failed"
return
1
fi
...
...
@@ -103,17 +78,64 @@ dns_nic_rm() {
#################### Private functions below ##################################
#_nic_get_auth_elements [need2save]
_nic_get_auth_elements
()
{
_need2save
=
$1
NIC_ClientID
=
"
${
NIC_ClientID
:-
$(
_readaccountconf_mutable NIC_ClientID
)
}
"
NIC_ClientSecret
=
"
${
NIC_ClientSecret
:-
$(
_readaccountconf_mutable NIC_ClientSecret
)
}
"
NIC_Username
=
"
${
NIC_Username
:-
$(
_readaccountconf_mutable NIC_Username
)
}
"
NIC_Password
=
"
${
NIC_Password
:-
$(
_readaccountconf_mutable NIC_Password
)
}
"
## for backward compatibility
if
[
-z
"
$NIC_ClientID
"
]
||
[
-z
"
$NIC_ClientSecret
"
]
;
then
NIC_Token
=
"
${
NIC_Token
:-
$(
_readaccountconf_mutable NIC_Token
)
}
"
_debug NIC_Token
"
$NIC_Token
"
if
[
-n
"
$NIC_Token
"
]
;
then
_two_values
=
"
$(
echo
"
${
NIC_Token
}
"
| _dbase64
)
"
_debug _two_values
"
$_two_values
"
IFS
=
":"
read
-r
NIC_ClientID NIC_ClientSecret
<<<
$_two_values
_debug restored_NIC_ClientID
"
$NIC_ClientID
"
_debug restored_NIC_ClientSecret
"
$NIC_ClientSecret
"
fi
fi
if
[
-z
"
$NIC_ClientID
"
]
||
[
-z
"
$NIC_ClientSecret
"
]
||
[
-z
"
$NIC_Username
"
]
||
[
-z
"
$NIC_Password
"
]
;
then
NIC_ClientID
=
""
NIC_ClientSecret
=
""
NIC_Username
=
""
NIC_Password
=
""
_err
"You must export variables: NIC_ClientID, NIC_ClientSecret, NIC_Username and NIC_Password"
return
1
fi
if
[
"
$_need2save
"
]
;
then
_saveaccountconf_mutable NIC_ClientID
"
$NIC_ClientID
"
_saveaccountconf_mutable NIC_ClientSecret
"
$NIC_ClientSecret
"
_saveaccountconf_mutable NIC_Username
"
$NIC_Username
"
_saveaccountconf_mutable NIC_Password
"
$NIC_Password
"
fi
NIC_BasicAuth
=
$(
printf
"%s:%s"
"
${
NIC_ClientID
}
"
"
${
NIC_ClientSecret
}
"
| _base64
)
_debug NIC_BasicAuth
"
$NIC_BasicAuth
"
}
#_nic_get_authtoken [need2save]
_nic_get_authtoken
()
{
username
=
"
$1
"
password
=
"
$2
"
token
=
"
$3
"
_need2save
=
$1
if
!
_nic_get_auth_elements
$_need2save
;
then
return
1
fi
_info
"Getting NIC auth token"
export
_H1
=
"Authorization: Basic
$
token
"
export
_H1
=
"Authorization: Basic
$
{
NIC_BasicAuth
}
"
export
_H2
=
"Content-Type: application/x-www-form-urlencoded"
res
=
$(
_post
"grant_type=password&username=
$
u
sername
&password=
$
p
assword
&scope=%28GET%7CPUT%7CPOST%7CDELETE%29%3A%2Fdns-master%2F.%2B"
"
$NIC_Api
/oauth/token"
""
"POST"
)
res
=
$(
_post
"grant_type=password&username=
$
{
NIC_U
sername
}
&password=
$
{
NIC_P
assword
}
&scope=%28GET%7CPUT%7CPOST%7CDELETE%29%3A%2Fdns-master%2F.%2B"
"
$NIC_Api
/oauth/token"
""
"POST"
)
if
_contains
"
$res
"
"access_token"
;
then
_auth_token
=
$(
printf
"%s"
"
$res
"
|
cut
-d
,
-f2
|
tr
-d
"
\"
"
|
sed
"s/access_token://"
)
_info
"Token received"
...
...
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