carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package activator
2
3import "context"
4
5// BuildStateLocation is where an instance's build-state.json lives (settings
6// spec §4.2): the bucket and the prefix of the lease's lock.json. With host
7// claims off that is Config.Bucket and HibernatePrefix(Config.Prefix, host);
8// with them on, the claim actor's bucket and Holder.Location (never a
9// g-<gen>/ generation prefix). The wake knows which lease it holds, so it
10// puts the location on the context it hands BeforeExec, and the agent's hook
11// writes there rather than guessing.
12type BuildStateLocation struct{ Bucket, Prefix string }
13
14type buildStateLocationKey struct{}
15
16// WithBuildStateLocation returns ctx carrying l. A location with either part
17// empty reads back as none, so a caller can mask a location it inherited.
18func WithBuildStateLocation(ctx context.Context, l BuildStateLocation) context.Context {
19 return context.WithValue(ctx, buildStateLocationKey{}, l)
20}
21
22// BuildStateLocationFrom is the location ctx carries, if a whole one.
23func BuildStateLocationFrom(ctx context.Context) (BuildStateLocation, bool) {
24 l, ok := ctx.Value(buildStateLocationKey{}).(BuildStateLocation)
25 if !ok || l.Bucket == "" || l.Prefix == "" {
26 return BuildStateLocation{}, false
27 }
28 return l, true
29}
30