mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-09-27 03:50:56 -04:00
move nodestate and role
Signed-off-by: Fabian Kammel <fk@edgeless.systems>
This commit is contained in:
parent
26e9c67a00
commit
22c912a56d
30 changed files with 29 additions and 29 deletions
31
internal/nodestate/nodestate.go
Normal file
31
internal/nodestate/nodestate.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package nodestate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/edgelesssys/constellation/internal/file"
|
||||
"github.com/edgelesssys/constellation/internal/role"
|
||||
)
|
||||
|
||||
const nodeStatePath = "/run/state/constellation/node_state.json"
|
||||
|
||||
// NodeState is the state of a constellation node that is required to recover from a reboot.
|
||||
// Can be persisted to disk and reloaded later.
|
||||
type NodeState struct {
|
||||
Role role.Role
|
||||
MeasurementSalt []byte
|
||||
}
|
||||
|
||||
// FromFile reads a NodeState from disk.
|
||||
func FromFile(fileHandler file.Handler) (*NodeState, error) {
|
||||
nodeState := &NodeState{}
|
||||
if err := fileHandler.ReadJSON(nodeStatePath, nodeState); err != nil {
|
||||
return nil, fmt.Errorf("loading node state: %w", err)
|
||||
}
|
||||
return nodeState, nil
|
||||
}
|
||||
|
||||
// ToFile writes a NodeState to disk.
|
||||
func (nodeState *NodeState) ToFile(fileHandler file.Handler) error {
|
||||
return fileHandler.WriteJSON(nodeStatePath, nodeState, file.OptMkdirAll)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue