56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
// Package system serves the bootstrap values the binary reads before the
|
|
// database is reachable, read-only, and instance health.
|
|
package system
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"net/http"
|
|
"sync"
|
|
|
|
"github.com/danielgtaylor/huma/v2"
|
|
|
|
"github.com/samcharles93/archie-core/internal/platform/httpapi"
|
|
"github.com/samcharles93/archie-core/modules/governance"
|
|
)
|
|
|
|
// Bootstrap is what the binary loaded from config.toml, reduced to values safe
|
|
// to show: no connection URL and no secret.
|
|
type Bootstrap struct {
|
|
Listen string `json:"listen"`
|
|
Database string `json:"database_host"`
|
|
Schemas int `json:"schemas"`
|
|
AdminPrefix string `json:"admin_token_hash_prefix"`
|
|
AdminSet bool `json:"admin_token_set"`
|
|
Sealing bool `json:"sealing_identity_set"`
|
|
}
|
|
|
|
// Module serves the bootstrap view and instance health.
|
|
type Module struct {
|
|
mu sync.RWMutex
|
|
bootstrap Bootstrap
|
|
sources Sources
|
|
log *slog.Logger
|
|
}
|
|
|
|
// New returns the system module.
|
|
func New(b Bootstrap, log *slog.Logger) *Module {
|
|
return &Module{bootstrap: b, log: log}
|
|
}
|
|
|
|
// Register adds the system API.
|
|
func (m *Module) Register(api huma.API) {
|
|
tags := []string{"System"}
|
|
httpapi.Register(api, httpapi.AdminAuthorized(governance.ActionRead, governance.KindInstance), huma.Operation{
|
|
OperationID: "get-bootstrap", Method: http.MethodGet, Path: "/api/system/bootstrap",
|
|
Summary: "Get the bootstrap values, which only the config file sets", Tags: tags,
|
|
}, m.getBootstrap)
|
|
m.registerHealth(api)
|
|
}
|
|
|
|
func (m *Module) getBootstrap(_ context.Context, _ *struct{}) (*httpapi.Reply[Bootstrap], error) {
|
|
m.mu.RLock()
|
|
defer m.mu.RUnlock()
|
|
return httpapi.OK(m.bootstrap), nil
|
|
}
|