Serge Bazanski | 6dff6d6 | 2022-01-28 18:15:14 +0100 | [diff] [blame] | 1 | package roleserve |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "crypto/ed25519" |
| 6 | |
| 7 | "source.monogon.dev/metropolis/pkg/event" |
| 8 | "source.monogon.dev/metropolis/pkg/event/memory" |
| 9 | ) |
| 10 | |
| 11 | // bootstrapData is an internal EventValue structure which is populated by the |
| 12 | // Cluster Enrolment logic via ProvideBootstrapData. It contains data needed by |
| 13 | // the control plane logic to go into bootstrap mode and bring up a control |
| 14 | // plane from scratch. |
| 15 | type bootstrapData struct { |
| 16 | nodePrivateKey ed25519.PrivateKey |
| 17 | clusterUnlockKey []byte |
| 18 | initialOwnerKey []byte |
| 19 | } |
| 20 | |
| 21 | type bootstrapDataValue struct { |
| 22 | value memory.Value |
| 23 | } |
| 24 | |
| 25 | func (c *bootstrapDataValue) Watch() *bootstrapDataWatcher { |
| 26 | return &bootstrapDataWatcher{ |
| 27 | Watcher: c.value.Watch(), |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | func (c *bootstrapDataValue) set(v *bootstrapData) { |
| 32 | c.value.Set(v) |
| 33 | } |
| 34 | |
| 35 | type bootstrapDataWatcher struct { |
| 36 | event.Watcher |
| 37 | } |
| 38 | |
| 39 | func (c *bootstrapDataWatcher) Get(ctx context.Context) (*bootstrapData, error) { |
| 40 | v, err := c.Watcher.Get(ctx) |
| 41 | if err != nil { |
| 42 | return nil, err |
| 43 | } |
| 44 | return v.(*bootstrapData), nil |
| 45 | } |