32 lines
852 B
Go
32 lines
852 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/nats-io/nats.go"
|
|
|
|
"github.com/novox/mesh-controller/internal/broker"
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
)
|
|
|
|
// provisioningFailed is every module whose files a machine's provisioner client last said it failed to place, from
|
|
// the stream that keeps their reports.
|
|
func provisioningFailed(js nats.JetStreamContext) ([]inventory.ProvReport, error) {
|
|
all, err := broker.ProvAppliedReports(js)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var out []inventory.ProvReport
|
|
for subject, raw := range all {
|
|
var r inventory.ProvReport
|
|
if err := json.Unmarshal(raw, &r); err != nil {
|
|
return nil, fmt.Errorf("what was said on %s is not a provisioner client's report: %w", subject, err)
|
|
}
|
|
if r.Status == inventory.ProvFailed {
|
|
out = append(out, r)
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|