commit
e3741a0fa3
@ -10,14 +10,14 @@ import (
|
|||||||
const DefaultSSHKeyName = "coreos-cloudinit"
|
const DefaultSSHKeyName = "coreos-cloudinit"
|
||||||
|
|
||||||
type CloudConfig struct {
|
type CloudConfig struct {
|
||||||
SSH_Authorized_Keys []string
|
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
|
||||||
Coreos struct {
|
Coreos struct {
|
||||||
Etcd struct{ Discovery_URL string }
|
Etcd struct{ Discovery_URL string }
|
||||||
Fleet struct{ Autostart bool }
|
Fleet struct{ Autostart bool }
|
||||||
Units []Unit
|
Units []Unit
|
||||||
}
|
}
|
||||||
Write_Files []WriteFile
|
WriteFiles []WriteFile `yaml:"write_files"`
|
||||||
Hostname string
|
Hostname string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCloudConfig(contents []byte) (*CloudConfig, error) {
|
func NewCloudConfig(contents []byte) (*CloudConfig, error) {
|
||||||
@ -46,8 +46,8 @@ func ApplyCloudConfig(cfg CloudConfig, sshKeyName string) error {
|
|||||||
log.Printf("Set hostname to %s", cfg.Hostname)
|
log.Printf("Set hostname to %s", cfg.Hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cfg.SSH_Authorized_Keys) > 0 {
|
if len(cfg.SSHAuthorizedKeys) > 0 {
|
||||||
err := AuthorizeSSHKeys(sshKeyName, cfg.SSH_Authorized_Keys)
|
err := AuthorizeSSHKeys(sshKeyName, cfg.SSHAuthorizedKeys)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Printf("Authorized SSH keys for core user")
|
log.Printf("Authorized SSH keys for core user")
|
||||||
} else {
|
} else {
|
||||||
@ -55,8 +55,8 @@ func ApplyCloudConfig(cfg CloudConfig, sshKeyName string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cfg.Write_Files) > 0 {
|
if len(cfg.WriteFiles) > 0 {
|
||||||
for _, file := range cfg.Write_Files {
|
for _, file := range cfg.WriteFiles {
|
||||||
if err := ProcessWriteFile("/", &file); err != nil {
|
if err := ProcessWriteFile("/", &file); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ func TestCloudConfigEmpty(t *testing.T) {
|
|||||||
t.Fatalf("Encountered unexpected error :%v", err)
|
t.Fatalf("Encountered unexpected error :%v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
keys := cfg.SSH_Authorized_Keys
|
keys := cfg.SSHAuthorizedKeys
|
||||||
if len(keys) != 0 {
|
if len(keys) != 0 {
|
||||||
t.Error("Parsed incorrect number of SSH keys")
|
t.Error("Parsed incorrect number of SSH keys")
|
||||||
}
|
}
|
||||||
@ -25,8 +25,8 @@ func TestCloudConfigEmpty(t *testing.T) {
|
|||||||
t.Error("Expected AutostartFleet not to be defined")
|
t.Error("Expected AutostartFleet not to be defined")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cfg.Write_Files) != 0 {
|
if len(cfg.WriteFiles) != 0 {
|
||||||
t.Error("Expected zero Write_Files")
|
t.Error("Expected zero WriteFiles")
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Hostname != "" {
|
if cfg.Hostname != "" {
|
||||||
@ -72,7 +72,7 @@ hostname: trontastic
|
|||||||
t.Fatalf("Encountered unexpected error :%v", err)
|
t.Fatalf("Encountered unexpected error :%v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
keys := cfg.SSH_Authorized_Keys
|
keys := cfg.SSHAuthorizedKeys
|
||||||
if len(keys) != 2 {
|
if len(keys) != 2 {
|
||||||
t.Error("Parsed incorrect number of SSH keys")
|
t.Error("Parsed incorrect number of SSH keys")
|
||||||
} else if keys[0] != "foobar" {
|
} else if keys[0] != "foobar" {
|
||||||
@ -89,10 +89,10 @@ hostname: trontastic
|
|||||||
t.Error("Expected AutostartFleet to be true")
|
t.Error("Expected AutostartFleet to be true")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cfg.Write_Files) != 1 {
|
if len(cfg.WriteFiles) != 1 {
|
||||||
t.Error("Failed to parse correct number of write_files")
|
t.Error("Failed to parse correct number of write_files")
|
||||||
} else {
|
} else {
|
||||||
wf := cfg.Write_Files[0]
|
wf := cfg.WriteFiles[0]
|
||||||
if wf.Content != "penny\nelroy\n" {
|
if wf.Content != "penny\nelroy\n" {
|
||||||
t.Errorf("WriteFile has incorrect contents '%s'", wf.Content)
|
t.Errorf("WriteFile has incorrect contents '%s'", wf.Content)
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ ssh_authorized_keys:
|
|||||||
t.Fatalf("Encountered unexpected error :%v", err)
|
t.Fatalf("Encountered unexpected error :%v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
keys := cfg.SSH_Authorized_Keys
|
keys := cfg.SSHAuthorizedKeys
|
||||||
if len(keys) != 0 {
|
if len(keys) != 0 {
|
||||||
t.Error("Parsed incorrect number of SSH keys")
|
t.Error("Parsed incorrect number of SSH keys")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user