flags: add validate flag
This will allow the user to run a standalone validation.
This commit is contained in:
parent
055a3c339a
commit
dda314b518
@ -24,6 +24,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/coreos-cloudinit/config"
|
"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"
|
||||||
"github.com/coreos/coreos-cloudinit/datasource/configdrive"
|
"github.com/coreos/coreos-cloudinit/datasource/configdrive"
|
||||||
"github.com/coreos/coreos-cloudinit/datasource/file"
|
"github.com/coreos/coreos-cloudinit/datasource/file"
|
||||||
@ -64,6 +65,7 @@ var (
|
|||||||
workspace string
|
workspace string
|
||||||
sshKeyName string
|
sshKeyName string
|
||||||
oem 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.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.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.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
|
type oemConfig map[string]string
|
||||||
@ -158,6 +161,22 @@ func main() {
|
|||||||
failure = true
|
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())
|
fmt.Printf("Fetching meta-data from datasource of type %q\n", ds.Type())
|
||||||
metadataBytes, err := ds.FetchMetadata()
|
metadataBytes, err := ds.FetchMetadata()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user