manager

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 30 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package manager connects to an LDAP directory, and keeps the connection, binding as the manager's user, and reconnecting when it's lost

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager keeps a connection to an LDAP directory

func New

func New(opt ...Opt) (*Manager, error)

New returns a manager of the directory at the URL, ldap or ldaps, whose user and password are the URL's, unless they're options, under the base DN. It doesn't connect until Connect, or Run, is called.

func (*Manager) AddGroupUsers

func (manager *Manager) AddGroupUsers(ctx context.Context, group string, users ...string) (_ *schema.Object, err error)

AddGroupUsers adds the users, by name, to the group, in one request, and returns it. Users who are members already are left as they are.

func (*Manager) Bind

func (manager *Manager) Bind(ctx context.Context, dn, password string) (_ *schema.Object, err error)

Bind checks the password of the entry, whose DN is under the base DN, or relative to it, and returns the entry, or ErrNotAuthorized. It binds on a connection of its own, so the manager's stays bound as its user.

func (*Manager) ChangePassword

func (manager *Manager) ChangePassword(ctx context.Context, dn string, req schema.ObjectPasswordRequest) (_ *schema.PasswordResponse, err error)

ChangePassword sets the password of the entry, whose DN is under the base DN, or relative to it, to the request's new password, or one which is generated, which is returned, when it's empty. With the old password, it binds as the entry, which changes its own password, so the old one is checked. Without it, the manager's user resets it.

An Active Directory user, whose objectClass is "user", has its unicodePwd set, which needs ldaps. Other directories have the password modify operation (RFC 3062).

func (*Manager) Connect

func (manager *Manager) Connect(ctx context.Context) (err error)

Connect connects to the directory, and binds, or, when it's connected, checks the connection, which is closed when it's lost, so the next call connects again

func (*Manager) Create

func (manager *Manager) Create(ctx context.Context, dn string, attrs schema.Attrs) (_ *schema.Object, err error)

Create adds the entry, whose DN is under the base DN, or relative to it, with the attributes, which need an objectClass, and returns it

func (*Manager) CreateGroup

func (manager *Manager) CreateGroup(ctx context.Context, name string, attrs schema.Attrs) (_ *schema.Object, err error)

CreateGroup adds a group with the name, as its cn, and the attributes, and returns it. The groups' object classes are added, which, when they aren't set, are those the directory has, such as groupOfNames and posixGroup, or Active Directory's group. A posixGroup without a gidNumber has the next one. A group whose class needs a member has itself, as groupOfNames and groupOfUniqueNames do.

func (*Manager) CreateUser

func (manager *Manager) CreateUser(ctx context.Context, name string, attrs schema.Attrs, allocateGID bool) (_ *schema.Object, err error)

CreateUser adds a user with the name, and the attributes, and returns it. The users' object classes are added, which, when they aren't set, are those the directory has, such as inetOrgPerson and posixAccount, or Active Directory's user. A posixAccount without a uidNumber has the next one, and, with allocateGID, the same gidNumber.

A password, in userPassword or unicodePwd, is set. An Active Directory user is created disabled, then has its password set, and is enabled, or is deleted when that fails. Without a password, it stays disabled.

func (*Manager) Delete

func (manager *Manager) Delete(ctx context.Context, dn string) (_ *schema.Object, err error)

Delete removes the entry, which has no children, and returns it

func (*Manager) DeleteGroup

func (manager *Manager) DeleteGroup(ctx context.Context, name string) (_ *schema.Object, err error)

DeleteGroup removes the group with the name, and returns it

func (*Manager) DeleteUser

func (manager *Manager) DeleteUser(ctx context.Context, name string) (_ *schema.Object, err error)

DeleteUser removes the user with the name, and returns it

func (*Manager) Disconnect

func (manager *Manager) Disconnect(ctx context.Context) (err error)

Disconnect closes the connection to the directory, when it's connected

func (*Manager) Get

func (manager *Manager) Get(ctx context.Context, dn string, attrs ...string) (_ *schema.Object, err error)

Get returns the entry, whose DN is under the base DN, or relative to it, with its attributes, or only those named, such as operational ones, which aren't returned otherwise, such as entryUUID

func (*Manager) GetGroup

func (manager *Manager) GetGroup(ctx context.Context, name string) (_ *schema.Object, err error)

GetGroup returns the group with the name

func (*Manager) GetUser

func (manager *Manager) GetUser(ctx context.Context, name string) (_ *schema.Object, err error)

GetUser returns the user with the name

func (*Manager) Host

func (manager *Manager) Host() string

Host returns the host of the directory

func (*Manager) List

func (manager *Manager) List(ctx context.Context, req schema.ObjectListRequest) (_ *schema.ObjectList, err error)

List returns the entries under the base DN, or, with a prefix, in the subtree of its DN, relative to the base DN, or under it, or, with children, only those directly under it, which match the request's filter, or all of them, with its attributes, or all of them. Count is the number which match, and Body those from the offset, up to the limit, or schema.MaxListEntries.

