Download this file
| 1 | package hostactors |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "reflect" |
| 6 | |
| 7 | "github.com/carlosframework/platform/internal/release" |
| 8 | ) |
| 9 | |
| 10 | func (d Directory) PublishActivation(ctx context.Context, id string) (*release.SystemPointer, error) { |
| 11 | o, err := d.Read(ctx) |
| 12 | if err != nil { |
| 13 | return nil, err |
| 14 | } |
| 15 | h, ok := o.Roster.Activations[id] |
| 16 | if !ok || h.Publication == nil || h.Publication.ID != id { |
| 17 | return nil, ErrRoster |
| 18 | } |
| 19 | return release.PublishSystemPublication(ctx, d.Store, d.PublicKey, *h.Publication) |
| 20 | } |
| 21 | |
| 22 | func (d Directory) CancelActivation(ctx context.Context, sg release.Signer, id string) error { |
| 23 | o, err := d.Read(ctx) |
| 24 | if err != nil { |
| 25 | return err |
| 26 | } |
| 27 | h, ok := o.Roster.Activations[id] |
| 28 | if !ok { |
| 29 | return nil |
| 30 | } |
| 31 | if h.Publication == nil || h.Publication.ID != id { |
| 32 | return ErrRoster |
| 33 | } |
| 34 | if err := release.CancelSystemPublication(ctx, d.Store, sg, *h.Publication); err != nil { |
| 35 | return err |
| 36 | } |
| 37 | fresh, err := d.Read(ctx) |
| 38 | if err != nil { |
| 39 | return err |
| 40 | } |
| 41 | if _, ok := fresh.Roster.Activations[id]; !ok { |
| 42 | return nil |
| 43 | } |
| 44 | if !reflect.DeepEqual(h, fresh.Roster.Activations[id]) { |
| 45 | return ErrRoster |
| 46 | } |
| 47 | next := Clone(fresh.Roster) |
| 48 | delete(next.Activations, id) |
| 49 | _, err = d.Replace(ctx, sg, fresh, next) |
| 50 | return err |
| 51 | } |
| 52 | |