package host import ( "context" "encoding/json" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/hostclaim" "github.com/carlosframework/platform/internal/hostfence" "github.com/carlosframework/platform/internal/hostops" "github.com/carlosframework/platform/internal/release" "time" ) func (p ClaimProviders) VerifyMoveTargetFence(ctx context.Context, o hostclaim.Observed) (hostclaim.ReturnFence, error) { if p.moveTargetFence == nil { return hostclaim.ReturnFence{}, hostclaim.ErrFence } return p.moveTargetFence(ctx, o) } func claimBoxFenceVerifier(check func(context.Context) error, store release.Store, authority *hostops.ProductionAuthority) func(context.Context, hostclaim.Observed) (hostclaim.ReturnFence, error) { return func(ctx context.Context, o hostclaim.Observed) (hostclaim.ReturnFence, error) { if check == nil || store == nil || authority == nil || o.Claim == nil { return hostclaim.ReturnFence{}, hostclaim.ErrFence } if err := check(ctx); err != nil { return hostclaim.ReturnFence{}, err } fresh, err := hostclaim.Read(ctx, store, o.Host) if err != nil { return hostclaim.ReturnFence{}, err } if fresh.ETag != o.ETag { return hostclaim.ReturnFence{}, hostbox.ErrChanged } var ref hostclaim.FenceRef if json.Unmarshal([]byte(o.Claim.Op.Journal["fence."+o.Claim.Op.Intent["target"]]), &ref) != nil { return hostclaim.ReturnFence{}, hostclaim.ErrFence } 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"]}) } }