feat(archiemessaging): verify update reports against archied's presence and restore release announcements
This commit is contained in:
1 parent
32eded1db8
commit
164c40f37b
5 files changed
+68
-33
No files matched your search
@@ -0,0 +1,9 @@
|
||||
package configtemplate
|
||||
|
||||
import _ "embed"
|
||||
|
||||
// Changelog is the verbatim contents of CHANGELOG.md, so a binary carries the
|
||||
// release notes for the version it was built as.
|
||||
//
|
||||
//go:embed CHANGELOG.md
|
||||
var Changelog string
|
||||
@@ -28,6 +28,9 @@ type deps struct {
|
||||
// ChannelStatus is where the service publishes channel lifecycle for the
|
||||
// dashboard. Optional: nil leaves the report in-process only.
|
||||
ChannelStatus storecontract.ChannelStatusStore
|
||||
// Presence reads which version each service reports for itself, to verify
|
||||
// update reports. Nil leaves them unverified.
|
||||
Presence storecontract.PresenceStore
|
||||
Config ResolvedConfig
|
||||
Log *slog.Logger
|
||||
Chat messaging.ChatContract
|
||||
@@ -180,7 +183,7 @@ func composeTelegram(ctx context.Context, d deps) (*channelInstance, error) {
|
||||
}
|
||||
tg := telegram.New(cfg.TelegramToken, cfg.Telegram.AllowedUserIDs, d.Log)
|
||||
tg.Settings = d.Settings
|
||||
configureTelegram(ctx, tg, cfg, d.Chat, d.Secrets, d.Log)
|
||||
configureTelegram(ctx, tg, cfg, d)
|
||||
if err := tg.ValidateConfig(telegramValidateConfigMap(cfg.Telegram)); err != nil {
|
||||
return nil, fmt.Errorf("chat.telegram config invalid: %w", err)
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ func Run(ctx context.Context, o Options) error {
|
||||
// channelStatusStore is the same client, held where compose can reach it: the
|
||||
// channel report is published to the store this process already dials.
|
||||
var channelStatusStore storecontract.ChannelStatusStore
|
||||
var presenceStore storecontract.PresenceStore
|
||||
// settingsSource and applyReporter are the live channel-settings path: the
|
||||
// control-plane client to re-read the resource, and the record of what this
|
||||
// process applied. Both stay nil without a State Store, which leaves the
|
||||
@@ -78,7 +79,7 @@ func Run(ctx context.Context, o Options) error {
|
||||
return fmt.Errorf("resolve database webhook secret: %w", settingsErr)
|
||||
}
|
||||
settings = messaging.NewSettingsCommand(messagingControlPlane{client: stateStore.ControlPlane()}).WithIdentities(stateStore)
|
||||
channelStatusStore = stateStore
|
||||
channelStatusStore, presenceStore = stateStore, stateStore
|
||||
settingsSource, applyReporter, appliedVersion = controlPlaneClient, reporter, channelVersion
|
||||
}
|
||||
|
||||
@@ -90,6 +91,7 @@ func Run(ctx context.Context, o Options) error {
|
||||
srv, err := compose(ctx, deps{
|
||||
Secrets: secrets,
|
||||
ChannelStatus: channelStatusStore,
|
||||
Presence: presenceStore,
|
||||
Config: cfg,
|
||||
Log: log,
|
||||
Chat: chat,
|
||||
|
||||
@@ -8,35 +8,66 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
configtemplate "github.com/samcharles93/archie-core"
|
||||
"github.com/samcharles93/archie-core/internal/buildinfo"
|
||||
"github.com/samcharles93/archie-core/internal/channels/telegram"
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
"github.com/samcharles93/archie-core/internal/domain/presence"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/installtype"
|
||||
"github.com/samcharles93/archie-core/internal/releaseannounce"
|
||||
"github.com/samcharles93/archie-core/internal/releaseupdate"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
)
|
||||
|
||||
// configureTelegram wires the operator seams telegram.Gateway leaves to its
|
||||
// composition root. RunningVersions is supplied here from this process's own
|
||||
// build stamp; see messagingRunningVersions.
|
||||
func configureTelegram(ctx context.Context, g *telegram.Gateway, cfg ResolvedConfig, chat messaging.ChatContract, secrets *secret.Registry, log *slog.Logger) {
|
||||
g.Version = gatewayVersionReporter(ctx, chat, cfg.Options.DependencyTimeout)
|
||||
// composition root.
|
||||
func configureTelegram(ctx context.Context, g *telegram.Gateway, cfg ResolvedConfig, d deps) {
|
||||
g.Version = gatewayVersionReporter(ctx, d.Chat, cfg.Options.DependencyTimeout)
|
||||
g.SetShowToolCalls(cfg.ShowToolCalls)
|
||||
g.Reload = telegramReloader(cfg.Options, secrets, log)
|
||||
g.RunningVersions = messagingRunningVersions
|
||||
g.Reload = telegramReloader(cfg.Options, d.Secrets, d.Log)
|
||||
g.RunningVersions = runningVersions(ctx, d.Presence, cfg.Options.DependencyTimeout)
|
||||
|
||||
if updates := updateService(cfg); updates != nil {
|
||||
g.Updates = updates
|
||||
}
|
||||
if cfg.WorkDir != "" {
|
||||
g.UpdateReportPath = identityStatePath(cfg.WorkDir, "update-report", cfg.BotUser)
|
||||
g.ReleaseAnnouncements = &releaseannounce.Announcer{
|
||||
StatePath: identityStatePath(cfg.WorkDir, "release-announcements", cfg.BotUser),
|
||||
Components: []releaseannounce.Component{
|
||||
{ID: "archie", Label: "ARCHIE", Version: buildinfo.Version, Changelog: configtemplate.Changelog},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// messagingRunningVersions reports this process's own build version for
|
||||
// update verification.
|
||||
func messagingRunningVersions() map[string]string {
|
||||
return map[string]string{releaseupdate.ComponentDaemon: buildinfo.Version}
|
||||
// runningVersions reports the daemon version archied's own presence record
|
||||
// carries, so an update report is checked against what archied compiled in
|
||||
// rather than this process's build. A down or unreachable daemon, or a
|
||||
// missing store, leaves the daemon unverified. The agent stays unverified:
|
||||
// only archied observes it.
|
||||
func runningVersions(ctx context.Context, store storecontract.PresenceStore, timeout time.Duration) func() map[string]string {
|
||||
return func() map[string]string {
|
||||
if store == nil {
|
||||
return nil
|
||||
}
|
||||
if timeout <= 0 {
|
||||
timeout = 5 * time.Second
|
||||
}
|
||||
callCtx, cancel := context.WithTimeout(ctx, timeout)
|
||||
defer cancel()
|
||||
records, err := store.ListPresence(callCtx)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
for _, service := range presence.Mesh(records, time.Now()) {
|
||||
if service.Service == presence.Daemon && service.State != presence.StateDown {
|
||||
return map[string]string{releaseupdate.ComponentDaemon: service.Version}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// gatewayVersionReporter renders /version from the Gateway's build info,
|
||||
|
||||
@@ -22,10 +22,11 @@ type Announcer struct {
|
||||
}
|
||||
|
||||
type Component struct {
|
||||
ID string
|
||||
Label string
|
||||
Version string
|
||||
ChangelogPath string
|
||||
ID string
|
||||
Label string
|
||||
Version string
|
||||
// Changelog is the CHANGELOG.md text the component's notes are read from.
|
||||
Changelog string
|
||||
}
|
||||
|
||||
func (a Announcer) Announce(ctx context.Context, recipients []int64, send Sender) error {
|
||||
@@ -158,7 +159,7 @@ func (a Announcer) componentMessage(changed map[string]bool) (string, error) {
|
||||
fmt.Fprintf(&message, "No %s changes as part of this release.", component.ID)
|
||||
continue
|
||||
}
|
||||
notes, err := changelogSection(component.ChangelogPath, component.Version)
|
||||
notes, err := changelogSection(component.Changelog, component.Version)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("%s changelog: %w", component.ID, err)
|
||||
}
|
||||
@@ -170,10 +171,8 @@ func (a Announcer) componentMessage(changed map[string]bool) (string, error) {
|
||||
type releaseVersion [3]uint64
|
||||
|
||||
func parseReleaseVersion(value string) (releaseVersion, bool) {
|
||||
if len(value) < len("v0.0.0") || value[0] != 'v' {
|
||||
return releaseVersion{}, false
|
||||
}
|
||||
parts := strings.Split(value[1:], ".")
|
||||
// Release builds are stamped with or without the tag's "v".
|
||||
parts := strings.Split(strings.TrimPrefix(value, "v"), ".")
|
||||
if len(parts) != 3 {
|
||||
return releaseVersion{}, false
|
||||
}
|
||||
@@ -203,16 +202,11 @@ func compareVersions(left, right releaseVersion) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func changelogSection(path, version string) (string, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("open changelog: %w", err)
|
||||
}
|
||||
|
||||
headerPrefix := "## [" + version + "]"
|
||||
func changelogSection(changelog, version string) (string, error) {
|
||||
headerPrefix := "## [" + strings.TrimPrefix(version, "v") + "]"
|
||||
var lines []string
|
||||
found := false
|
||||
scanner := bufio.NewScanner(file)
|
||||
scanner := bufio.NewScanner(strings.NewReader(changelog))
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if !found {
|
||||
@@ -225,12 +219,8 @@ func changelogSection(path, version string) (string, error) {
|
||||
lines = append(lines, line)
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
_ = file.Close()
|
||||
return "", fmt.Errorf("read changelog: %w", err)
|
||||
}
|
||||
if err := file.Close(); err != nil {
|
||||
return "", fmt.Errorf("close changelog: %w", err)
|
||||
}
|
||||
notes := strings.TrimSpace(strings.Join(lines, "\n"))
|
||||
if !found || notes == "" {
|
||||
return "", fmt.Errorf("changelog has no notes for release %s", version)
|
||||
|
||||
Reference in new issue
Block a user