Documentation
¶
Overview ¶
Package settings reads and writes the instance settings stored in the settings table. Every key has a typed accessor with a default, values are cached in memory until the next Set, and Set validates the value, audits the change and appends a settings.updated event in one transaction.
Index ¶
- Constants
- Variables
- func DeadlineValue(t *time.Time) any
- func Keys() []string
- func Validate(key string, value any) error
- func WindowEnd(now time.Time, hours int) *time.Time
- type Store
- func (s *Store) AlertRenotifyS() int
- func (s *Store) AllowedCIDRs() []netip.Prefix
- func (s *Store) CloseRegistration(ctx context.Context, actor audit.Actor) error
- func (s *Store) DefaultRetentionDays() *int
- func (s *Store) DiskReserveBytes() int64
- func (s *Store) InstanceName() string
- func (s *Store) Invalidate()
- func (s *Store) MDNSEnabled() bool
- func (s *Store) PushPayload() string
- func (s *Store) RegistrationClosesAt() *time.Time
- func (s *Store) RegistrationOpen(now time.Time) bool
- func (s *Store) ReopenRegistration(ctx context.Context, actor audit.Actor, now time.Time) error
- func (s *Store) SessionIdleDays() int
- func (s *Store) Set(ctx context.Context, actor audit.Actor, key string, value any) error
- func (s *Store) SetMany(ctx context.Context, actor audit.Actor, values map[string]json.RawMessage) error
- func (s *Store) SetManyAt(ctx context.Context, actor audit.Actor, now time.Time, ...) error
- func (s *Store) SetTx(tx *store.Tx, actor audit.Actor, key string, value any) error
- func (s *Store) UploadMaxBytes() int64
- func (s *Store) UserQuotaBytes() int64
- func (s *Store) Values() Values
- func (s *Store) WebPushEnabled() bool
- func (s *Store) WebResetEnabled() bool
- type Values
Constants ¶
const ( KeyInstanceName = "instance_name" KeyOpenRegistration = "open_registration" KeyRegistrationWindowH = "registration_window_hours" KeyOpenRegistrationEnds = "open_registration_until" KeyUploadMaxBytes = "upload_max_bytes" KeyUserQuotaBytes = "user_quota_bytes" KeyDiskReserveBytes = "disk_reserve_bytes" KeyDefaultRetentionDays = "default_retention_days" KeyWebPushEnabled = "web_push_enabled" KeyPushPayload = "push_payload" KeyAllowedCIDRs = "allowed_cidrs" KeySessionIdleDays = "session_idle_days" KeyAlertRenotifyS = "alert_renotify_s" KeyMDNSEnabled = "mdns_enabled" KeyWebResetEnabled = "web_reset_enabled" )
Setting keys.
const ( PushMinimal = "minimal" PushFull = "full" )
Push payload modes.
const ( MaxUploadBytes = 2 << 30 MaxInstanceNameLen = 64 MaxSessionIdleDays = 90 MaxRetentionDays = 3650 // MaxRegistrationWindowHours is one year. MaxRegistrationWindowHours = 8760 )
Limits enforced by Set.
Variables ¶
var ErrInvalid = errors.New("invalid setting")
ErrInvalid is wrapped by every error that rejects a key or value.
Functions ¶
func DeadlineValue ¶ added in v0.2.0
DeadlineValue renders a sign-up deadline as the value to store for open_registration_until; nil is JSON null.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store gives typed, cached access to the settings table.
func (*Store) AlertRenotifyS ¶
AlertRenotifyS is the default alert renotify interval in seconds.
func (*Store) AllowedCIDRs ¶
AllowedCIDRs returns the extra source ranges admitted besides private addresses. The slice is shared: do not modify it.
func (*Store) CloseRegistration ¶ added in v0.2.0
CloseRegistration switches sign-up off and clears the deadline.
func (*Store) DefaultRetentionDays ¶
DefaultRetentionDays is the default channel retention; nil keeps forever.
func (*Store) DiskReserveBytes ¶
DiskReserveBytes is the free space uploads must leave.
func (*Store) InstanceName ¶
InstanceName is the display name of this server.
func (*Store) Invalidate ¶
func (s *Store) Invalidate()
Invalidate drops the cache; the next accessor reloads from the database. Set calls it after commit; call it after changing the table another way.
func (*Store) MDNSEnabled ¶
MDNSEnabled reports whether mDNS advertising is on.
func (*Store) PushPayload ¶
PushPayload is PushMinimal or PushFull.
func (*Store) RegistrationClosesAt ¶ added in v0.2.0
RegistrationClosesAt is the sign-up deadline; nil when sign-up is switched off or has no deadline. It does not look at the clock: a deadline that has passed is still returned, so callers check RegistrationOpen too.
func (*Store) RegistrationOpen ¶ added in v0.2.0
RegistrationOpen reports whether anyone may self-register at now: the switch is on and the deadline, if any, has not passed. Every sign-up check goes through here.
func (*Store) ReopenRegistration ¶ added in v0.2.0
ReopenRegistration switches sign-up on and starts a new window at now.
func (*Store) SessionIdleDays ¶
SessionIdleDays is the idle expiry of sessions in days.
func (*Store) Set ¶
Set validates value for key and stores it, audits the change and appends a settings.updated event, all in one transaction.
func (*Store) SetMany ¶
func (s *Store) SetMany(ctx context.Context, actor audit.Actor, values map[string]json.RawMessage) error
SetMany validates every entry first and then stores all of them in one transaction, so a rejected value changes nothing. Each key is audited.
func (*Store) SetManyAt ¶ added in v0.2.0
func (s *Store) SetManyAt(ctx context.Context, actor audit.Actor, now time.Time, values map[string]json.RawMessage) error
SetManyAt is SetMany plus the sign-up deadline rules, all in one transaction. Switching open_registration on starts a new window (now plus registration_window_hours), switching it off clears the deadline, and changing registration_window_hours while sign-up is open re-bases the deadline on now. open_registration_until is not a patchable key: callers reject it before this point.
func (*Store) SetTx ¶
SetTx is Set inside the caller's transaction (first-run setup uses it). The cache is dropped after the transaction commits.
func (*Store) UploadMaxBytes ¶
UploadMaxBytes is the per-file upload limit.
func (*Store) UserQuotaBytes ¶
UserQuotaBytes is the per-user storage quota; 0 means unlimited.
func (*Store) Values ¶
Values returns every setting. Rows that fail validation (edited by hand) fall back to the default; if the table cannot be read the defaults are returned and nothing is cached.
func (*Store) WebPushEnabled ¶
WebPushEnabled reports whether Web Push is switched on.
func (*Store) WebResetEnabled ¶
WebResetEnabled reports whether the admin UI may reset the instance.
type Values ¶
type Values struct {
InstanceName string
OpenRegistration bool
RegistrationWindowH int // hours sign-up stays open once switched on; 0 = no deadline
OpenRegistrationEnds *time.Time // nil = no deadline
UploadMaxBytes int64
UserQuotaBytes int64 // 0 = unlimited
DiskReserveBytes int64
DefaultRetentionDays *int // nil = keep forever
WebPushEnabled bool
PushPayload string
AllowedCIDRs []netip.Prefix
SessionIdleDays int
AlertRenotifyS int
MDNSEnabled bool
WebResetEnabled bool
}
Values is a snapshot of every setting with defaults applied.