user: move User into config package
- Add YAML tags for the fields
This commit is contained in:
parent
85b8d804c8
commit
4b472795c4
17
config/user.go
Normal file
17
config/user.go
Normal file
@ -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"`
|
||||||
|
}
|
@ -39,7 +39,7 @@ type CloudConfig struct {
|
|||||||
}
|
}
|
||||||
WriteFiles []config.File `yaml:"write_files"`
|
WriteFiles []config.File `yaml:"write_files"`
|
||||||
Hostname string
|
Hostname string
|
||||||
Users []system.User
|
Users []config.User
|
||||||
ManageEtcHosts config.EtcHosts `yaml:"manage_etc_hosts"`
|
ManageEtcHosts config.EtcHosts `yaml:"manage_etc_hosts"`
|
||||||
NetworkConfigPath string
|
NetworkConfigPath string
|
||||||
NetworkConfig string
|
NetworkConfig string
|
||||||
@ -85,7 +85,7 @@ func warnOnUnrecognizedKeys(contents string, warn warner) {
|
|||||||
// Check for any badly-specified users, if any are set
|
// Check for any badly-specified users, if any are set
|
||||||
if users, ok := c["users"]; ok {
|
if users, ok := c["users"]; ok {
|
||||||
var known map[string]interface{}
|
var known map[string]interface{}
|
||||||
b, _ := yaml.Marshal(&system.User{})
|
b, _ := yaml.Marshal(&config.User{})
|
||||||
yaml.Unmarshal(b, &known)
|
yaml.Unmarshal(b, &known)
|
||||||
|
|
||||||
if set, ok := users.([]interface{}); ok {
|
if set, ok := users.([]interface{}); ok {
|
||||||
|
@ -6,30 +6,16 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/coreos/coreos-cloudinit/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
func UserExists(u *config.User) bool {
|
||||||
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 {
|
|
||||||
_, err := user.Lookup(u.Name)
|
_, err := user.Lookup(u.Name)
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateUser(u *User) error {
|
func CreateUser(u *config.User) error {
|
||||||
args := []string{}
|
args := []string{}
|
||||||
|
|
||||||
if u.PasswordHash != "" {
|
if u.PasswordHash != "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user