| 1 | //go:build linux |
| 2 | |
| 3 | package host |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "github.com/carlosframework/platform/internal/controlsock" |
| 8 | "github.com/carlosframework/platform/internal/hostbox" |
| 9 | "github.com/carlosframework/platform/internal/hostclaim" |
| 10 | "github.com/carlosframework/platform/internal/hostwrite" |
| 11 | "github.com/carlosframework/platform/internal/provision" |
| 12 | "github.com/carlosframework/platform/internal/registry" |
| 13 | ) |
| 14 | |
| 15 | type claimTokenWork struct { |
| 16 | tokens claimAdminTokens |
| 17 | host string |
| 18 | } |
| 19 | |
| 20 | func (w claimTokenWork) With(ctx context.Context, _ hostwrite.Identity, effect func() error) error { |
| 21 | return w.tokens.With(ctx, w.host, effect) |
| 22 | } |
| 23 | |
| 24 | func (t claimAdminTokens) prepareState(ctx context.Context, route registry.Route) error { |
| 25 | if route.DBPath != provision.NestedDBPath(t.Guard.DataDir, route.Host) { |
| 26 | return hostbox.ErrChanged |
| 27 | } |
| 28 | call := rootJournalClient(controlsock.Path) |
| 29 | _, inventory := hostbox.RemoteJournals(call) |
| 30 | defer inventory.Close() |
| 31 | t.Guard.FenceView = rootFenceViewClient(call) |
| 32 | observed, err := hostclaim.Read(ctx, t.Claims, route.Host) |
| 33 | if err != nil { |
| 34 | return err |
| 35 | } |
| 36 | actor, err := t.Verify(ctx) |
| 37 | if err != nil { |
| 38 | return err |
| 39 | } |
| 40 | a := &ClaimRoleAssembly{Claims: t.Claims, Guard: t.Guard, Inventory: inventory, ManagedRoots: map[string]string{"data": t.Guard.DataDir}} |
| 41 | return a.prepareStateRemote(ctx, observed, claimTokenWork{t, route.Host}, ClaimLaunchInputs{DBPath: route.DBPath}, actor) |
| 42 | } |
| 43 | |