Download this file
| 1 | package release |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "crypto/sha256" |
| 6 | "encoding/hex" |
| 7 | "encoding/json" |
| 8 | |
| 9 | "github.com/carlosframework/platform/internal/hostwrite" |
| 10 | ) |
| 11 | |
| 12 | func WithHostWrites(config hostwrite.Config) PassOption { |
| 13 | return func(c *passConfig) { c.hostWrites = config } |
| 14 | } |
| 15 | |
| 16 | func releaseIdentity(m *Manifest) (hostwrite.Identity, error) { |
| 17 | raw, err := json.Marshal(m) |
| 18 | if err != nil { |
| 19 | return hostwrite.Identity{}, err |
| 20 | } |
| 21 | sum := sha256.Sum256(raw) |
| 22 | return hostwrite.Identity{Release: "sha256:" + hex.EncodeToString(sum[:])}, nil |
| 23 | } |
| 24 | |
| 25 | func withReleaseWork(ctx context.Context, work hostwrite.Work, id hostwrite.Identity, fn func() error) error { |
| 26 | if ctx == nil || work == nil { |
| 27 | return hostwrite.ErrUnavailable |
| 28 | } |
| 29 | return work.With(ctx, id, fn) |
| 30 | } |
| 31 | |
| 32 | // WithSelectedRestarts supplies receivers that retain the original selection |
| 33 | // through restart and rollback start. Receivers validate at their final effect; |
| 34 | // network waits must not hold the hostguard flock. |
| 35 | func WithSelectedRestarts(restart, start hostwrite.Callback) PassOption { |
| 36 | return func(c *passConfig) { c.selectedRestart = restart; c.selectedStart = start } |
| 37 | } |
| 38 | |