admin

package
v0.0.0-...-19f3e22 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccessDenied    = errors.New("Access denied")
	ErrAlreadyExists   = errors.New("Parameter already exists")
	ErrVersionNotMatch = errors.New("Version not match")
	ErrCommentRequired = errors.New("Comment required")
	ErrInvalidValue    = errors.New("Invalid value")
	ErrNotEmpty        = errors.New("Parameter has children")
	ErrNotFound        = errors.New("Parameter not found")
	ErrParentNotFound  = errors.New("Parent not found")
)
View Source
var ErrNoSuchVersion = errors.New("no such version")

Functions

func AddUserToGroup

func AddUserToGroup(ctx context.Context, group, user string) error

func ClearAccess

func ClearAccess(ctx context.Context, tx *sql.Tx, nodeID int) error

func CreateGroup

func CreateGroup(ctx context.Context, name string) error

func CreateParameter

func CreateParameter(ctx context.Context, path, contentType, value string, optSummary, optDescription, optNotification NullString, comment string) error

func DeleteAccess

func DeleteAccess(ctx context.Context, path, group string) error

func DeleteGroup

func DeleteGroup(ctx context.Context, name string) error

func DeleteParameter

func DeleteParameter(ctx context.Context, path string, version int, comment string) error

func DeleteServerStatus

func DeleteServerStatus(ctx context.Context, host string) error

func DeleteUserFromGroup

func DeleteUserFromGroup(ctx context.Context, group, user string) error

func Initialize

func Initialize(config AdminConfig)

func LogLastVersion

func LogLastVersion(ctx context.Context, tx *sql.Tx, path, comment string) error

func MoveParameter

func MoveParameter(ctx context.Context, path string, newPath string, symlink bool, version int, comment string) error

func NewHeaderAuthenticator

func NewHeaderAuthenticator(config HeaderAuthenticatorConfig) *headerAuthenticator

func NewMySQLAuthenticator

func NewMySQLAuthenticator(config MySQLAuthenticatorConfig) *mysqlAuthenticator

func RegisterRoutes

func RegisterRoutes(r *mux.Router)

func RootUsersOnly

func RootUsersOnly(next http.Handler) http.Handler

func SelectChildren

func SelectChildren(ctx context.Context, params []*ParameterWithChildren) error

func SelectGroupUsers

func SelectGroupUsers(ctx context.Context, group string) ([]string, error)

func SelectGroups

func SelectGroups(ctx context.Context) ([]string, error)

func SelectSubtree

func SelectSubtree(ctx context.Context, params []*ParameterWithSubtree) error

func SelectWithChildrenMulti

func SelectWithChildrenMulti(ctx context.Context, paths []string) (map[string]*ParameterWithChildren, error)

func SetAccess

func SetAccess(ctx context.Context, path, group string, rw NullBool) error

func SetParameter

func SetParameter(ctx context.Context, path string, version int, contentType string, value string, comment string) error

func SetParameterDescription

func SetParameterDescription(ctx context.Context, path string, summary, description string) error

func SetParameterNotification

func SetParameterNotification(ctx context.Context, path string, notification string) error

func UserCanEditAccess

func UserCanEditAccess(ctx context.Context, user, path string) (bool, error)

func UserIsRoot

func UserIsRoot(ctx context.Context, user string) (bool, error)

Types

type Access

type Access struct {
	Group      string   `json:"group"`
	Overridden bool     `json:"overridden"`
	RW         NullBool `json:"rw"`
}

func SelectAccess

func SelectAccess(ctx context.Context, path string) ([]Access, error)

type AdminConfig

type AdminConfig struct {
	Auth                 AuthenticatorConfig
	NotificationDatabase DatabaseConfig `yaml:"notification_database"`
}

type Authenticator

type Authenticator interface {
	Authenticate(req *http.Request) (string, error)
	SelectUsers(ctx context.Context, term string) ([]string, error)
}

type AuthenticatorConfig

type AuthenticatorConfig struct {
	Method     string
	MySQLAuth  MySQLAuthenticatorConfig  `yaml:",inline"`
	HeaderAuth HeaderAuthenticatorConfig `yaml:",inline"`
	Realm      string
}

type Avatar

