| 1 | package hostactors |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "github.com/carlosframework/platform/internal/status" |
| 7 | "strings" |
| 8 | ) |
| 9 | |
| 10 | // PrivateBoxReport reads the private status report of box ref. A box its |
| 11 | // region's group enrolled (b.Group set) is read under the reference the |
| 12 | // console derives from the instance the roster pins, never under the key |
| 13 | // the box chose (GroupBoxReference); every other box under ref, as before. |
| 14 | func (d Directory) PrivateBoxReport(ctx context.Context, ref string, b Box) (Report, error) { |
| 15 | key := "status/boxes/" + ref + ".json" |
| 16 | if b.Group != "" { |
| 17 | if b.Cloud.Account == "" || !segment(b.Cloud.InstanceID) { |
| 18 | return Report{}, ErrRoster |
| 19 | } |
| 20 | key = "status/boxes/" + GroupBoxReference(b.Cloud.Account, b.Cloud.InstanceID) + ".json" |
| 21 | } else if strings.HasPrefix(b.Namespace, "fleet:") { |
| 22 | fleet := strings.TrimPrefix(b.Namespace, "fleet:") |
| 23 | if !segment(fleet) || !segment(b.Label) { |
| 24 | return Report{}, ErrRoster |
| 25 | } |
| 26 | key = "fleets/" + fleet + "/status/boxes/" + b.Label + ".json" |
| 27 | } |
| 28 | raw, _, err := d.Store.Get(ctx, key) |
| 29 | if err != nil { |
| 30 | return Report{}, err |
| 31 | } |
| 32 | var box status.Box |
| 33 | if json.Unmarshal(raw, &box) != nil || box.Metrics == nil { |
| 34 | return Report{}, ErrRoster |
| 35 | } |
| 36 | m := box.Metrics |
| 37 | 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 |
| 38 | } |
| 39 | |