blob: 4ab1250722fbb387566822f5298f6dc2a5a7c31e [file] [log] [blame]
Serge Bazanski6dff6d62022-01-28 18:15:14 +01001package roleserve
2
3import (
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.
15type bootstrapData struct {
16 nodePrivateKey ed25519.PrivateKey
17 clusterUnlockKey []byte
18 initialOwnerKey []byte
19}
20
21type bootstrapDataValue struct {
22 value memory.Value
23}
24
25func (c *bootstrapDataValue) Watch() *bootstrapDataWatcher {
26 return &bootstrapDataWatcher{
27 Watcher: c.value.Watch(),
28 }
29}
30
31func (c *bootstrapDataValue) set(v *bootstrapData) {
32 c.value.Set(v)
33}
34
35type bootstrapDataWatcher struct {
36 event.Watcher
37}
38
39func (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}