websettings

package
v5.28.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxSessionDuration = time.Hour * 24 * 30
	SessionGracePeriod = time.Minute * 10
)

Constants

Variables

View Source
var (
	DefaultShutdownGracePeriod = fxp.Ten
	DefaultReadTimeout         = fxp.Ten
	DefaultWriteTimeout        = fxp.Thirty
	DefaultIdleTimeout         = fxp.Sixty
	MinimumTimeout             = fxp.One
	MaximumTimeout             = fxp.SixHundred
	DefaultAddress             = "localhost:8422"
)

Minimums and defaults for web server settings.

Functions

func HashPassword

func HashPassword(in string) string

HashPassword hashes passwords.

func UserNameToKey

func UserNameToKey(name string) string

UserNameToKey converts a user name to a key.

Types

type Access

type Access struct {
	Dir      string `json:"dir"`
	ReadOnly bool   `json:"read_only"`
}

Access holds the configuration for a user's access to a directory (and all of its sub-paths) on the server.

type AccessWithKey

type AccessWithKey struct {
	Key string `json:"key"`
	Access
}

AccessWithKey holds the configuration for a user's access to a directory (and all of its sub-paths) on the server and also includes the key by which it is referenced.

func (*AccessWithKey) String

func (a *AccessWithKey) String() string

type Server

type Server struct {
	Enabled             bool    `json:"enabled"`
	Address             string  `json:"address"`
	CertFile            string  `json:"cert_file,omitempty"`
	KeyFile             string  `json:"key_file,omitempty"`
	ShutdownGracePeriod fxp.Int `json:"shutdown_grace_period"`
	ReadTimeout         fxp.Int `json:"read_timeout"`
	WriteTimeout        fxp.Int `json:"write_timeout"`
	IdleTimeout         fxp.Int `json:"idle_timeout"`
}

Server holds the settings for the embedded web server.

type Session

type Session struct {
	ID       tid.TID   `json:"id"`
	UserKey  string    `json:"user"`
	Issued   time.Time `json:"issued"`
	LastUsed time.Time `json:"last_used"`
}

Session holds a session's information.

func (*Session) Clone

func (s *Session) Clone() *Session

Clone creates a copy of this session.

func (*Session) Expired

func (s *Session) Expired() bool

Expired returns true if this session has expired.

type Settings

type Settings struct {
	Server
	// contains filtered or unexported fields
}

Settings holds the settings for the embedded web server.

func Default

func Default() *Settings

Default returns the default settings.

func NewSettingsFromFile

func NewSettingsFromFile(fileSystem fs.FS, filePath string) (*Settings, error)

NewSettingsFromFile loads new settings from a file.

func (*Settings) AccessList

func (s *Settings) AccessList(name string) map[string]Access

AccessList returns the access list for a user.

func (*Settings) CopyFrom

func (s *Settings) CopyFrom(other *Settings)

CopyFrom copies the settings from the other Settings to this Settings object. If 'other' is nil, the default settings are used.

func (*Settings) CreateSession

func (s *Settings) CreateSession(userName string) tid.TID

CreateSession creates a session.

func (*Settings) CreateUser

func (s *Settings) CreateUser(name, password string) bool

CreateUser creates a user. Returns true on success, false if a user by that name already exists.

func (*Settings) LookupSession

func (s *Settings) LookupSession(id tid.TID) (string, bool)

LookupSession looks up a session, updating its last used time and returning the user's name if found.

func (*Settings) LookupUserNameAndPassword

func (s *Settings) LookupUserNameAndPassword(name string) (actualName, hashedPassword string, ok bool)

LookupUserNameAndPassword looks up a user.

func (*Settings) MarshalJSON

func (s *Settings) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Settings) PruneSessions

func (s *Settings) PruneSessions()

PruneSessions removes expired sessions.

func (*Settings) RemoveSession

func (s *Settings) RemoveSession(id tid.TID)

RemoveSession removes a session.

func (*Settings) RemoveUser

func (s *Settings) RemoveUser(name string)

RemoveUser removes a user.

func (*Settings) RenameUser

func (s *Settings) RenameUser(oldName, newName string) bool

RenameUser renames a user. Returns true on success, false if the new name already exists or the user can't be found.

func (*Settings) Save

func (s *Settings) Save(filePath string) error

Save writes the settings to the file as JSON.

func (*Settings) SetAccessList

func (s *Settings) SetAccessList(name string, accessList map[string]Access)

SetAccessList sets the access list for a user.

func (*Settings) SetUserPassword

func (s *Settings) SetUserPassword(name, password string) bool

SetUserPassword sets the user's password. Returns true on success, false if the user can't be found.

func (*Settings) UnmarshalJSON

func (s *Settings) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Settings) Users

func (s *Settings) Users() []*User

Users returns a sorted list of users.

func (*Settings) Valid

func (s *Settings) Valid() bool

Valid returns true if the settings are valid.

func (*Settings) Validate

func (s *Settings) Validate()

Validate the settings.

type User

type User struct {
	Name           string            `json:"name"`
	HashedPassword string            `json:"hash"`
	AccessList     map[string]Access `json:"access_list"` // Key is the name the user sees and uses for the directory.
}

User holds information for a web user.

func (*User) AccessListWithKeys

func (u *User) AccessListWithKeys() []*AccessWithKey

AccessListWithKeys returns the access list with keys.

func (*User) Clone

func (u *User) Clone() *User

Clone creates a copy of this user.

func (*User) Key

func (u *User) Key() string

Key returns the key for this user.

func (*User) String

func (u *User) String() string

Jump to

Keyboard shortcuts

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