Compare commits
No commits in common. "35962e41068fbdadd78dab3da9db537433090693" and "a9aa10cb3e8737e98e2209a27e2938f1c21d71b7" have entirely different histories.
35962e4106
...
a9aa10cb3e
|
@ -13,5 +13,5 @@
|
|||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
vendor/
|
||||
# vendor/
|
||||
bin/
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
|
||||
"forge.cadoles.com/pcaseiro/templatefile/pkg/utils"
|
||||
)
|
||||
|
@ -26,32 +25,8 @@ type ConfigFile struct {
|
|||
// Generate the configuration file from the template (hcl or json)
|
||||
func (cf *ConfigFile) Generate(root string, templateDir string, values []byte) error {
|
||||
var template string
|
||||
|
||||
if utils.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
cf.TemplateDir = templateDir
|
||||
dest := filepath.Join(root, cf.Destination)
|
||||
|
||||
// Get owner and group UID and GID
|
||||
owner, err := user.Lookup(cf.Owner)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Process templates failed with error: %v", err)
|
||||
}
|
||||
group, err := user.LookupGroup(cf.Group)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Process templates failed with error: %v", err)
|
||||
}
|
||||
uid, err := strconv.Atoi(owner.Uid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Process templates failed with error: %v", err)
|
||||
}
|
||||
gid, err := strconv.Atoi(group.Gid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Process templates failed with error: %v", err)
|
||||
}
|
||||
|
||||
intMod, err := strconv.ParseInt(cf.Mode, 8, 64)
|
||||
if err != nil {
|
||||
return (err)
|
||||
|
@ -70,10 +45,6 @@ func (cf *ConfigFile) Generate(root string, templateDir string, values []byte) e
|
|||
if err != nil {
|
||||
return fmt.Errorf("Process templates failed with error: %v", err)
|
||||
}
|
||||
if err = os.Chown(dest, uid, gid); err != nil {
|
||||
return fmt.Errorf("Process templates failed with error: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("\tFile %s generated\n", dest)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package templater
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os/user"
|
||||
|
||||
"forge.cadoles.com/pcaseiro/templatefile/pkg/utils"
|
||||
)
|
||||
|
@ -15,9 +14,17 @@ type SystemUser struct {
|
|||
Shell string `json:"shell"`
|
||||
}
|
||||
|
||||
func (su *SystemUser) exists() (bool, error) {
|
||||
_, _, err := utils.RunSystemCommand("getent", "passwd", su.UserName)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (su *SystemUser) Manage() error {
|
||||
_, err := user.Lookup(su.UserName)
|
||||
if err == nil {
|
||||
exist, _ := su.exists()
|
||||
if exist {
|
||||
log.Printf("\tUser %s already exists", su.UserName)
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue