Commit a439f055 authored by ale's avatar ale
Browse files

Update ai3/go-common

parent e0d2b845
...@@ -40,10 +40,12 @@ func (p *ConnectionPool) connect(ctx context.Context) (*ldap.Conn, error) { ...@@ -40,10 +40,12 @@ func (p *ConnectionPool) connect(ctx context.Context) (*ldap.Conn, error) {
conn := ldap.NewConn(c, false) conn := ldap.NewConn(c, false)
conn.Start() conn.Start()
conn.SetTimeout(time.Until(deadline)) if p.bindDN != "" {
if _, err = conn.SimpleBind(ldap.NewSimpleBindRequest(p.bindDN, p.bindPw, nil)); err != nil { conn.SetTimeout(time.Until(deadline))
conn.Close() if _, err = conn.SimpleBind(ldap.NewSimpleBindRequest(p.bindDN, p.bindPw, nil)); err != nil {
return nil, err conn.Close()
return nil, err
}
} }
return conn, err return conn, err
......
...@@ -10,16 +10,24 @@ import ( ...@@ -10,16 +10,24 @@ import (
"git.autistici.org/ai3/go-common/clientutil" "git.autistici.org/ai3/go-common/clientutil"
) )
// Treat all errors as potential network-level issues, except for a // Interface matched by net.Error.
// whitelist of LDAP protocol level errors that we know are benign. type hasTemporary interface {
Temporary() bool
}
// Treat network errors as temporary. Other errors are permanent by
// default.
func isTemporaryLDAPError(err error) bool { func isTemporaryLDAPError(err error) bool {
ldapErr, ok := err.(*ldap.Error) switch v := err.(type) {
if !ok { case *ldap.Error:
return true switch v.ResultCode {
} case ldap.ErrorNetwork:
switch ldapErr.ResultCode { return true
case ldap.ErrorNetwork: default:
return true return false
}
case hasTemporary:
return v.Temporary()
default: default:
return false return false
} }
...@@ -32,6 +40,7 @@ func (p *ConnectionPool) Search(ctx context.Context, searchRequest *ldap.SearchR ...@@ -32,6 +40,7 @@ func (p *ConnectionPool) Search(ctx context.Context, searchRequest *ldap.SearchR
err := clientutil.Retry(func() error { err := clientutil.Retry(func() error {
conn, err := p.Get(ctx) conn, err := p.Get(ctx)
if err != nil { if err != nil {
// Here conn is nil, so we don't need to Release it.
if isTemporaryLDAPError(err) { if isTemporaryLDAPError(err) {
return clientutil.TempError(err) return clientutil.TempError(err)
} }
...@@ -44,7 +53,7 @@ func (p *ConnectionPool) Search(ctx context.Context, searchRequest *ldap.SearchR ...@@ -44,7 +53,7 @@ func (p *ConnectionPool) Search(ctx context.Context, searchRequest *ldap.SearchR
result, err = conn.Search(searchRequest) result, err = conn.Search(searchRequest)
if err != nil && isTemporaryLDAPError(err) { if err != nil && isTemporaryLDAPError(err) {
p.Release(conn, nil) p.Release(conn, err)
return clientutil.TempError(err) return clientutil.TempError(err)
} }
p.Release(conn, err) p.Release(conn, err)
......
...@@ -5,32 +5,32 @@ ...@@ -5,32 +5,32 @@
{ {
"checksumSHA1": "raJx5BjBbVQG0ylGSjPpi+JvqjU=", "checksumSHA1": "raJx5BjBbVQG0ylGSjPpi+JvqjU=",
"path": "git.autistici.org/ai3/go-common", "path": "git.autistici.org/ai3/go-common",
"revision": "8cedcb1d73128f5566216cb3e39ad1ccea318213", "revision": "3e38f41af368c36cd5d6642abcf1460cf4c65e78",
"revisionTime": "2017-12-16T15:39:23Z" "revisionTime": "2018-01-11T08:21:54Z"
}, },
{ {
"checksumSHA1": "o+rWKVQIDy79ZwrItwa5/whAL6g=", "checksumSHA1": "o+rWKVQIDy79ZwrItwa5/whAL6g=",
"path": "git.autistici.org/ai3/go-common/clientutil", "path": "git.autistici.org/ai3/go-common/clientutil",
"revision": "9b20acad90c411c48f7ddc837a35ef3d0d6f98d4", "revision": "3e38f41af368c36cd5d6642abcf1460cf4c65e78",
"revisionTime": "2017-12-17T20:32:41Z" "revisionTime": "2018-01-11T08:21:54Z"
}, },
{ {
"checksumSHA1": "mEnXMNziH82HFtGngHU19VHTVHs=", "checksumSHA1": "jnfq/QeWcZCebhGuJ+t8nrd8POY=",
"path": "git.autistici.org/ai3/go-common/ldap", "path": "git.autistici.org/ai3/go-common/ldap",
"revision": "86a36cf5da88919ee7d9ec12d1a92043b16fcc9c", "revision": "3e38f41af368c36cd5d6642abcf1460cf4c65e78",
"revisionTime": "2017-12-10T11:04:55Z" "revisionTime": "2018-01-11T08:21:54Z"
}, },
{ {
"checksumSHA1": "z1034Bd8fOSLvtOP3VLf65YOQyA=", "checksumSHA1": "z1034Bd8fOSLvtOP3VLf65YOQyA=",
"path": "git.autistici.org/ai3/go-common/pwhash", "path": "git.autistici.org/ai3/go-common/pwhash",
"revision": "7eb77848e6d9507db2549ff853e968d1906dd8f4", "revision": "3e38f41af368c36cd5d6642abcf1460cf4c65e78",
"revisionTime": "2017-12-22T23:58:55Z" "revisionTime": "2018-01-11T08:21:54Z"
}, },
{ {
"checksumSHA1": "T2vf4xzKRqoIjfXlofMgudKA8rA=", "checksumSHA1": "T2vf4xzKRqoIjfXlofMgudKA8rA=",
"path": "git.autistici.org/ai3/go-common/unix", "path": "git.autistici.org/ai3/go-common/unix",
"revision": "8cedcb1d73128f5566216cb3e39ad1ccea318213", "revision": "3e38f41af368c36cd5d6642abcf1460cf4c65e78",
"revisionTime": "2017-12-16T15:39:23Z" "revisionTime": "2018-01-11T08:21:54Z"
}, },
{ {
"checksumSHA1": "7Kbb9vTjqcQhhxtSGpmp9rk6PUk=", "checksumSHA1": "7Kbb9vTjqcQhhxtSGpmp9rk6PUk=",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment