func (s *S) TestMap(c *gc.C) { sch := schema.Map(schema.String(), schema.Int()) out, err := sch.Coerce(map[string]interface{}{"a": 1, "b": int8(2)}, aPath) c.Assert(err, gc.IsNil) c.Assert(out, gc.DeepEquals, map[interface{}]interface{}{"a": int64(1), "b": int64(2)}) out, err = sch.Coerce(42, aPath) c.Assert(out, gc.IsNil) c.Assert(err, gc.ErrorMatches, "<path>: expected map, got int\\(42\\)") out, err = sch.Coerce(nil, aPath) c.Assert(out, gc.IsNil) c.Assert(err, gc.ErrorMatches, "<path>: expected map, got nothing") out, err = sch.Coerce(map[int]int{1: 1}, aPath) c.Assert(out, gc.IsNil) c.Assert(err, gc.ErrorMatches, "<path>: expected string, got int\\(1\\)") out, err = sch.Coerce(map[string]bool{"a": true}, aPath) c.Assert(out, gc.IsNil) c.Assert(err, gc.ErrorMatches, `<path>\.a: expected int, got bool\(true\)`) // First path entry shouldn't have dots in an error message. out, err = sch.Coerce(map[string]bool{"a": true}, nil) c.Assert(out, gc.IsNil) c.Assert(err, gc.ErrorMatches, `a: expected int, got bool\(true\)`) }
func (*ConfigSuite) TestValidateUnknownAttrs(c *gc.C) { defer makeFakeHome(c).Restore() cfg, err := config.New(config.UseDefaults, map[string]interface{}{ "name": "myenv", "type": "other", "known": "this", "unknown": "that", }) // No fields: all attrs passed through. attrs, err := cfg.ValidateUnknownAttrs(nil, nil) c.Assert(err, gc.IsNil) c.Assert(attrs, gc.DeepEquals, map[string]interface{}{ "known": "this", "unknown": "that", }) // Valid field: that and other attrs passed through. fields := schema.Fields{"known": schema.String()} attrs, err = cfg.ValidateUnknownAttrs(fields, nil) c.Assert(err, gc.IsNil) c.Assert(attrs, gc.DeepEquals, map[string]interface{}{ "known": "this", "unknown": "that", }) // Default field: inserted. fields["default"] = schema.String() defaults := schema.Defaults{"default": "the other"} attrs, err = cfg.ValidateUnknownAttrs(fields, defaults) c.Assert(err, gc.IsNil) c.Assert(attrs, gc.DeepEquals, map[string]interface{}{ "known": "this", "unknown": "that", "default": "the other", }) // Invalid field: failure. fields["known"] = schema.Int() _, err = cfg.ValidateUnknownAttrs(fields, defaults) c.Assert(err, gc.ErrorMatches, `known: expected int, got string\("this"\)`) }
func (s *S) TestString(c *gc.C) { sch := schema.String() out, err := sch.Coerce("foo", aPath) c.Assert(err, gc.IsNil) c.Assert(out, gc.Equals, "foo") out, err = sch.Coerce(true, aPath) c.Assert(out, gc.IsNil) c.Assert(err, gc.ErrorMatches, `<path>: expected string, got bool\(true\)`) out, err = sch.Coerce(nil, aPath) c.Assert(out, gc.IsNil) c.Assert(err, gc.ErrorMatches, "<path>: expected string, got nothing") }
// Licensed under the AGPLv3, see LICENCE file for details. package openstack import ( "fmt" "net/url" "launchpad.net/goose/identity" "github.com/wallyworld/core/environs/config" "github.com/wallyworld/core/schema" ) var configFields = schema.Fields{ "username": schema.String(), "password": schema.String(), "tenant-name": schema.String(), "auth-url": schema.String(), "auth-mode": schema.String(), "access-key": schema.String(), "secret-key": schema.String(), "region": schema.String(), "control-bucket": schema.String(), "use-floating-ip": schema.Bool(), "use-default-secgroup": schema.Bool(), "network": schema.String(), } var configDefaults = schema.Defaults{ "username": "", "password": "",
MantaPrivateKeyFile = "MANTA_PRIVATE_KEY_FILE" DefaultPrivateKey = "~/.ssh/id_rsa" ) var environmentVariables = map[string]string{ "sdc-user": SdcAccount, "sdc-key-id": SdcKeyId, "sdc-url": SdcUrl, "manta-user": MantaUser, "manta-key-id": MantaKeyId, "manta-url": MantaUrl, "private-key-path": MantaPrivateKeyFile, } var configFields = schema.Fields{ "sdc-user": schema.String(), "sdc-key-id": schema.String(), "sdc-url": schema.String(), "manta-user": schema.String(), "manta-key-id": schema.String(), "manta-url": schema.String(), "private-key-path": schema.String(), "algorithm": schema.String(), "control-dir": schema.String(), "private-key": schema.String(), } var configDefaults = schema.Defaults{ "sdc-url": "https://us-west-1.api.joyentcloud.com", "manta-url": "https://us-east.manta.joyent.com", "algorithm": "rsa-sha256",
// Licensed under the AGPLv3, see LICENCE file for details. package manual import ( "fmt" "github.com/wallyworld/core/environs/config" "github.com/wallyworld/core/schema" ) const defaultStoragePort = 8040 var ( configFields = schema.Fields{ "bootstrap-host": schema.String(), "bootstrap-user": schema.String(), "storage-listen-ip": schema.String(), "storage-port": schema.ForceInt(), "storage-auth-key": schema.String(), "use-sshstorage": schema.Bool(), } configDefaults = schema.Defaults{ "bootstrap-user": "", "storage-listen-ip": "", "storage-port": defaultStoragePort, "use-sshstorage": true, } ) type environConfig struct {
// SetStorageDelay causes any storage download operation in any current // environment to be delayed for the given duration. func SetStorageDelay(d time.Duration) { p := &providerInstance p.mu.Lock() defer p.mu.Unlock() for _, st := range p.state { st.mu.Lock() st.storageDelay = d st.mu.Unlock() } } var configFields = schema.Fields{ "state-server": schema.Bool(), "broken": schema.String(), "secret": schema.String(), "state-id": schema.String(), } var configDefaults = schema.Defaults{ "broken": "", "secret": "pork", "state-id": schema.Omit, } type environConfig struct { *config.Config attrs map[string]interface{} } func (c *environConfig) stateServer() bool {
func (option Option) validate(name string, value interface{}) (_ interface{}, err error) { if value == nil { return nil, nil } defer option.error(&err, name, value) if checker := optionTypeCheckers[option.Type]; checker != nil { if value, err = checker.Coerce(value, nil); err != nil { return nil, err } return value, nil } panic(fmt.Errorf("option %q has unknown type %q", name, option.Type)) } var optionTypeCheckers = map[string]schema.Checker{ "string": schema.String(), "int": schema.Int(), "float": schema.Float(), "boolean": schema.Bool(), } // parse returns an appropriately-typed value for the supplied string, or // returns an error if it cannot be parsed to the correct type. func (option Option) parse(name, str string) (_ interface{}, err error) { defer option.error(&err, name, str) switch option.Type { case "string": return str, nil case "int": return strconv.ParseInt(str, 10, 64) case "float":
// Copyright 2013 Canonical Ltd. // Licensed under the AGPLv3, see LICENCE file for details. package azure import ( "fmt" "io/ioutil" "github.com/wallyworld/core/environs/config" "github.com/wallyworld/core/schema" ) var configFields = schema.Fields{ "location": schema.String(), "management-subscription-id": schema.String(), "management-certificate-path": schema.String(), "management-certificate": schema.String(), "storage-account-name": schema.String(), "force-image-name": schema.String(), "availability-sets-enabled": schema.Bool(), } var configDefaults = schema.Defaults{ "location": "", "management-certificate": "", "management-certificate-path": "", "force-image-name": "", // availability-sets-enabled is set to Omit (equivalent // to false) for backwards compatibility. "availability-sets-enabled": schema.Omit, }
"os" "path/filepath" "github.com/wallyworld/core/agent" "github.com/wallyworld/core/environs/config" "github.com/wallyworld/core/instance" "github.com/wallyworld/core/schema" ) var checkIfRoot = func() bool { return os.Getuid() == 0 } var ( configFields = schema.Fields{ "root-dir": schema.String(), "bootstrap-ip": schema.String(), "network-bridge": schema.String(), "container": schema.String(), "storage-port": schema.ForceInt(), "namespace": schema.String(), "lxc-clone": schema.Bool(), "lxc-clone-aufs": schema.Bool(), } // The port defaults below are not entirely arbitrary. Local user web // frameworks often use 8000 or 8080, so I didn't want to use either of // these, but did want the familiarity of using something in the 8000 // range. configDefaults = schema.Defaults{ "root-dir": "", "network-bridge": "lxcbr0",
// Licensed under the AGPLv3, see LICENCE file for details. package maas import ( "errors" "fmt" "net/url" "strings" "github.com/wallyworld/core/environs/config" "github.com/wallyworld/core/schema" ) var configFields = schema.Fields{ "maas-server": schema.String(), // maas-oauth is a colon-separated triplet of: // consumer-key:resource-token:resource-secret "maas-oauth": schema.String(), // maas-agent-name is an optional UUID to group the instances // acquired from MAAS, to support multiple environments per MAAS user. "maas-agent-name": schema.String(), } var configDefaults = schema.Defaults{ // For backward-compatibility, maas-agent-name is the empty string // by default. However, new environments should all use a UUID. "maas-agent-name": "", } type maasEnvironConfig struct { *config.Config
delete(defined, k) } return New(NoDefaults, defined) } // Apply returns a new configuration that has the attributes of c plus attrs. func (c *Config) Apply(attrs map[string]interface{}) (*Config, error) { defined := c.AllAttrs() for k, v := range attrs { defined[k] = v } return New(NoDefaults, defined) } var fields = schema.Fields{ "type": schema.String(), "name": schema.String(), "default-series": schema.String(), "tools-metadata-url": schema.String(), "image-metadata-url": schema.String(), "image-stream": schema.String(), "authorized-keys": schema.String(), "authorized-keys-path": schema.String(), "firewall-mode": schema.String(), "agent-version": schema.String(), "development": schema.Bool(), "admin-secret": schema.String(), "ca-cert": schema.String(), "ca-cert-path": schema.String(), "ca-private-key": schema.String(), "ca-private-key-path": schema.String(),
// Copyright 2011, 2012, 2013 Canonical Ltd. // Licensed under the AGPLv3, see LICENCE file for details. package ec2 import ( "fmt" "launchpad.net/goamz/aws" "github.com/wallyworld/core/environs/config" "github.com/wallyworld/core/schema" ) var configFields = schema.Fields{ "access-key": schema.String(), "secret-key": schema.String(), "region": schema.String(), "control-bucket": schema.String(), } var configDefaults = schema.Defaults{ "access-key": "", "secret-key": "", "region": "us-east-1", } type environConfig struct { *config.Config attrs map[string]interface{} }
// interface: mysql // limit: // optional: false // // In all input cases, the output is the fully specified interface // representation as seen in the mysql interface description above. func ifaceExpander(limit interface{}) schema.Checker { return ifaceExpC{limit} } type ifaceExpC struct { limit interface{} } var ( stringC = schema.String() mapC = schema.StringMap(schema.Any()) ) func (c ifaceExpC) Coerce(v interface{}, path []string) (newv interface{}, err error) { s, err := stringC.Coerce(v, path) if err == nil { newv = map[string]interface{}{ "interface": s, "limit": c.limit, "optional": false, "scope": string(ScopeGlobal), } return }