-
Notifications
You must be signed in to change notification settings - Fork 31
/
config.go
44 lines (37 loc) · 856 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"crypto/tls"
"fmt"
"gopkg.in/ldap.v2"
)
// Config is the set of parameters needed to configure the LDAP provider.
type Config struct {
LDAPHost string
LDAPPort int
UseTLS bool
BindUser string
BindPassword string
}
func (c *Config) initiateAndBind() (*ldap.Conn, error) {
// TODO: should we handle UDP ?
connection, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", c.LDAPHost, c.LDAPPort))
if err != nil {
return nil, err
}
// handle TLS
if c.UseTLS {
//TODO: Finish the TLS integration
err = connection.StartTLS(&tls.Config{InsecureSkipVerify: true})
if err != nil {
return nil, err
}
}
// bind to current connection
err = connection.Bind(c.BindUser, c.BindPassword)
if err != nil {
connection.Close()
return nil, err
}
// return the LDAP connection
return connection, nil
}