Documentation
¶
Overview ¶
Package bootstrap loads the runtime configuration at startup and reloads a subsystem's part of it when an administrator changes its settings: it runs the database migration, seeds the first administrator, provisions the node secret and publishes each subsystem's stored settings (site, node, email, device, invite, verification, subscription, registration, mobile, currency and Telegram) into the process's runtime snapshot.
Index ¶
- Constants
- Variables
- func Currency(ctx context.Context, deps *Dependencies) error
- func Device(ctx context.Context, deps *Dependencies) error
- func Email(ctx context.Context, deps *Dependencies) error
- func Invite(ctx context.Context, deps *Dependencies) error
- func Migrate(ctx context.Context, deps *Dependencies) error
- func Mobile(ctx context.Context, deps *Dependencies) error
- func Node(ctx context.Context, deps *Dependencies) error
- func NodeSecret(ctx context.Context, deps *Dependencies) error
- func Register(ctx context.Context, deps *Dependencies) error
- func Reload(ctx context.Context, deps *Dependencies, subsystem Subsystem) error
- func ReloadAll(ctx context.Context, deps *Dependencies) error
- func Site(ctx context.Context, deps *Dependencies) error
- func Start(ctx context.Context, deps *Dependencies) error
- func Subscribe(ctx context.Context, deps *Dependencies) error
- func Telegram(ctx context.Context, deps *Dependencies) error
- func Verify(ctx context.Context, deps *Dependencies) error
- func WarnDefaultAdminPassword(ctx context.Context, deps *Dependencies)
- type Administrators
- type Dependencies
- type LoginMethods
- type NodeSettings
- type Settings
- type SettingsTransactor
- type Subsystem
- type TelegramNotifications
Constants ¶
const LegacyDefaultNodeSecret = "12345678"
LegacyDefaultNodeSecret is the node secret the original seed data shipped. The value is public knowledge, so an installation still carrying it serves the node API — which hands out every user's subscription uuid — to anyone.
Variables ¶
var ErrUnknownSubsystem = errors.New("unknown runtime subsystem")
ErrUnknownSubsystem is returned by Reload for a name no subsystem answers to, so a misspelt reload request fails loudly instead of doing nothing.
Functions ¶
func Currency ¶
func Currency(ctx context.Context, deps *Dependencies) error
Currency loads the site currency and resets billing's cached exchange rate to zero; the exchange-rate task refreshes it when an API key is configured.
func Device ¶
func Device(ctx context.Context, deps *Dependencies) error
Device loads the device login settings. A stored configuration that does not decode fails the load: applying the zero value instead would silently switch device request signing off.
func Email ¶
func Email(ctx context.Context, deps *Dependencies) error
Email loads the email sign-in and sending settings: the provider, its configuration, and the notification templates and subjects.
func Invite ¶
func Invite(ctx context.Context, deps *Dependencies) error
Invite loads the referral settings.
func Migrate ¶
func Migrate(ctx context.Context, deps *Dependencies) error
Migrate brings the database schema up to date and seeds the configured first administrator into a database that holds no account yet. The seed runs on every start, not only after a migration that changed the schema: identity's CreateInitialAdministrator does nothing once an account exists, and a seed that failed on the first start (the schema was current from then on) used to leave a panel without any administrator until someone fixed the database by hand.
func Mobile ¶
func Mobile(ctx context.Context, deps *Dependencies) error
Mobile loads the phone sign-in and SMS settings: the provider, its configuration and the area-code whitelist.
func Node ¶
func Node(ctx context.Context, deps *Dependencies) error
Node loads the node settings and the traffic multiplier. Everything is read before anything is published, so a failed load keeps the previous node configuration and multiplier manager.
func NodeSecret ¶
func NodeSecret(ctx context.Context, deps *Dependencies) error
NodeSecret provisions a random node secret when the database does not carry one yet, so a fresh installation never serves the node API with a guessable credential. It has to run after Migrate, which seeds the empty row, and before Node, which copies the value into the runtime config.
An installation still holding LegacyDefaultNodeSecret is only reported, never rotated: every node was configured with that secret, so rotating it here would silently cut them off. The operator rotates it from the admin panel and reconfigures the nodes in the same window.
func Register ¶
func Register(ctx context.Context, deps *Dependencies) error
Register loads the registration settings, the trial plan among them.
func Reload ¶
func Reload(ctx context.Context, deps *Dependencies, subsystem Subsystem) error
Reload refreshes the subsystem changed by an administrator. Startup-only migration and node-secret provisioning are deliberately excluded. A failure is logged and returned, and the subsystem keeps its previous configuration.
func ReloadAll ¶ added in v1.21.0
func ReloadAll(ctx context.Context, deps *Dependencies) error
ReloadAll refreshes every subsystem, in startup order, for a restart of the HTTP server: the routes are rebuilt on the reloaded settings. Like Reload it leaves migration and node-secret provisioning, startup work, out, and the first failure is returned with that subsystem's previous configuration kept.
func Site ¶
func Site(ctx context.Context, deps *Dependencies) error
Site loads the site settings: name, host, logo and the other branding.
func Start ¶
func Start(ctx context.Context, deps *Dependencies) error
Start loads startup state in dependency order. Migration and node-secret provisioning must precede every node configuration read. The first failure stops startup and is returned, so the caller fails fast instead of serving with a partially loaded configuration.
func Subscribe ¶
func Subscribe(ctx context.Context, deps *Dependencies) error
Subscribe loads the subscription delivery settings.
func Telegram ¶
func Telegram(ctx context.Context, deps *Dependencies) error
Telegram (re)initialises the bot from the stored configuration. On failure it returns without touching the running state, so a transient error during re-initialisation leaves the previous bot working instead of none at all.
A failed read of the stored configuration fails the load like every other subsystem. A missing telegram method or a stored configuration that does not decode is only logged: the bot is optional, so the panel starts, or keeps its running bot, without it. Failures talking to the Telegram API are only logged as well: the panel has to start and reload while Telegram is unreachable.
func Verify ¶
func Verify(ctx context.Context, deps *Dependencies) error
Verify loads the captcha and the verification-code settings. Both are read before either is published, so a failed read keeps the previous pair.
func WarnDefaultAdminPassword ¶ added in v1.21.0
func WarnDefaultAdminPassword(ctx context.Context, deps *Dependencies)
WarnDefaultAdminPassword flags administrators that still sign in with the password older releases seeded, which anyone can look up.
Types ¶
type Administrators ¶ added in v1.21.0
type Administrators interface {
CreateInitialAdministrator(ctx context.Context, email, password string) (bool, error)
FindAdministratorsWithPassword(ctx context.Context, password string) ([]*user.User, error)
}
Administrators seeds the first administrator of a database without accounts and finds the administrators who sign in with a given password.
type Dependencies ¶
type Dependencies struct {
Config func() config.Config
UpdateRuntime func(func(*config.Runtime))
// Settings is the platform kernel's system-settings table the loaders
// read, and SettingsTx runs the node-secret provisioning in one platform
// transaction; the composition root adapts the shared store to both.
Settings Settings
SettingsTx SettingsTransactor
ExchangeRate *billing.CurrencyRateCache
Notification TelegramNotifications
SetTelegramBot func(*tgbot.Bot)
SetNodeMultiplierManager func(*network.MultiplierManager)
// LoginMethods and Administrators are the identity module's part: the
// stored authentication-method settings the loaders publish, and the
// administrator accounts Migrate seeds and WarnDefaultAdminPassword
// checks. The identity facade provides both.
LoginMethods LoginMethods
Administrators Administrators
}
Dependencies is the startup/reconfiguration boundary. It owns only mutable runtime configuration and the services needed to load or publish it.
type LoginMethods ¶ added in v1.21.0
type LoginMethods interface {
FindLoginMethod(ctx context.Context, method string) (*auth.Auth, error)
}
LoginMethods reads the stored configuration of an authentication method, such as "email" or "telegram".
type NodeSettings ¶ added in v1.21.0
type NodeSettings interface {
GetNodeConfig(ctx context.Context) ([]*system.System, error)
UpdateValueByCategoryKey(ctx context.Context, category, key, value string, valueType ...string) error
}
NodeSettings is the server-settings access of the node-secret provisioning inside its transaction.
type Settings ¶ added in v1.21.0
type Settings interface {
GetSiteConfig(ctx context.Context) ([]*system.System, error)
GetInviteConfig(ctx context.Context) ([]*system.System, error)
GetRegisterConfig(ctx context.Context) ([]*system.System, error)
GetSubscribeConfig(ctx context.Context) ([]*system.System, error)
GetVerifyConfig(ctx context.Context) ([]*system.System, error)
GetVerifyCodeConfig(ctx context.Context) ([]*system.System, error)
GetNodeConfig(ctx context.Context) ([]*system.System, error)
GetCurrencyConfig(ctx context.Context) ([]*system.System, error)
FindNodeMultiplierConfig(ctx context.Context) (*system.System, error)
Insert(ctx context.Context, data *system.System) error
}
Settings is the system-settings table as the loaders read it: one read per settings category, the node multiplier setting, and the insert that seeds the multiplier setting on first start.
type SettingsTransactor ¶ added in v1.21.0
type SettingsTransactor interface {
InSettingsTx(ctx context.Context, fn func(NodeSettings) error) error
}
SettingsTransactor runs fn in one platform transaction. Reads inside it go to the database rather than the settings cache.
type Subsystem ¶ added in v1.21.0
type Subsystem string
Subsystem names a runtime configuration subsystem an administrator can reload. The values are the names the admin settings handlers pass through their reinitialize callback.
const ( SubsystemSite Subsystem = "site" SubsystemNode Subsystem = "node" SubsystemEmail Subsystem = "email" SubsystemDevice Subsystem = "device" SubsystemInvite Subsystem = "invite" SubsystemVerify Subsystem = "verify" SubsystemSubscribe Subsystem = "subscribe" SubsystemRegister Subsystem = "register" SubsystemMobile Subsystem = "mobile" SubsystemCurrency Subsystem = "currency" SubsystemTelegram Subsystem = "telegram" )
The reloadable subsystems.
type TelegramNotifications ¶ added in v1.21.0
type TelegramNotifications interface {
HandleTelegramUpdate(ctx context.Context, update *models.Update)
PublishTelegramCommands(ctx context.Context) error
SetupTelegramGroup(ctx context.Context) error
}
TelegramNotifications is the notification module's side of the Telegram bot: it handles the updates the long-polling loop receives, publishes the bot's command menu and sets up the administrators' group.