Commit a439f055 authored by ale's avatar ale
Browse files

Update ai3/go-common

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