func (s *S) TestBool(c *C) { sch := schema.Bool() out, err := sch.Coerce(true, aPath) c.Assert(err, IsNil) c.Assert(out, Equals, true) out, err = sch.Coerce(false, aPath) c.Assert(err, IsNil) c.Assert(out, Equals, false) out, err = sch.Coerce(1, aPath) c.Assert(out, IsNil) c.Assert(err, ErrorMatches, "<path>: expected bool, got 1") out, err = sch.Coerce(nil, aPath) c.Assert(out, IsNil) c.Assert(err, ErrorMatches, "<path>: expected bool, got nothing") }
// 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(), } var configDefaults = schema.Defaults{ "broken": "", "secret": "pork", } type environConfig struct { *config.Config attrs map[string]interface{} } func (c *environConfig) stateServer() bool { return c.attrs["state-server"].(bool)
if err != nil { return } m := v.(map[string]interface{}) if _, ok := m["limit"]; !ok { m["limit"] = c.limit } return ifaceSchema.Coerce(m, path) } var ifaceSchema = schema.FieldMap( schema.Fields{ "interface": schema.String(), "limit": schema.OneOf(schema.Const(nil), schema.Int()), "scope": schema.OneOf(schema.Const(string(ScopeGlobal)), schema.Const(string(ScopeContainer))), "optional": schema.Bool(), }, schema.Defaults{ "scope": string(ScopeGlobal), "optional": false, }, ) var charmSchema = schema.FieldMap( schema.Fields{ "name": schema.String(), "summary": schema.String(), "description": schema.String(), "peers": schema.StringMap(ifaceExpander(int64(1))), "provides": schema.StringMap(ifaceExpander(nil)), "requires": schema.StringMap(ifaceExpander(int64(1))),
"net/url" ) 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(), "public-bucket": schema.String(), "public-bucket-url": schema.String(), "use-floating-ip": schema.Bool(), // These next keys are deprecated and ignored. We keep them them in the schema // so existing configs do not error. "default-image-id": schema.String(), "default-instance-type": schema.String(), } var configDefaults = schema.Defaults{ "username": "", "password": "", "tenant-name": "", "auth-url": "", "auth-mode": string(AuthUserPass), "access-key": "", "secret-key": "", "region": "", "control-bucket": "",
} } return out, nil } var validTypes = map[string]reflect.Kind{ "string": reflect.String, "int": reflect.Int64, "boolean": reflect.Bool, "float": reflect.Float64, } var optionSchema = schema.FieldMap( schema.Fields{ "type": schema.OneOf(schema.Const("string"), schema.Const("int"), schema.Const("float"), schema.Const("boolean")), "default": schema.OneOf(schema.String(), schema.Int(), schema.Float(), schema.Bool()), "description": schema.String(), }, schema.Defaults{ "default": schema.Omit, "description": schema.Omit, }, ) var configSchema = schema.FieldMap( schema.Fields{ "options": schema.StringMap(optionSchema), }, nil, )
m := c.AllAttrs() for k, v := range attrs { m[k] = v } return New(m) } var fields = schema.Fields{ "type": schema.String(), "name": schema.String(), "default-series": 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(), "ssl-hostname-verification": schema.Bool(), "state-port": schema.ForceInt(), "api-port": schema.ForceInt(), } var defaults = schema.Defaults{ "default-series": DefaultSeries, "authorized-keys": "", "authorized-keys-path": "", "firewall-mode": FwDefault,
if checker := optionTypeCheckers[option.Type]; checker != nil { if value, err = checker.Coerce(value, nil); err != nil { return nil, err } else if value == "" { value = nil } 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. Empty // string values are returned as nil. func (option Option) parse(name, str string) (_ interface{}, err error) { if str == "" { return nil, nil } defer option.error(&err, name, str) switch option.Type { case "string": return str, nil case "int": return strconv.ParseInt(str, 10, 64)