script: move Script into config package

This commit is contained in:
Alex Crawford
2014-09-27 11:11:57 -07:00
parent 3e2823df1b
commit 6e2db882e6
6 changed files with 38 additions and 20 deletions

View File

@@ -45,6 +45,17 @@ type CloudConfig struct {
NetworkConfig string `yaml:"-"`
}
func IsCloudConfig(userdata string) bool {
header := strings.SplitN(userdata, "\n", 2)[0]
// Explicitly trim the header so we can handle user-data from
// non-unix operating systems. The rest of the file is parsed
// by yaml, which correctly handles CRLF.
header = strings.TrimSuffix(header, "\r")
return (header == "#cloud-config")
}
// NewCloudConfig instantiates a new CloudConfig from the given contents (a
// string of YAML), returning any error encountered. It will ignore unknown
// fields but log encountering them.

16
config/script.go Normal file
View File

@@ -0,0 +1,16 @@
package config
import (
"strings"
)
type Script []byte
func IsScript(userdata string) bool {
header := strings.SplitN(userdata, "\n", 2)[0]
return strings.HasPrefix(header, "#!")
}
func NewScript(userdata string) (Script, error) {
return Script(userdata), nil
}