file: refactor config
- Seperate the config from Permissions() - Add YAML tags for the fields
This commit is contained in:
@@ -37,7 +37,7 @@ type CloudConfig struct {
|
||||
Update config.Update
|
||||
Units []config.Unit
|
||||
}
|
||||
WriteFiles []system.File `yaml:"write_files"`
|
||||
WriteFiles []config.File `yaml:"write_files"`
|
||||
Hostname string
|
||||
Users []system.User
|
||||
ManageEtcHosts config.EtcHosts `yaml:"manage_etc_hosts"`
|
||||
@@ -217,6 +217,11 @@ func Apply(cfg CloudConfig, env *Environment) error {
|
||||
}
|
||||
}
|
||||
|
||||
var writeFiles []system.File
|
||||
for _, file := range cfg.WriteFiles {
|
||||
writeFiles = append(writeFiles, system.File{file})
|
||||
}
|
||||
|
||||
for _, ccf := range []CloudConfigFile{
|
||||
system.OEM{cfg.Coreos.OEM},
|
||||
system.Update{cfg.Coreos.Update, system.DefaultReadConfig},
|
||||
@@ -227,7 +232,7 @@ func Apply(cfg CloudConfig, env *Environment) error {
|
||||
return err
|
||||
}
|
||||
if f != nil {
|
||||
cfg.WriteFiles = append(cfg.WriteFiles, *f)
|
||||
writeFiles = append(writeFiles, *f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +254,7 @@ func Apply(cfg CloudConfig, env *Environment) error {
|
||||
}
|
||||
|
||||
wroteEnvironment := false
|
||||
for _, file := range cfg.WriteFiles {
|
||||
for _, file := range writeFiles {
|
||||
fullPath, err := system.WriteFile(&file, env.Root())
|
||||
if err != nil {
|
||||
return err
|
||||
|
@@ -178,7 +178,7 @@ hostname: trontastic
|
||||
if len(cfg.WriteFiles) != 1 {
|
||||
t.Error("Failed to parse correct number of write_files")
|
||||
} else {
|
||||
wf := cfg.WriteFiles[0]
|
||||
wf := system.File{cfg.WriteFiles[0]}
|
||||
if wf.Content != "penny\nelroy\n" {
|
||||
t.Errorf("WriteFile has incorrect contents '%s'", wf.Content)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/coreos-cloudinit/config"
|
||||
"github.com/coreos/coreos-cloudinit/system"
|
||||
)
|
||||
|
||||
@@ -81,9 +82,9 @@ func (e *Environment) Apply(data string) string {
|
||||
|
||||
func (e *Environment) DefaultEnvironmentFile() *system.EnvFile {
|
||||
ef := system.EnvFile{
|
||||
File: &system.File{
|
||||
File: &system.File{config.File{
|
||||
Path: "/etc/environment",
|
||||
},
|
||||
}},
|
||||
Vars: map[string]string{},
|
||||
}
|
||||
if ip, ok := e.substitutions["$public_ipv4"]; ok && len(ip) > 0 {
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/coreos-cloudinit/config"
|
||||
"github.com/coreos/coreos-cloudinit/system"
|
||||
)
|
||||
|
||||
@@ -31,21 +32,21 @@ func PersistScriptInWorkspace(script system.Script, workspace string) (string, e
|
||||
|
||||
relpath := strings.TrimPrefix(tmp.Name(), workspace)
|
||||
|
||||
file := system.File{
|
||||
file := system.File{config.File{
|
||||
Path: relpath,
|
||||
RawFilePermissions: "0744",
|
||||
Content: string(script),
|
||||
}
|
||||
}}
|
||||
|
||||
return system.WriteFile(&file, workspace)
|
||||
}
|
||||
|
||||
func PersistUnitNameInWorkspace(name string, workspace string) error {
|
||||
file := system.File{
|
||||
file := system.File{config.File{
|
||||
Path: path.Join("scripts", "unit-name"),
|
||||
RawFilePermissions: "0644",
|
||||
Content: name,
|
||||
}
|
||||
}}
|
||||
_, err := system.WriteFile(&file, workspace)
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user