Connect shared configuration to CLI and server startup
This commit is contained in:
43
internal/adapter/cli/bootstrap.go
Normal file
43
internal/adapter/cli/bootstrap.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"go.maximumdirect.net/ckconfig"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
"go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
type bootstrapSinkKey struct{}
|
||||
type bootstrapSink func(*configkit.SecretsReport, error)
|
||||
|
||||
func bootstrapFeature() commandkit.InvocationFeature {
|
||||
return commandkit.NewInvocationFeature(commandkit.InvocationFeatureSpec[struct{}]{Start: func(inv commandkit.Invocation, _ struct{}) (context.Context, func() commandkit.Report) {
|
||||
sink := bootstrapSink(func(report *configkit.SecretsReport, err error) {
|
||||
var failure *configkit.SecretsError
|
||||
if errors.As(err, &failure) && failure != nil {
|
||||
diagnostics, explanation := ckconfig.AdaptDiagnostics("Secrets bootstrap:\n", nil, failure.Diagnostics())
|
||||
queueDiagnostics(inv.Reporter(), diagnostics)
|
||||
for _, detail := range explanation.Details {
|
||||
_ = inv.Reporter().AtEnd().Warn("", detail)
|
||||
}
|
||||
}
|
||||
if report == nil || len(report.Entries()) == 0 {
|
||||
return
|
||||
}
|
||||
write := func(w io.Writer) error { _, err := report.WriteTo(w); return err }
|
||||
failed := false
|
||||
for _, entry := range report.Entries() {
|
||||
failed = failed || entry.Status == configkit.SecretFileFailed || entry.Status == configkit.SecretFileNotApplied
|
||||
}
|
||||
if failed {
|
||||
_ = inv.Reporter().AtEnd().Warn("", write)
|
||||
} else {
|
||||
_ = inv.Reporter().AtEnd().Info("", write)
|
||||
}
|
||||
})
|
||||
return context.WithValue(inv.Context, bootstrapSinkKey{}, sink), nil
|
||||
}})
|
||||
}
|
||||
Reference in New Issue
Block a user