From dda314b518c5a62ffcffed4c4d43683b0caf81b2 Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Mon, 15 Sep 2014 15:38:31 -0700 Subject: [PATCH] flags: add validate flag This will allow the user to run a standalone validation. --- coreos-cloudinit.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/coreos-cloudinit.go b/coreos-cloudinit.go index cb7f879..a482d94 100644 --- a/coreos-cloudinit.go +++ b/coreos-cloudinit.go @@ -24,6 +24,7 @@ import ( "time" "github.com/coreos/coreos-cloudinit/config" + "github.com/coreos/coreos-cloudinit/config/validate" "github.com/coreos/coreos-cloudinit/datasource" "github.com/coreos/coreos-cloudinit/datasource/configdrive" "github.com/coreos/coreos-cloudinit/datasource/file" @@ -64,6 +65,7 @@ var ( workspace string sshKeyName string oem string + validate bool }{} ) @@ -83,6 +85,7 @@ func init() { flag.StringVar(&flags.convertNetconf, "convert-netconf", "", "Read the network config provided in cloud-drive and translate it from the specified format into networkd unit files") flag.StringVar(&flags.workspace, "workspace", "/var/lib/coreos-cloudinit", "Base directory coreos-cloudinit should use to store data") flag.StringVar(&flags.sshKeyName, "ssh-key-name", initialize.DefaultSSHKeyName, "Add SSH keys to the system with the given name") + flag.BoolVar(&flags.validate, "validate", false, "[EXPERIMENTAL] Validate the user-data but do not apply it to the system") } type oemConfig map[string]string @@ -158,6 +161,22 @@ func main() { failure = true } + if report, err := validate.Validate(userdataBytes); err == nil { + ret := 0 + for _, e := range report.Entries() { + fmt.Println(e) + ret = 1 + } + if flags.validate { + os.Exit(ret) + } + } else { + fmt.Printf("Failed while validating user_data (%q)\n", err) + if flags.validate { + os.Exit(1) + } + } + fmt.Printf("Fetching meta-data from datasource of type %q\n", ds.Type()) metadataBytes, err := ds.FetchMetadata() if err != nil {