Merge pull request #719 from hpcng/hashConf

more secure edit command
This commit is contained in:
Christian Goll
2023-04-11 11:44:01 +02:00
committed by GitHub
13 changed files with 761 additions and 434 deletions

View File

@@ -26,14 +26,16 @@ func ProfileDelete(ndp *wwapiv1.NodeDeleteParameter) (err error) {
wwlog.Error("Failed to open node database: %s\n", err)
return
}
if nodeDB.StringHash() != ndp.Hash && !ndp.Force {
return fmt.Errorf("got wrong hash, not modifying profile database")
}
for _, p := range profileList {
err := nodeDB.DelProfile(p.Id.Get())
if err != nil {
wwlog.Error("%s\n", err)
} else {
//count++
wwlog.Verbose("Deleting node: %s\n", p.Id.Print())
wwlog.Verbose("Deleting profile: %s\n", p.Id.Print())
}
}

View File

@@ -1,6 +1,7 @@
package apiprofile
import (
"fmt"
"os"
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
@@ -49,13 +50,17 @@ func FilteredProfiles(profileList *wwapiv1.NodeList) *wwapiv1.NodeYaml {
/*
Add profiles from yaml
*/
func ProfileAddFromYaml(nodeList *wwapiv1.NodeYaml) (err error) {
func ProfileAddFromYaml(nodeList *wwapiv1.NodeAddParameter) (err error) {
nodeDB, err := node.New()
if err != nil {
return errors.Wrap(err, "Could not open NodeDB: %s\n")
}
if nodeDB.StringHash() != nodeList.Hash && !nodeList.Force {
return fmt.Errorf("got wrong hash, not modifying profile database")
}
profileMap := make(map[string]*node.NodeConf)
err = yaml.Unmarshal([]byte(nodeList.NodeConfMapYaml), profileMap)
err = yaml.Unmarshal([]byte(nodeList.NodeConfYaml), profileMap)
if err != nil {
return errors.Wrap(err, "Could not unmarshall Yaml: %s\n")
}