feat(11-04): add the websockets health, VAPID key and test-push commands
- centrifugo.Client.Info probes the info API method; an error body fails - websockets:health ports CentrifugoHealthCheck: exits 1 without an API key or when the probe fails, prints the Setting/Value table otherwise - websockets:generate-vapid-keys prints a new P-256 pair, shows configured keys only truncated, and --update persists them to overrides.yaml - websockets:test-push reads subscriptions from an app-published SubscriptionSource, refuses to send while push is disabled and sends one encrypted push per subscription - no command prints a configured private key or the Centrifugo API key - flare and lighthouse READMEs document the CLI commands
This commit is contained in:
69
modules/lighthouse/centrifugo/commands.go
Normal file
69
modules/lighthouse/centrifugo/commands.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package centrifugo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/bonfire"
|
||||
)
|
||||
|
||||
// HealthCommandName is the name of the Centrifugo health check command.
|
||||
const HealthCommandName = "websockets:health"
|
||||
|
||||
// errHealthFailed is returned by the health command after it has printed
|
||||
// why the check failed, so the binary exits 1.
|
||||
var errHealthFailed = errors.New(HealthCommandName + ": check failed")
|
||||
|
||||
// Commands returns the Centrifugo console commands for an application
|
||||
// binary: the HealthCommandName check. An application appends them to the
|
||||
// commands its plugin returns from Commands.
|
||||
func Commands(app *backpack.App) []bonfire.Command {
|
||||
return []bonfire.Command{healthCommand(app)}
|
||||
}
|
||||
|
||||
// healthCommand ports the WinterCMS CentrifugoHealthCheck command. The
|
||||
// WinterCMS command only read the local configuration; this one also calls
|
||||
// the Centrifugo info API, so a wrong URL or key fails the check. The API
|
||||
// key is never printed.
|
||||
func healthCommand(app *backpack.App) bonfire.Command {
|
||||
return bonfire.Command{
|
||||
Name: HealthCommandName,
|
||||
Description: "Check Centrifugo connection health",
|
||||
Run: func(ctx context.Context, _ bonfire.Input, out bonfire.Output) error {
|
||||
var cfg Config
|
||||
if app != nil {
|
||||
cfg = LoadConfig(app.Config)
|
||||
} else {
|
||||
cfg = LoadConfig(nil)
|
||||
}
|
||||
client := NewClient(cfg, nil)
|
||||
if !client.Enabled() {
|
||||
out.Error("Centrifugo not configured (API key missing)")
|
||||
out.Println("Set SUMMER_REALTIME__CENTRIFUGO__API_KEY in the environment")
|
||||
return errHealthFailed
|
||||
}
|
||||
out.Info("Checking Centrifugo connection...")
|
||||
out.Println("API URL: " + cfg.APIURL)
|
||||
if _, err := client.Info(ctx); err != nil {
|
||||
out.Error("Connection check failed: " + err.Error())
|
||||
return errHealthFailed
|
||||
}
|
||||
info := client.DebugInfo()
|
||||
out.Success("Configuration OK")
|
||||
out.Table([]string{"Setting", "Value"}, [][]string{
|
||||
{"API URL", info.APIURL},
|
||||
{"Enabled", yesNo(info.Enabled)},
|
||||
{"API Key Set", yesNo(info.APIKeySet)},
|
||||
})
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func yesNo(b bool) string {
|
||||
if b {
|
||||
return "Yes"
|
||||
}
|
||||
return "No"
|
||||
}
|
||||
Reference in New Issue
Block a user