package hostops import ( "context" "github.com/carlosframework/platform/internal/hostclaim" ) // A door that chooses its executor before it registers anything (region HA // spec 2 ยง7, H27) carries the choice to the create through the context, so // the create names exactly the box the door checked, and a refusal leaves // nothing registered, nothing written to the claim and nothing for // recovery to settle. selectExecutor still checks the choice against // claim Plan 5's scope (namespace, region, pool, active, unfenced). type chosenExecutorKey struct{} type chosenExecutor struct { host string sel hostclaim.ExecutorSelection } // WithChosenExecutor records sel as host's executor for the create that // ctx carries. func WithChosenExecutor(ctx context.Context, host string, sel hostclaim.ExecutorSelection) context.Context { return context.WithValue(ctx, chosenExecutorKey{}, chosenExecutor{host: host, sel: sel}) } // ChosenExecutor is the executor ctx carries for host, if any: a door that // already chose finds its choice here and does not choose again. func ChosenExecutor(ctx context.Context, host string) (hostclaim.ExecutorSelection, bool) { c, ok := ctx.Value(chosenExecutorKey{}).(chosenExecutor) if !ok || c.host == "" || c.host != host || c.sel.Box == "" || c.sel.Enrollment == "" { return hostclaim.ExecutorSelection{}, false } return c.sel, true }