carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package hostops
2
3import (
4 "context"
5
6 "github.com/carlosframework/platform/internal/hostclaim"
7)
8
9// A door that chooses its executor before it registers anything (region HA
10// spec 2 §7, H27) carries the choice to the create through the context, so
11// the create names exactly the box the door checked, and a refusal leaves
12// nothing registered, nothing written to the claim and nothing for
13// recovery to settle. selectExecutor still checks the choice against
14// claim Plan 5's scope (namespace, region, pool, active, unfenced).
15
16type chosenExecutorKey struct{}
17
18type chosenExecutor struct {
19 host string
20 sel hostclaim.ExecutorSelection
21}
22
23// WithChosenExecutor records sel as host's executor for the create that
24// ctx carries.
25func WithChosenExecutor(ctx context.Context, host string, sel hostclaim.ExecutorSelection) context.Context {
26 return context.WithValue(ctx, chosenExecutorKey{}, chosenExecutor{host: host, sel: sel})
27}
28
29// ChosenExecutor is the executor ctx carries for host, if any: a door that
30// already chose finds its choice here and does not choose again.
31func ChosenExecutor(ctx context.Context, host string) (hostclaim.ExecutorSelection, bool) {
32 c, ok := ctx.Value(chosenExecutorKey{}).(chosenExecutor)
33 if !ok || c.host == "" || c.host != host || c.sel.Box == "" || c.sel.Enrollment == "" {
34 return hostclaim.ExecutorSelection{}, false
35 }
36 return c.sel, true
37}
38