From 4b472795c458a874daf76220c8be2f6f593b3dec Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Sun, 21 Sep 2014 16:33:01 -0700 Subject: [PATCH] user: move User into config package - Add YAML tags for the fields --- config/user.go | 17 +++++++++++++++++ initialize/config.go | 4 ++-- system/user.go | 22 ++++------------------ 3 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 config/user.go diff --git a/config/user.go b/config/user.go new file mode 100644 index 0000000..d66fbe8 --- /dev/null +++ b/config/user.go @@ -0,0 +1,17 @@ +package config + +type User struct { + Name string `yaml:"name"` + PasswordHash string `yaml:"passwd"` + SSHAuthorizedKeys []string `yaml:"ssh-authorized-keys"` + SSHImportGithubUser string `yaml:"coreos-ssh-import-github"` + SSHImportURL string `yaml:"coreos-ssh-import-url"` + GECOS string `yaml:"gecos"` + Homedir string `yaml:"homedir"` + NoCreateHome bool `yaml:"no-create-home"` + PrimaryGroup string `yaml:"primary-group"` + Groups []string `yaml:"groups"` + NoUserGroup bool `yaml:"no-user-group"` + System bool `yaml:"system"` + NoLogInit bool `yaml:"no-log-init"` +} diff --git a/initialize/config.go b/initialize/config.go index 79ec5e7..61ac7a4 100644 --- a/initialize/config.go +++ b/initialize/config.go @@ -39,7 +39,7 @@ type CloudConfig struct { } WriteFiles []config.File `yaml:"write_files"` Hostname string - Users []system.User + Users []config.User ManageEtcHosts config.EtcHosts `yaml:"manage_etc_hosts"` NetworkConfigPath string NetworkConfig string @@ -85,7 +85,7 @@ func warnOnUnrecognizedKeys(contents string, warn warner) { // Check for any badly-specified users, if any are set if users, ok := c["users"]; ok { var known map[string]interface{} - b, _ := yaml.Marshal(&system.User{}) + b, _ := yaml.Marshal(&config.User{}) yaml.Unmarshal(b, &known) if set, ok := users.([]interface{}); ok { diff --git a/system/user.go b/system/user.go index 9e627f0..849e735 100644 --- a/system/user.go +++ b/system/user.go @@ -6,30 +6,16 @@ import ( "os/exec" "os/user" "strings" + + "github.com/coreos/coreos-cloudinit/config" ) -type User struct { - Name string `yaml:"name"` - PasswordHash string `yaml:"passwd"` - SSHAuthorizedKeys []string `yaml:"ssh-authorized-keys"` - SSHImportGithubUser string `yaml:"coreos-ssh-import-github"` - SSHImportURL string `yaml:"coreos-ssh-import-url"` - GECOS string `yaml:"gecos"` - Homedir string `yaml:"homedir"` - NoCreateHome bool `yaml:"no-create-home"` - PrimaryGroup string `yaml:"primary-group"` - Groups []string `yaml:"groups"` - NoUserGroup bool `yaml:"no-user-group"` - System bool `yaml:"system"` - NoLogInit bool `yaml:"no-log-init"` -} - -func UserExists(u *User) bool { +func UserExists(u *config.User) bool { _, err := user.Lookup(u.Name) return err == nil } -func CreateUser(u *User) error { +func CreateUser(u *config.User) error { args := []string{} if u.PasswordHash != "" {