Compare commits

..

No commits in common. "fix-tkt-04" and "master" have entirely different histories.

3 changed files with 11 additions and 33 deletions

2
.gitignore vendored
View File

@ -13,5 +13,5 @@
*.out *.out
# Dependency directories (remove the comment below to include it) # Dependency directories (remove the comment below to include it)
vendor/ # vendor/
bin/ bin/

View File

@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"os" "os"
"os/user"
"forge.cadoles.com/pcaseiro/templatefile/pkg/utils" "forge.cadoles.com/pcaseiro/templatefile/pkg/utils"
) )
@ -26,32 +25,8 @@ type ConfigFile struct {
// Generate the configuration file from the template (hcl or json) // Generate the configuration file from the template (hcl or json)
func (cf *ConfigFile) Generate(root string, templateDir string, values []byte) error { func (cf *ConfigFile) Generate(root string, templateDir string, values []byte) error {
var template string var template string
if utils.DryRun {
return nil
}
cf.TemplateDir = templateDir cf.TemplateDir = templateDir
dest := filepath.Join(root, cf.Destination) 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) intMod, err := strconv.ParseInt(cf.Mode, 8, 64)
if err != nil { if err != nil {
return (err) return (err)
@ -70,10 +45,6 @@ func (cf *ConfigFile) Generate(root string, templateDir string, values []byte) e
if err != nil { if err != nil {
return fmt.Errorf("Process templates failed with error: %v", err) 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) log.Printf("\tFile %s generated\n", dest)
return nil return nil
} }

View File

@ -3,7 +3,6 @@ package templater
import ( import (
"fmt" "fmt"
"log" "log"
"os/user"
"forge.cadoles.com/pcaseiro/templatefile/pkg/utils" "forge.cadoles.com/pcaseiro/templatefile/pkg/utils"
) )
@ -15,9 +14,17 @@ type SystemUser struct {
Shell string `json:"shell"` 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 { func (su *SystemUser) Manage() error {
_, err := user.Lookup(su.UserName) exist, _ := su.exists()
if err == nil { if exist {
log.Printf("\tUser %s already exists", su.UserName) log.Printf("\tUser %s already exists", su.UserName)
return nil return nil
} }