package hostactors import ( "context" "encoding/json" "github.com/carlosframework/platform/internal/status" "strings" ) // PrivateBoxReport reads the private status report of box ref. A box its // region's group enrolled (b.Group set) is read under the reference the // console derives from the instance the roster pins, never under the key // the box chose (GroupBoxReference); every other box under ref, as before. func (d Directory) PrivateBoxReport(ctx context.Context, ref string, b Box) (Report, error) { key := "status/boxes/" + ref + ".json" if b.Group != "" { if b.Cloud.Account == "" || !segment(b.Cloud.InstanceID) { return Report{}, ErrRoster } key = "status/boxes/" + GroupBoxReference(b.Cloud.Account, b.Cloud.InstanceID) + ".json" } else if strings.HasPrefix(b.Namespace, "fleet:") { fleet := strings.TrimPrefix(b.Namespace, "fleet:") if !segment(fleet) || !segment(b.Label) { return Report{}, ErrRoster } key = "fleets/" + fleet + "/status/boxes/" + b.Label + ".json" } raw, _, err := d.Store.Get(ctx, key) if err != nil { return Report{}, err } var box status.Box if json.Unmarshal(raw, &box) != nil || box.Metrics == nil { return Report{}, ErrRoster } m := box.Metrics return Report{ConsoleProcesses: m.ConsoleProcesses, Component: "router", SystemChannel: m.SystemChannel, ActivationID: m.ActivationID, ActivationComplete: m.ActivationComplete, GeneratedAt: box.GeneratedAt, Actor: ref, Enrollment: m.Enrollment, InstanceID: m.InstanceID, Release: m.Release, ReleaseTag: m.ReleaseTag, Platform: m.Platform, BinarySHA256: m.BinarySHA256, MovesProtocol: m.MovesProtocol, BootID: m.BootID, FloorSHA256: m.FloorSHA256, FloorGuardReady: m.FloorGuardReady, HostClaimEnabled: m.HostClaimEnabled, RetirementReceiptSHA256: m.RetirementReceiptSHA256}, nil }