db

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MigrateFromBBoltToSQLite

func MigrateFromBBoltToSQLite(dbDir string) error

MigrateFromBBoltToSQLite migrates data from bbolt to SQLite.

func RemoveDB

func RemoveDB(dbDir string) error

RemoveDB removes the database file.

func Z_ForTests_CreateDBFromYAML

func Z_ForTests_CreateDBFromYAML(src, destDir string) error

Z_ForTests_CreateDBFromYAML creates the bbolt 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_CreateDBFromYAMLReader

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

Z_ForTests_CreateDBFromYAML creates the bbolt 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_DumpNormalizedYAML

func Z_ForTests_DumpNormalizedYAML(c *Manager) (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_GetGroupFile added in v0.5.1

func Z_ForTests_GetGroupFile() string

Z_ForTests_GetGroupFile returns the path to the group file.

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

func Z_ForTests_SetGroupFile

func Z_ForTests_SetGroupFile(groupFilePath string)

Z_ForTests_SetGroupFile sets the group file to the provided path.

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

Types

type GroupRow

type GroupRow struct {
	Name string
	GID  uint32
	UGID string
}

GroupRow represents a group in the database.

func NewGroupRow

func NewGroupRow(name string, gid uint32, ugid string) GroupRow

NewGroupRow creates a new GroupRow.

type GroupWithMembers

type GroupWithMembers struct {
	GroupRow `yaml:",inline"`
	Users    []string
}

GroupWithMembers is a GroupRow with a list of users that are members of the group.

type Manager

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

Manager is an abstraction to interact with the database.

func New

func New(dbDir string) (*Manager, error)

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

func (*Manager) AllGroupsWithMembers

func (m *Manager) AllGroupsWithMembers() (_ []GroupWithMembers, err error)

AllGroupsWithMembers returns all groups with their members.

func (*Manager) AllUsers

func (m *Manager) AllUsers() ([]UserRow, error)

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

func (*Manager) Close

func (m *Manager) Close() error

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

func (*Manager) DeleteUser

func (m *Manager) DeleteUser(uid uint32) error

DeleteUser removes the user from the database.

func (*Manager) GroupByID

func (m *Manager) GroupByID(gid uint32) (GroupRow, error)

GroupByID returns the group with the given group ID or a NoDataFoundError if no group was found.

func (*Manager) GroupByName

func (m *Manager) GroupByName(name string) (GroupRow, error)

GroupByName returns the group with the given name or a NoDataFoundError if no group was found.

func (*Manager) GroupByUGID

func (m *Manager) GroupByUGID(ugid string) (GroupRow, error)

GroupByUGID returns the group with the given UGID or a NoDataFoundError if no group was found.

func (*Manager) GroupWithMembersByID

func (m *Manager) GroupWithMembersByID(gid uint32) (_ GroupWithMembers, err error)

GroupWithMembersByID returns the group with the given group ID with a list of users that are members of the group.

func (*Manager) GroupWithMembersByName

func (m *Manager) GroupWithMembersByName(name string) (_ GroupWithMembers, err error)

GroupWithMembersByName returns the group with the given name with a list of users that are members of the group.

func (*Manager) RemoveUserFromGroup

func (m *Manager) RemoveUserFromGroup(uid, gid uint32) error

RemoveUserFromGroup removes a user from a group.

func (*Manager) UpdateBrokerForUser

func (m *Manager) UpdateBrokerForUser(username, brokerID string) error

UpdateBrokerForUser updates the last broker the user successfully authenticated with.

func (*Manager) UpdateUserEntry

func (m *Manager) UpdateUserEntry(user UserRow, authdGroups []GroupRow, localGroups []string) (err error)

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

func (*Manager) UserByID

func (m *Manager) UserByID(uid uint32) (UserRow, error)

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

func (*Manager) UserByName

func (m *Manager) UserByName(name string) (UserRow, error)

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

func (*Manager) UserGroups

func (m *Manager) UserGroups(uid uint32) ([]GroupRow, error)

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

func (*Manager) UserLocalGroups

func (m *Manager) 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 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.

func (NoDataFoundError) Is

func (NoDataFoundError) Is(target error) bool

Is makes this error insensitive to the key and table names.

type UserRow

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

	// BrokerID specifies the broker the user last successfully authenticated with.
	BrokerID string `yaml:"broker_id,omitempty"`
}

UserRow represents a user row in the database.

func NewUserRow

func NewUserRow(name string, uid, gid uint32, gecos, dir, shell string) UserRow

NewUserRow creates a new UserRow.

Directories

Path Synopsis
Package bbolt handles transaction with the deprecated bbolt database
Package bbolt handles transaction with the deprecated bbolt database

Jump to

Keyboard shortcuts

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