mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
68092f27dd
* Move `file`, `ssh` and `user` packages to internal * Rename `SSHKey` to `(ssh.)UserKey` * Rename KeyValue / Publickey to PublicKey * Rename SSH key file from "debugd" to "ssh-keys" * Add CreateSSHUsers function to Core * Call CreateSSHUsers users on first control-plane node, when defined in config Tests: * Make StubUserCreator add entries to /etc/passwd * Add NewLinuxUserManagerFake for unit tests * Add unit tests & adjust existing ones to changes
35 lines
959 B
Go
35 lines
959 B
Go
package nodestate
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/edgelesssys/constellation/coordinator/role"
|
|
"github.com/edgelesssys/constellation/internal/file"
|
|
)
|
|
|
|
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
|
|
VPNIP string
|
|
VPNPrivKey []byte
|
|
OwnerID []byte
|
|
ClusterID []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("could not load 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)
|
|
}
|