ldappool

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2023 License: MIT Imports: 6 Imported by: 0

README

Basic connection pool for go-ldap

This little library use the go-ldap library and pool connections for you.

Don't hesitate to open issues or pull requests, I write that for my own need so that miss some features or tests :)

Features

  • Customize the number of connections to keep alive.
  • Custom timeout duration while awaiting a available connection
  • Reconnect when a connection or the server goes down

Limitation

  • Fixed connections count.
  • Some functions is missing, I only added Search, SearchWithPaging, Add, Modify, ModifyWithResult, ModifyDN, Del.
  • Only anonymous or simple bind is available for the moment.

How to use it ?

p, err := ldappool.NewPool(context.Background(), &ldappool.PoolOptions{
    URL: "ldaps://ldap.example.fr",
    // Manage 10 connections
    ConnectionsCount: 10,
    // Every request is going to wait a available connection 5 seconds and return an error if there is no connections available
    ConnectionTimeout: time.Second * 5,
    // If a connection is marked as unavailable after a heartbeat, we try to connect every 5 seconds
    WakeupInterval: time.Second * 5,
    BindCredentials: &ldappool.BindCredentials{
        Username: "cn=admin,dc=example,dc=fr",
        Password: "toto",
    },
})

if err != nil {
    log.Fatal(err)
}

res, err := p.Search(ldap.NewSearchRequest(
    "dc=example,dc=fr",
    ldap.ScopeWholeSubtree,
    ldap.NeverDerefAliases, 0, 0, false,
    "(&(objectClass=posixAccount))",
    []string{"*"}, []ldap.Control{}),
)

log.Println(res, err)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BindCredentials

type BindCredentials struct {
	Username string
	Password string
}

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool(ctx context.Context, po *PoolOptions) (*Pool, error)

func (*Pool) Add

func (p *Pool) Add(addRequest *ldap.AddRequest) error

func (*Pool) Close

func (p *Pool) Close() error

func (*Pool) Del

func (p *Pool) Del(delRequest *ldap.DelRequest) error

func (*Pool) Modify

func (p *Pool) Modify(modifyRequest *ldap.ModifyRequest) error

func (*Pool) ModifyDN

func (p *Pool) ModifyDN(m *ldap.ModifyDNRequest) error

func (*Pool) ModifyWithResult

func (p *Pool) ModifyWithResult(modifyRequest *ldap.ModifyRequest) (*ldap.ModifyResult, error)

func (*Pool) PasswordModify

func (p *Pool) PasswordModify(passwordModifyRequest *ldap.PasswordModifyRequest) (*ldap.PasswordModifyResult, error)

func (*Pool) Search

func (p *Pool) Search(searchRequest *ldap.SearchRequest) (*ldap.SearchResult, error)

func (*Pool) SearchWithPaging

func (p *Pool) SearchWithPaging(searchRequest *ldap.SearchRequest, pagingSize uint32) (*ldap.SearchResult, error)

type PoolConnection

type PoolConnection struct {
	*ldap.Conn
	State PoolConnectionState

	Index int
	// contains filtered or unexported fields
}

func (*PoolConnection) SetState

func (pc *PoolConnection) SetState(state PoolConnectionState)

type PoolConnectionState

type PoolConnectionState int
const (
	PoolConnectionAvailable PoolConnectionState = iota
	PoolConnectionBusy
	PoolConnectionUnavailable
)

type PoolOptions

type PoolOptions struct {
	Debug           bool
	URL             string
	BindCredentials *BindCredentials

	ConnectionsCount  int
	ConnectionTimeout time.Duration
	WakeupInterval    time.Duration
	IdleTimeout       time.Duration
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL