carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package host
2
3import (
4 "context"
5 "encoding/json"
6 "github.com/carlosframework/platform/internal/hostbox"
7 "github.com/carlosframework/platform/internal/hostclaim"
8 "github.com/carlosframework/platform/internal/hostfence"
9 "github.com/carlosframework/platform/internal/hostops"
10 "github.com/carlosframework/platform/internal/release"
11 "time"
12)
13
14func (p ClaimProviders) VerifyMoveTargetFence(ctx context.Context, o hostclaim.Observed) (hostclaim.ReturnFence, error) {
15 if p.moveTargetFence == nil {
16 return hostclaim.ReturnFence{}, hostclaim.ErrFence
17 }
18 return p.moveTargetFence(ctx, o)
19}
20func claimBoxFenceVerifier(check func(context.Context) error, store release.Store, authority *hostops.ProductionAuthority) func(context.Context, hostclaim.Observed) (hostclaim.ReturnFence, error) {
21 return func(ctx context.Context, o hostclaim.Observed) (hostclaim.ReturnFence, error) {
22 if check == nil || store == nil || authority == nil || o.Claim == nil {
23 return hostclaim.ReturnFence{}, hostclaim.ErrFence
24 }
25 if err := check(ctx); err != nil {
26 return hostclaim.ReturnFence{}, err
27 }
28 fresh, err := hostclaim.Read(ctx, store, o.Host)
29 if err != nil {
30 return hostclaim.ReturnFence{}, err
31 }
32 if fresh.ETag != o.ETag {
33 return hostclaim.ReturnFence{}, hostbox.ErrChanged
34 }
35 var ref hostclaim.FenceRef
36 if json.Unmarshal([]byte(o.Claim.Op.Journal["fence."+o.Claim.Op.Intent["target"]]), &ref) != nil {
37 return hostclaim.ReturnFence{}, hostclaim.ErrFence
38 }
39 return hostclaim.VerifyMoveTargetFence(ctx, store, o, ref, hostops.MoveFenceRegions{Authority: hostfence.ClaimFenceAuthority{Directory: authority.Directory, Now: time.Now}, HomeRegion: o.Claim.Op.Intent["home_region"]})
40 }
41}
42