func (*Manager) ListAttributeTypes

func (manager *Manager) ListAttributeTypes(ctx context.Context, req schema.AttributeTypeListRequest) (_ *schema.AttributeTypeListResponse, err error)

ListAttributeTypes returns copies of the directory's attribute types, by name, which match the request. Count is the number which match, and Body those from the offset, up to the limit, or schema.MaxListEntries.

func (*Manager) ListGroups

func (manager *Manager) ListGroups(ctx context.Context, req schema.GroupListRequest) (_ *schema.ObjectList, err error)

ListGroups returns the groups, which are the entries directly under the groups' DN, which match the request's filter, and, when it has a user, have it as a member

func (*Manager) ListObjectClasses

func (manager *Manager) ListObjectClasses(ctx context.Context, req schema.ObjectClassListRequest) (_ *schema.ObjectClassListResponse, err error)

ListObjectClasses returns copies of the directory's object classes, by name, which match the request. Count is the number which match, and Body those from the offset, up to the limit, or schema.MaxListEntries. With For, they're only the classes users, or groups, are created with, and their superiors.

func (*Manager) ListUsers

func (manager *Manager) ListUsers(ctx context.Context, req schema.UserListRequest) (_ *schema.ObjectList, err error)

ListUsers returns the users, which are the entries directly under the users' DN, which match the request's filter, and, when it has a group, are its members

func (*Manager) Port

func (manager *Manager) Port() uint

Port returns the port of the directory

func (*Manager) RemoveGroupUsers

func (manager *Manager) RemoveGroupUsers(ctx context.Context, group string, users ...string) (_ *schema.Object, err error)

RemoveGroupUsers removes the users, by name, from the group, in one request, and returns it. Users who aren't members are left as they are.

func (*Manager) Run

func (manager *Manager) Run(ctx context.Context, logger *slog.Logger) error

Run connects to the directory, and checks the connection, reconnecting when it's lost, with a growing delay, or at once when an operation loses it, until the context is cancelled, when it disconnects

func (*Manager) Status added in v0.0.15

func (manager *Manager) Status() schema.Status

Status returns the directory, and whether the manager is connected to it, without waiting for the requests it's making

func (*Manager) Update

func (manager *Manager) Update(ctx context.Context, dn string, attrs schema.Attrs) (_ *schema.Object, err error)

Update replaces the entry's attributes which have values, and deletes those which have none, and returns it. Changing a value of the entry's RDN renames it first, keeping it under the same parent, then replaces the RDN's attribute with all its values, unless the rename has set them. When the changes fail, the rename is undone.

func (*Manager) UpdateGroup

func (manager *Manager) UpdateGroup(ctx context.Context, name string, attrs schema.Attrs) (_ *schema.Object, err error)

UpdateGroup changes the group with the name, as Update does, and returns it. Changing its cn renames it.

func (*Manager) UpdateUser

func (manager *Manager) UpdateUser(ctx context.Context, name string, attrs schema.Attrs) (_ *schema.Object, err error)

UpdateUser changes the user with the name, as Update does, and returns it. Changing its name renames it.

func (*Manager) User

func (manager *Manager) User() string

User returns the DN the manager binds as: a name, such as admin, is the common name under the base DN, and anything else is a DN

func (*Manager) WhoAmI

func (manager *Manager) WhoAmI(ctx context.Context) (_ string, err error)

WhoAmI returns the identity the manager is bound as

type Opt

type Opt func(*opt) error

Opt represents a function that modifies the options

func WithBaseDN

func WithBaseDN(v string) Opt

WithBaseDN sets the base DN, which the manager's DNs are under

func WithBroadcaster added in v0.0.15

func WithBroadcaster(publisher Publisher) Opt

WithTracer sets the OpenTelemetry tracer used for manager spans WithBroadcaster publishes the changes the manager makes, to objects, users and groups, and its connection coming up or going down, with schema.SchemaName as their schema

func WithGroupDN

func WithGroupDN(dn string, classes ...string) Opt

WithGroupDN sets the DN of the groups, and their object classes

func WithPassword

func WithPassword(v string) Opt

WithPassword sets the password, rather than the URL's

func WithSkipVerify

func WithSkipVerify() Opt

WithSkipVerify doesn't verify an ldaps server's certificate

func WithTracer added in v0.0.15

func WithTracer(tracer trace.Tracer) Opt

func WithUrl

func WithUrl(v string) Opt

WithUrl sets the directory's URL, ldap or ldaps, which can have the user and password

func WithUser

func WithUser(v string) Opt

WithUser sets the user, rather than the URL's, which is a name under the base DN, or a DN

func WithUserDN

func WithUserDN(dn string, classes ...string) Opt

WithUserDN sets the DN of the users, and their object classes

type Publisher added in v0.0.15

type Publisher interface {
	Publish(changes.Change) int
}

Publisher publishes changes, such as go-server's broadcaster, which a web UI follows

Jump to

Keyboard shortcuts

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