type Avatar struct {
	URI       string            `json:"uri"`
	Domain    string            `json:"domain"`
	Gravatar  bool              `json:"gravatar"`
	Extension string            `json:"extension"`
	Rename    map[string]string `json:"rename,omitempty"`
	Link      *struct {
		URI    string            `json:"uri"`
		Rename map[string]string `json:"rename,omitempty"`
	} `json:"link,omitempty"`
}

type HeaderAuthenticatorConfig

type HeaderAuthenticatorConfig struct {
	Header string
	Secret string
}

type LogEntry

type LogEntry struct {
	ID          int        `json:"id"`
	NodeID      int        `json:"-"`
	Path        string     `json:"path"`
	Version     int        `json:"version"`
	ContentType string     `json:"mime"`
	Value       NullString `json:"data"`
	MTime       string     `json:"mtime"`
	Author      string     `json:"author"`
	Comment     NullString `json:"comment"`
	Deleted     bool       `json:"deleted"`
	RW          NullBool   `json:"rw"`
	Same        bool       `json:"same"`
}

func SelectLog

func SelectLog(ctx context.Context, filter LogFilter, lastID int) ([]LogEntry, error)

type LogFilter

type LogFilter struct {
	Path   string
	Author string
	Branch string
	From   string
	Till   string
	All    bool
}

type MySQLAuthenticatorConfig

type MySQLAuthenticatorConfig struct {
	DatabaseConfig `yaml:",inline"`
	Table          string
	NameField      string `yaml:"name_field"`
	PasswordField  string `yaml:"password_field"`
	Condition      string
}

type Parameter

type Parameter struct {
	ID                   int           `json:"-"`
	Name                 string        `json:"name"`
	ParentID             sql.NullInt64 `json:"-"`
	Path                 string        `json:"path"`
	Value                NullString    `json:"data"`
	ContentType          string        `json:"mime"`
	Summary              string        `json:"summary"`
	Description          string        `json:"description"`
	Version              int           `json:"version"`
	MTime                string        `json:"mtime"`
	Deleted              bool          `json:"-"`
	NumChildren          int           `json:"num_children"`
	AccessModified       bool          `json:"access_modified"`
	RW                   NullBool      `json:"rw"`
	Notification         string        `json:"notification"`
	NotificationModified bool          `json:"notification_modified"`
}

func SearchParameters

func SearchParameters(ctx context.Context, term string) ([]Parameter, error)

func SelectParameter

func SelectParameter(ctx context.Context, path string) (*Parameter, error)
func SelectParameterFollowingSymlink(ctx context.Context, path string) (*Parameter, error)
func SelectParameterResolvingSymlink(ctx context.Context, path string) (*Parameter, error)

func (*Parameter) WithChildren

func (p *Parameter) WithChildren(ctx context.Context) (*ParameterWithChildren, error)

func (*Parameter) WithSubtree

func (p *Parameter) WithSubtree(ctx context.Context) (*ParameterWithSubtree, error)

type ParameterWithChildren

type ParameterWithChildren struct {
	Parameter
	Children []Parameter `json:"children"`
}

func (*ParameterWithChildren) AddChild

func (p *ParameterWithChildren) AddChild(child Parameter)

func (*ParameterWithChildren) GetParameter

func (p *ParameterWithChildren) GetParameter() *Parameter

type ParameterWithDescendants

type ParameterWithDescendants interface {
	GetParameter() *Parameter
	AddChild(Parameter)
}

type ParameterWithSubtree

type ParameterWithSubtree struct {
	Parameter
	Children []ParameterWithSubtree `json:"children"`
}

func (*ParameterWithSubtree) AddChild

func (p *ParameterWithSubtree) AddChild(child Parameter)

func (*ParameterWithSubtree) GetParameter

func (p *ParameterWithSubtree) GetParameter() *Parameter

type ServerStatus

type ServerStatus struct {
	Host        string     `json:"host"`
	MTime       NullString `json:"mtime"`
	Online      string     `json:"online"`
	Package     string     `json:"package"`
	MTimeAlert  bool       `json:"mtime_alert"`
	OnlineAlert bool       `json:"online_alert"`
}

func SelectServerStatus

func SelectServerStatus(ctx context.Context, sort string) ([]ServerStatus, error)

type UIConfig

type UIConfig struct {
	Avatar *Avatar `json:"avatar,omitempty"`
}

Jump to

Keyboard shortcuts

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