Files
warewulf/internal/pkg/node/hash.go
Christian Goll b4acf0fdf2 added hash check for node edit
Signed-off-by: Christian Goll <cgoll@suse.de>
2023-03-24 19:47:22 +01:00

36 lines
666 B
Go

package node
import (
"crypto/sha256"
"encoding/hex"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"gopkg.in/yaml.v2"
)
/*
Calculate the hash of NodeYaml in an orderder fashion
*/
func (config *NodeYaml) Hash() [32]byte {
// flatten out profiles and nodes
for _, val := range config.NodeProfiles {
val.Flatten()
}
for _, val := range config.Nodes {
val.Flatten()
}
data, err := yaml.Marshal(config)
if err != nil {
wwlog.Warn("couldn't marshall NodeYaml for hashing")
}
return sha256.Sum256(data)
}
/*
Return the hash as string
*/
func (config *NodeYaml) StringHash() string {
buffer := config.Hash()
return hex.EncodeToString(buffer[:])
}