package hostbox import ( "context" "encoding/json" "github.com/carlosframework/platform/internal/registry" "strings" ) type RegistryRows struct { Registry *registry.Registry Inventory RetirementInventory } func (r RegistryRows) RetireRows(context.Context, string, []Artifact) error { return ErrTypedJournal } func (r RegistryRows) RetireRowsJournal(ctx context.Context, id, owner string, rows []Artifact, archive func(json.RawMessage) error) error { if r.Registry == nil || owner != r.Inventory.Ownership { return ErrTypedInventory } targets := make([]registry.ClaimRow, 0, len(rows)) for _, a := range rows { if a.Root != "registry" || a.Owner != owner { return ErrTypedInventory } target := registry.ClaimRow{AllowAbsent: a.AllowAbsent, Kind: string(a.Kind), Host: r.Inventory.Host, Ownership: registry.ClaimOwnership{ClaimIncarnation: r.Inventory.Captured.Incarnation, ClaimStamp: r.Inventory.Captured.Stamp, ClaimOwner: owner, ClaimRowID: a.RowID}} if a.Kind == ArtifactRoute { if a.Name != target.Host { return ErrTypedInventory } } else if a.Kind == ArtifactTimer { prefix := target.Host + "/" if !strings.HasPrefix(a.Name, prefix) { return ErrTypedInventory } target.Name = strings.TrimPrefix(a.Name, prefix) target.Registration = a.RowID if id, registration, ok := strings.Cut(a.RowID, "~"); ok { if id == "" || registration == "" || strings.Contains(registration, "~") { return ErrTypedInventory } target.Ownership.ClaimRowID = id target.Registration = registration } } else { return ErrTypedInventory } targets = append(targets, target) } return r.Registry.RetireClaimRows(ctx, id, targets, func(rows []registry.ClaimRowArchive) error { b, err := json.Marshal(rows) if err != nil { return err } return archive(b) }) }