@@ -1861,12 +1861,10 @@ func (clnt *Client) CreateUser(policy *AdminPolicy, user string, password string
18611861 return err
18621862 }
18631863
1864- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
1864+ return node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
18651865 command := NewAdminCommand (nil )
1866- err = command .createUser (conn , policy , user , hash , roles )
1866+ return command .createUser (conn , policy , user , hash , roles )
18671867 })
1868-
1869- return err
18701868}
18711869
18721870// CreatePKIUser creates a new user PKI user with roles. PKI users are authenticated via TLS and a certificate instead of a password.
@@ -1891,12 +1889,10 @@ func (clnt *Client) CreatePKIUser(policy *AdminPolicy, user string, roles []stri
18911889 return newCommonError (nil , fmt .Sprintf ("Node version %s is less than required minimum version %s" , node .version .String (), serverMinVersion ))
18921890 }
18931891
1894- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
1892+ if err := node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
18951893 command := NewAdminCommand (nil )
1896- err = command .createUser (conn , policy , user , hash , roles )
1897- })
1898-
1899- if err != nil {
1894+ return command .createUser (conn , policy , user , hash , roles )
1895+ }); err != nil {
19001896 return newError (err .resultCode (), fmt .Sprintf ("PKI user creation failed: %s" , err .Error ()))
19011897 }
19021898
@@ -1913,11 +1909,10 @@ func (clnt *Client) DropUser(policy *AdminPolicy, user string) Error {
19131909 return err
19141910 }
19151911
1916- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
1912+ return node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
19171913 command := NewAdminCommand (nil )
1918- err = command .dropUser (conn , policy , user )
1914+ return command .dropUser (conn , policy , user )
19191915 })
1920- return err
19211916}
19221917
19231918// ChangePassword changes a user's password. Clear-text password will be hashed using bcrypt before sending to server.
@@ -1939,23 +1934,21 @@ func (clnt *Client) ChangePassword(policy *AdminPolicy, user string, password st
19391934 return err
19401935 }
19411936
1942- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
1937+ if err := node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
19431938 command := NewAdminCommand (nil )
19441939
19451940 if user == clnt .cluster .user {
19461941 // Change own password.
1947- err = command .changePassword (conn , policy , user , clnt .cluster .Password (), hash )
1948- } else {
1949- // Change other user's password by user admin.
1950- err = command .setPassword (conn , policy , user , hash )
1942+ return command .changePassword (conn , policy , user , clnt .cluster .Password (), hash )
19511943 }
1952- })
1953-
1954- if err = = nil {
1955- clnt . cluster . changePassword ( user , password , hash )
1944+ // Change other user's password by user admin.
1945+ return command . setPassword ( conn , policy , user , hash )
1946+ }); err ! = nil {
1947+ return err
19561948 }
19571949
1958- return err
1950+ clnt .cluster .changePassword (user , password , hash )
1951+ return nil
19591952}
19601953
19611954// GrantRoles adds roles to user's list of roles.
@@ -1968,11 +1961,10 @@ func (clnt *Client) GrantRoles(policy *AdminPolicy, user string, roles []string)
19681961 return err
19691962 }
19701963
1971- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
1964+ return node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
19721965 command := NewAdminCommand (nil )
1973- err = command .grantRoles (conn , policy , user , roles )
1966+ return command .grantRoles (conn , policy , user , roles )
19741967 })
1975- return err
19761968}
19771969
19781970// RevokeRoles removes roles from user's list of roles.
@@ -1985,12 +1977,10 @@ func (clnt *Client) RevokeRoles(policy *AdminPolicy, user string, roles []string
19851977 return err
19861978 }
19871979
1988- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
1980+ return node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
19891981 command := NewAdminCommand (nil )
1990- err = command .revokeRoles (conn , policy , user , roles )
1982+ return command .revokeRoles (conn , policy , user , roles )
19911983 })
1992-
1993- return err
19941984}
19951985
19961986// QueryUser retrieves roles for a given user.
@@ -2003,10 +1993,15 @@ func (clnt *Client) QueryUser(policy *AdminPolicy, user string) (res *UserRoles,
20031993 return nil , err
20041994 }
20051995
2006- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
1996+ if errCall := node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
20071997 command := NewAdminCommand (nil )
20081998 res , err = command .QueryUser (conn , policy , user )
2009- })
1999+
2000+ return err
2001+ }); errCall != nil {
2002+ return nil , errCall
2003+ }
2004+
20102005 return res , err
20112006}
20122007
@@ -2020,10 +2015,15 @@ func (clnt *Client) QueryUsers(policy *AdminPolicy) (res []*UserRoles, err Error
20202015 return nil , err
20212016 }
20222017
2023- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
2018+ if errCall := node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
20242019 command := NewAdminCommand (nil )
20252020 res , err = command .QueryUsers (conn , policy )
2026- })
2021+
2022+ return err
2023+ }); errCall != nil {
2024+ return nil , errCall
2025+ }
2026+
20272027 return res , err
20282028}
20292029
@@ -2037,10 +2037,15 @@ func (clnt *Client) QueryRole(policy *AdminPolicy, role string) (res *Role, err
20372037 return nil , err
20382038 }
20392039
2040- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
2040+ if errCall := node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
20412041 command := NewAdminCommand (nil )
20422042 res , err = command .QueryRole (conn , policy , role )
2043- })
2043+
2044+ return err
2045+ }); errCall != nil {
2046+ return nil , errCall
2047+ }
2048+
20442049 return res , err
20452050}
20462051
@@ -2054,10 +2059,15 @@ func (clnt *Client) QueryRoles(policy *AdminPolicy) (res []*Role, err Error) {
20542059 return nil , err
20552060 }
20562061
2057- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
2062+ if errCall := node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
20582063 command := NewAdminCommand (nil )
20592064 res , err = command .QueryRoles (conn , policy )
2060- })
2065+
2066+ return err
2067+ }); errCall != nil {
2068+ return nil , errCall
2069+ }
2070+
20612071 return res , err
20622072}
20632073
@@ -2073,11 +2083,10 @@ func (clnt *Client) CreateRole(policy *AdminPolicy, roleName string, privileges
20732083 return err
20742084 }
20752085
2076- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
2086+ return node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
20772087 command := NewAdminCommand (nil )
2078- err = command .createRole (conn , policy , roleName , privileges , whitelist , readQuota , writeQuota )
2088+ return command .createRole (conn , policy , roleName , privileges , whitelist , readQuota , writeQuota )
20792089 })
2080- return err
20812090}
20822091
20832092// DropRole removes a user-defined role.
@@ -2090,11 +2099,10 @@ func (clnt *Client) DropRole(policy *AdminPolicy, roleName string) Error {
20902099 return err
20912100 }
20922101
2093- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
2102+ return node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
20942103 command := NewAdminCommand (nil )
2095- err = command .dropRole (conn , policy , roleName )
2104+ return command .dropRole (conn , policy , roleName )
20962105 })
2097- return err
20982106}
20992107
21002108// GrantPrivileges grant privileges to a user-defined role.
@@ -2107,11 +2115,10 @@ func (clnt *Client) GrantPrivileges(policy *AdminPolicy, roleName string, privil
21072115 return err
21082116 }
21092117
2110- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
2118+ return node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
21112119 command := NewAdminCommand (nil )
2112- err = command .grantPrivileges (conn , policy , roleName , privileges )
2120+ return command .grantPrivileges (conn , policy , roleName , privileges )
21132121 })
2114- return err
21152122}
21162123
21172124// RevokePrivileges revokes privileges from a user-defined role.
@@ -2124,11 +2131,10 @@ func (clnt *Client) RevokePrivileges(policy *AdminPolicy, roleName string, privi
21242131 return err
21252132 }
21262133
2127- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
2134+ return node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
21282135 command := NewAdminCommand (nil )
2129- err = command .revokePrivileges (conn , policy , roleName , privileges )
2136+ return command .revokePrivileges (conn , policy , roleName , privileges )
21302137 })
2131- return err
21322138}
21332139
21342140// SetWhitelist sets IP address whitelist for a role. If whitelist is nil or empty, it removes existing whitelist from role.
@@ -2141,11 +2147,10 @@ func (clnt *Client) SetWhitelist(policy *AdminPolicy, roleName string, whitelist
21412147 return err
21422148 }
21432149
2144- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
2150+ return node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
21452151 command := NewAdminCommand (nil )
2146- err = command .setWhitelist (conn , policy , roleName , whitelist )
2152+ return command .setWhitelist (conn , policy , roleName , whitelist )
21472153 })
2148- return err
21492154}
21502155
21512156// SetQuotas sets maximum reads/writes per second limits for a role. If a quota is zero, the limit is removed.
@@ -2160,11 +2165,10 @@ func (clnt *Client) SetQuotas(policy *AdminPolicy, roleName string, readQuota, w
21602165 return err
21612166 }
21622167
2163- node .usingTendConn (policy .Timeout , func (conn * Connection ) {
2168+ return node .usingTendConn (policy .Timeout , func (conn * Connection ) Error {
21642169 command := NewAdminCommand (nil )
2165- err = command .setQuotas (conn , policy , roleName , readQuota , writeQuota )
2170+ return command .setQuotas (conn , policy , roleName , readQuota , writeQuota )
21662171 })
2167- return err
21682172}
21692173
21702174//-------------------------------------------------------
0 commit comments