Files
warewulf/internal/pkg/node/hash.go
Christian Goll 5bd4fd4712 use yaml/v3 and don't export Nodes
introduced wwbool and don't export
Nodes and NodeConfs. This requires new
explict Yaml (un)marshaling as the standard
marshaller won't touch these fields

Signed-off-by: Christian Goll <cgoll@suse.com>
2024-10-17 15:30:54 -04:00

36 lines
669 B
Go

package node
import (
"crypto/sha256"
"encoding/hex"
"github.com/warewulf/warewulf/internal/pkg/wwlog"
"gopkg.in/yaml.v3"
)
/*
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[:])
}