Configure nodes.conf path dynamically from config
Removes the use of init() to initialize the variable. - Closes: #1596 - See also: #1569 Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
"github.com/warewulf/warewulf/internal/pkg/config"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
@@ -31,17 +30,10 @@ Simple check if the config can be written in case wwctl isn't run as root
|
||||
*/
|
||||
func CanWriteConfig() (canwrite *wwapiv1.CanWriteConfig, err error) {
|
||||
canwrite = new(wwapiv1.CanWriteConfig)
|
||||
// node is not initialized yet
|
||||
if node.ConfigFile == "" {
|
||||
_, err := node.New()
|
||||
if err != nil {
|
||||
canwrite.CanWriteConfig = false
|
||||
return canwrite, fmt.Errorf("unable to initialize the node %w", err)
|
||||
}
|
||||
}
|
||||
err = syscall.Access(node.ConfigFile, syscall.O_RDWR)
|
||||
nodesConf := config.Get().Paths.NodesConf()
|
||||
err = syscall.Access(nodesConf, syscall.O_RDWR)
|
||||
if err != nil {
|
||||
wwlog.Warn("Couldn't open %s:%s", node.ConfigFile, err)
|
||||
wwlog.Warn("Couldn't open %s:%s", nodesConf, err)
|
||||
canwrite.CanWriteConfig = false
|
||||
} else {
|
||||
canwrite.CanWriteConfig = true
|
||||
|
||||
Reference in New Issue
Block a user