store

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingEquals    = errors.New("missing = in DN, expected exactly one")
	ErrInvalidComponent = errors.New("invalid component")
)
View Source
var ErrCommitted = errors.New("transaction already committed")
View Source
var (
	ErrInvalidBackend = errors.New("invalid backend")
)
View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

func StoreFlagSet

func StoreFlagSet() (*flag.FlagSet, func() StoreConfig)

Types

type AttributeKey

type AttributeKey string

func NewAttributeKey

func NewAttributeKey(key string) AttributeKey

func (AttributeKey) EqualFold

func (ak1 AttributeKey) EqualFold(ak2 AttributeKey) bool

type AttributeValue

type AttributeValue []string

type Attributes

type Attributes map[AttributeKey]AttributeValue

func (Attributes) Get

func (attrs Attributes) Get(key AttributeKey) AttributeValue

type Component

type Component struct {
	Type  string
	Value string
}

func NewComponent

func NewComponent(typ, value string) Component

func ParseComponent

func ParseComponent(rawComp string) (Component, error)

func (Component) String

func (seg Component) String() string

type DN

type DN []Component

DN represents an LDAP DN split by ,.

func ParseDN

func ParseDN(rawDN string) (DN, error)

func (DN) Clone

func (dn DN) Clone() DN

func (DN) Equal

func (dn DN) Equal(dn2 DN) bool

func (DN) Level

func (dn DN) Level() int

func (DN) Parent

func (dn DN) Parent() DN

func (DN) Prefix

func (dn DN) Prefix() Prefix

func (DN) String

func (dn DN) String() string

func (DN) Sub

func (dn DN) Sub(comps ...Component) DN

type Entry

type Entry struct {
	DN         DN
	Attributes Attributes
}

func NewEntry

func NewEntry(dn DN, attributes Attributes) Entry

func (*Entry) Get

func (e *Entry) Get(key AttributeKey) AttributeValue

func (Entry) Key added in v0.0.16

func (e Entry) Key() Prefix

Key implements pgcache.Object.

type Mem

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

func NewMem

func NewMem() *Mem

func (*Mem) Begin

func (m *Mem) Begin(ctx context.Context) (Transaction, error)

func (*Mem) List

func (m *Mem) List(ctx context.Context, prefix Prefix, exact bool) (entries []Entry, err error)

List implements Store.

func (*Mem) Metrics added in v0.0.15

func (m *Mem) Metrics() []prometheus.Collector

Metrics implements observability.Metrics.

func (*Mem) Ping added in v0.0.15

func (m *Mem) Ping(_ context.Context) error

Ping implements Store.

func (*Mem) ReadinessChecks added in v0.0.16

func (m *Mem) ReadinessChecks() map[string]observability.Check

ReadinessChecks implements run.ReadinessChecks

This is a no-op.

func (*Mem) Run added in v0.0.16

func (m *Mem) Run(ctx context.Context, notify run.Notify) error

Run implements run.Runnable

This is a no-op.

type MemTransaction

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

func (*MemTransaction) Commit

func (m *MemTransaction) Commit(ctx context.Context) error

func (*MemTransaction) Delete

func (m *MemTransaction) Delete(ctx context.Context, dn DN) (err error)

Delete implements Transaction.

func (*MemTransaction) Store

func (m *MemTransaction) Store(ctx context.Context, entry Entry) error

Store implements Transaction.

type PSQL

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

func NewPSQL

func NewPSQL(ctx context.Context, url string, logger *slog.Logger) (*PSQL, error)

func (*PSQL) Begin

func (p *PSQL) Begin(ctx context.Context) (Transaction, error)

Begin implements Store.

func (*PSQL) List

func (p *PSQL) List(ctx context.Context, prefix Prefix, exact bool) (entries []Entry, _ error)

List implements Store.

func (*PSQL) Metrics added in v0.0.15

func (p *PSQL) Metrics() []prometheus.Collector

Metrics implements observability.Metrics.

func (*PSQL) Ping added in v0.0.15

func (p *PSQL) Ping(ctx context.Context) error

Ping implements Store.

func (*PSQL) ReadinessChecks added in v0.0.16

func (p *PSQL) ReadinessChecks() map[string]observability.Check

ReadinessChecks implements run.ReadinessChecks.

func (*PSQL) Run added in v0.0.16

func (p *PSQL) Run(ctx context.Context, notify run.Notify) error

Run implements run.Runnable.

type PSQLTransaction

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

func (*PSQLTransaction) Commit

func (p *PSQLTransaction) Commit(ctx context.Context) (err error)

Commit implements Transaction.

func (*PSQLTransaction) Delete

func (p *PSQLTransaction) Delete(ctx context.Context, dn DN) (err error)

Delete implements Transaction.

func (*PSQLTransaction) Store

func (p *PSQLTransaction) Store(ctx context.Context, entry Entry) (err error)

Store implements Transaction.

type Prefix

type Prefix []Component

Prefix is the reverse of a DN and can be used to recursively enumerate the directory. If you take two DNs (of length n and m respectively) and get their prefixes, you can check if the two DNs are one subtree of the other by checking if the fist min(n, m) parts match. For example: DN1: dc=teapot,dc=ovh PR1: dc=ovh/dc=teapot DN2: ou=users,dc=teapot,dc=ovh PR2: dc=ovh/dc=teapot/ou=users Checking if strings.HasPrefix(PR1, PR2) will tell you if one is subtree of the other.

func ParsePrefix

func ParsePrefix(rawPrefix string) (Prefix, error)

func PrefixFromString added in v0.0.16

func PrefixFromString(rawPrefix string) (*Prefix, error)

func (Prefix) Clone

func (prefix Prefix) Clone() Prefix

func (Prefix) DN

func (prefix Prefix) DN() DN

func (Prefix) Equal

func (prefix Prefix) Equal(prefix2 Prefix) bool

func (Prefix) IsPrefixOf

func (prefix Prefix) IsPrefixOf(prf Prefix) bool

func (Prefix) Less added in v0.0.16

func (prefix Prefix) Less(p Prefix) bool

func (Prefix) Level

func (prefix Prefix) Level() int

func (Prefix) String

func (prefix Prefix) String() string

type Store

type Store interface {
	run.Runnable
	observability.Metrics
	observability.ReadinessChecks

	// Ping allows pinging the store to verify that it is ready to accept requests
	Ping(ctx context.Context) error

	// Lists all entries under the provided prefix DN. If exact is true, only
	// entries exactly matching this DN.
	List(ctx context.Context, prefix Prefix, exact bool) ([]Entry, error)

	// Begin starts a transaction through which the contents on the store can be modified.
	Begin(ctx context.Context) (Transaction, error)
}

Store provides an interface implemented by all types of stores for LDAP entries.

func NewStore

func NewStore(config StoreConfig, logger *slog.Logger) (Store, error)

type StoreConfig

type StoreConfig struct {
	Timeout time.Duration
	Type    string
	URL     string
}

type Transaction

type Transaction interface {
	// Store inserts or updates an entry in the store.
	Store(ctx context.Context, entry Entry) error

	// Delete deletes the entry with the specified DN.
	Delete(ctx context.Context, dn DN) error

	// Commit permanently saves the changes made through this transaction to the store.
	Commit(ctx context.Context) error
}

Transaction provides an interface to modify the LDAP entries in the store.

Jump to

Keyboard shortcuts

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