database

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserNotFound is returned when a user is not found.
	ErrUserNotFound = errors.New("user not found")
	// ErrUserAlreadyExists is returned when a user already exists.
	ErrUserAlreadyExists = errors.New("user already exists")
	// ErrVLANNotFound is returned when a VLAN is not found.
	ErrVLANNotFound = errors.New("vlan not found")
	// ErrVLANAlreadyExists is returned when a VLAN already exists.
	ErrVLANAlreadyExists = errors.New("vlan already exists")
	// ErrDefaultVLANNotFound is returned when the default VLAN is not found.
	ErrDefaultVLANNotFound = errors.New("default vlan not found")
	// ErrDefaultVLANAlreadyExists is returned when the default VLAN already exists.
	ErrDefaultVLANAlreadyExists = errors.New("default vlan already exists")
	// ErrBlockedUserNotFound is returned when a blocked user is not found.
	ErrBlockedUserNotFound = errors.New("blocked user not found")
	// ErrUserAlreadyBlocked is returned when a user is already blocked.
	ErrUserAlreadyBlocked = errors.New("user already blocked")
)

Functions

This section is empty.

Types

type BlockedUser

type BlockedUser struct {
	Username string `json:"username" yaml:"username"`
}

type Database

type Database interface {
	// GetVLANs returns all the VLANs.
	GetVLANs() ([]VLAN, error)
	// GetVLAN returns a VLAN by its ID.
	GetVLAN(id string) (VLAN, error)
	// CreateVLAN creates a new VLAN.
	CreateVLAN(v VLAN) error
	// UpdateVLAN updates a VLAN.
	UpdateVLAN(v VLAN) error
	// DeleteVLAN deletes a VLAN by its ID.
	DeleteVLAN(id string) error
	// GetDefaultVLAN returns the default VLAN.
	GetDefaultVLAN() (VLAN, error)

	// GetUsers returns all the users.
	GetUsers() ([]User, error)
	// GetUser returns a user by its username.
	GetUser(username string) (User, error)
	// GetUserByDescription returns a user by its description.
	GetUserByDescription(description string) (User, error)
	// CreateUser creates a new user.
	CreateUser(u User) error
	// UpdateUser updates a user.
	UpdateUser(u User) error
	// DeleteUser deletes a user by its username.
	DeleteUser(username string) error

	// GetBlockedUsers returns all the blocked users.
	GetBlockedUsers() ([]BlockedUser, error)
	// IsUserBlocked checks if a user is blocked by its username.
	IsUserBlocked(username string) (bool, error)
	// BlockUser blocks a user by its username.
	BlockUser(username string) error
	// UnblockUser unblocks a user by its username.
	UnblockUser(username string) error

	// Init initializes the database.
	Open(ctx context.Context) error
	// Close closes the database.
	Close(ctx context.Context) error
}

Database is the interface that wraps the basic database operations.

type User

type User struct {
	Username    string `json:"username"              yaml:"username"`
	Password    string `json:"password"              yaml:"password"`
	VlanID      string `json:"vlan"                  yaml:"vlan"`
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
}

type VLAN

type VLAN struct {
	ID               string `json:"id"                         yaml:"id"`
	Name             string `json:"name"                       yaml:"name"`
	Default          bool   `json:"default,omitempty"          yaml:"default,omitempty"`
	TunnelType       uint32 `json:"tunnelType,omitempty"       yaml:"tunnelType,omitempty"`
	TunnelMediumType uint32 `json:"tunnelMediumType,omitempty" yaml:"tunnelMediumType,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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