44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
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
|
|
}})
|
|
}
|