cache

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package cache handles transaction with an underlying database to cache user and group information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemoveDb

func RemoveDb(cacheDir string) error

RemoveDb removes the database file.

func Z_ForTests_CreateDBFromYAML added in v0.4.1

func Z_ForTests_CreateDBFromYAML(t *testing.T, src, destDir string)

Z_ForTests_CreateDBFromYAML creates the database inside destDir and loads the src file content into it.

nolint:revive,nolintlint // We want to use underscores in the function name here.

func Z_ForTests_DBName added in v0.4.1

func Z_ForTests_DBName() string

Z_ForTests_DBName returns the name of the database.

nolint:revive,nolintlint // We want to use underscores in the function name here.

func Z_ForTests_DumpNormalizedYAML added in v0.4.1

func Z_ForTests_DumpNormalizedYAML(c *Cache) (string, error)

Z_ForTests_DumpNormalizedYAML gets the content of the database, normalizes it (so that it can be compared with a golden file) and returns it as a YAML string.

nolint:revive,nolintlint // We want to use underscores in the function name here.

func Z_ForTests_FromYAML added in v0.4.1

func Z_ForTests_FromYAML(r io.Reader, destDir string) error

Z_ForTests_FromYAML loads the content of the database from YAML.

nolint:revive,nolintlint // We want to use underscores in the function name here.

Types

type Cache

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

Cache is our database API.

func New

func New(cacheDir string) (cache *Cache, err error)

New creates a new database cache by creating or opening the underlying db.

func (*Cache) AllGroups

func (c *Cache) AllGroups() (all []GroupDB, err error)

AllGroups returns all groups or an error if the database is corrupted.

func (*Cache) AllUsers

func (c *Cache) AllUsers() (all []UserDB, err error)

AllUsers returns all users or an error if the database is corrupted.

func (*Cache) BrokerForUser

func (c *Cache) BrokerForUser(username string) (brokerID string, err error)

BrokerForUser returns the broker ID assigned to the given username, empty if it's not assigned yet or an error if no user was found in cache.

func (*Cache) Close

func (c *Cache) Close() error

Close closes the db and signal the monitoring goroutine to stop.

func (*Cache) DeleteUser

func (c *Cache) DeleteUser(uid uint32) error

DeleteUser removes the user from the database.

func (*Cache) GroupByID

func (c *Cache) GroupByID(gid uint32) (GroupDB, error)

GroupByID returns a group matching this gid or an error if the database is corrupted or no entry was found.

func (*Cache) GroupByName

func (c *Cache) GroupByName(name string) (GroupDB, error)

GroupByName returns a group matching a given name or an error if the database is corrupted or no entry was found.

func (*Cache) GroupByUGID added in v0.4.1

func (c *Cache) GroupByUGID(ugid string) (GroupDB, error)

GroupByUGID returns a group matching this ugid or an error if the database is corrupted or no entry was found.

func (*Cache) UpdateBrokerForUser

func (c *Cache) UpdateBrokerForUser(username, brokerID string) error

UpdateBrokerForUser updates the last broker the user successfully authenticated with.

func (*Cache) UpdateUserEntry

func (c *Cache) UpdateUserEntry(usr UserDB, authdGroups []GroupDB, localGroups []string) error

UpdateUserEntry inserts or updates user and group buckets from the user information.

func (*Cache) UserByID

func (c *Cache) UserByID(uid uint32) (UserDB, error)

UserByID returns a user matching this uid or an error if the database is corrupted or no entry was found.

func (*Cache) UserByName

func (c *Cache) UserByName(name string) (UserDB, error)

UserByName returns a user matching this name or an error if the database is corrupted or no entry was found.

func (*Cache) UserGroups

func (c *Cache) UserGroups(uid uint32) ([]GroupDB, error)

UserGroups returns all groups for a given user or an error if the database is corrupted or no entry was found.

func (*Cache) UserLocalGroups

func (c *Cache) UserLocalGroups(uid uint32) ([]string, error)

UserLocalGroups returns all local groups for a given user or an error if the database is corrupted or no entry was found.

type GroupDB

type GroupDB struct {
	Name  string
	GID   uint32
	UGID  string
	Users []string
}

GroupDB is the struct stored in json format in the bucket.

func NewGroupDB

func NewGroupDB(name string, gid uint32, ugid string, members []string) GroupDB

NewGroupDB creates a new GroupDB.

type NoDataFoundError

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

NoDataFoundError is returned when we didn’t find a matching entry.

func (NoDataFoundError) Error

func (err NoDataFoundError) Error() string

Error implements the error interface to return key/bucket name.

func (NoDataFoundError) Is

func (NoDataFoundError) Is(target error) bool

Is makes this error insensitive to the key and bucket name.

type UserDB

type UserDB struct {
	Name  string
	UID   uint32
	GID   uint32
	Gecos string // Gecos is an optional field. It can be empty.
	Dir   string
	Shell string

	// Shadow entries
	LastPwdChange  int
	MaxPwdAge      int
	PwdWarnPeriod  int
	PwdInactivity  int
	MinPwdAge      int
	ExpirationDate int
}

UserDB is the public type that is shared to external packages.

func NewUserDB

func NewUserDB(name string, uid, gid uint32, gecos, dir, shell string) UserDB

NewUserDB creates a new UserDB.

Jump to

Keyboard shortcuts

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