feat(metadata): Distinguish between userdata and metadata for datasources

This commit is contained in:
Alex Crawford
2014-06-18 11:58:18 -07:00
parent 29ed6b38bd
commit 840c208b60
9 changed files with 55 additions and 11 deletions

View File

@@ -34,10 +34,11 @@ type CloudConfig struct {
Update UpdateConfig
Units []system.Unit
}
WriteFiles []system.File `yaml:"write_files"`
Hostname string
Users []system.User
ManageEtcHosts EtcHosts `yaml:"manage_etc_hosts"`
WriteFiles []system.File `yaml:"write_files"`
Hostname string
Users []system.User
ManageEtcHosts EtcHosts `yaml:"manage_etc_hosts"`
NetworkConfigPath string
}
type warner func(format string, v ...interface{})

26
initialize/meta_data.go Normal file
View File

@@ -0,0 +1,26 @@
package initialize
import (
"encoding/json"
)
func ParseMetaData(contents string) (cfg CloudConfig, err error) {
var metadata struct {
SSHAuthorizedKeyMap map[string]string `json:"public_keys"`
Hostname string `json:"hostname"`
NetworkConfig struct {
ContentPath string `json:"content_path"`
} `json:"network_config"`
}
if err = json.Unmarshal([]byte(contents), &metadata); err != nil {
return
}
cfg.SSHAuthorizedKeys = make([]string, 0, len(metadata.SSHAuthorizedKeyMap))
for _, key := range metadata.SSHAuthorizedKeyMap {
cfg.SSHAuthorizedKeys = append(cfg.SSHAuthorizedKeys, key)
}
cfg.Hostname = metadata.Hostname
cfg.NetworkConfigPath = metadata.NetworkConfig.ContentPath
return
}