Download this file
| 1 | package hostops |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "github.com/carlosframework/platform/internal/hostclaim" |
| 7 | ) |
| 8 | |
| 9 | func (a ProductionAuthority) RefreshDeleteRecord(ctx context.Context, old hostclaim.Observed, r Record) error { |
| 10 | if old.Absent || old.Claim.Holder == nil || !matches(r, old.Claim.Holder) { |
| 11 | return ErrIdentity |
| 12 | } |
| 13 | admission, err := a.admission(ctx, r.Holder.Account, r.Holder.App) |
| 14 | if err != nil { |
| 15 | return err |
| 16 | } |
| 17 | if admission.Value.State != "closed" || admission.Value.Op == nil || len(admission.Value.Registrations) != 0 { |
| 18 | return ErrPending |
| 19 | } |
| 20 | for _, effect := range admission.Value.Effects { |
| 21 | if effect.State != "complete" { |
| 22 | return ErrPending |
| 23 | } |
| 24 | } |
| 25 | fresh, err := hostclaim.Read(ctx, a.Store, r.Holder.Host) |
| 26 | if err != nil { |
| 27 | return err |
| 28 | } |
| 29 | if fresh.Absent || fresh.Claim.Op.ID != old.Claim.Op.ID || !matches(r, fresh.Claim.Holder) || (fresh.Claim.Op.Kind != hostclaim.KindDeleting && fresh.Claim.Op.Kind != hostclaim.KindPurging) { |
| 30 | return ErrPending |
| 31 | } |
| 32 | _, err = hostclaim.Update(ctx, a.Store, fresh, func(c *hostclaim.Claim) error { |
| 33 | if c.Op.ID != old.Claim.Op.ID || !matches(r, c.Holder) { |
| 34 | return ErrIdentity |
| 35 | } |
| 36 | c.Op.Intent["etag"] = r.ETag |
| 37 | return nil |
| 38 | }) |
| 39 | if err != nil { |
| 40 | return err |
| 41 | } |
| 42 | return ErrPending |
| 43 | } |
| 44 | |