summaryrefslogtreecommitdiff
path: root/internal/authentication/ldap_client_dialer.go
blob: 4577e2eae59c9a6de188c4898a1f17280d797705 (plain)
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
package authentication

import (
	"fmt"

	"github.com/go-ldap/ldap/v3"
)

// LDAPClientDialer is an abstract type that dials a ldap.Client.
type LDAPClientDialer interface {
	// DialURL takes a single address and dials it returning the ldap.Client.
	DialURL(addr string, opts ...ldap.DialOpt) (client ldap.Client, err error)
}

// NewLDAPClientDialerStandard returns a new *LDAPClientDialerStandard.
func NewLDAPClientDialerStandard() *LDAPClientDialerStandard {
	return &LDAPClientDialerStandard{}
}

// LDAPClientDialerStandard is a concrete type that dials a ldap.Client and returns it, implementing the
// LDAPClientDialer.
type LDAPClientDialerStandard struct{}

// DialURL takes a single address and dials it returning the ldap.Client.
func (d *LDAPClientDialerStandard) DialURL(addr string, opts ...ldap.DialOpt) (client ldap.Client, err error) {
	if client, err = ldap.DialURL(addr, opts...); err != nil {
		return nil, fmt.Errorf("failed to dial LDAP server at %s: %w", addr, err)
	}

	return client, nil
}