// SchemaAddFromConfig means you have a Schema-Source you want to add
358680
func (m *Registry) SchemaAddFromConfig(conf *ConfigSource) error {

	source, err := m.GetSource(conf.SourceType)
	if err != nil {
		u.Warnf("could not find source type %q  \nregistry: %s", conf.SourceType, m.String())
		return err
	}

	s := NewSchema(conf.Name)
	s.Conf = conf
	s.DS = source
	if err := s.DS.Setup(s); err != nil {
		u.Errorf("Error setuping up %+v  err=%v", conf, err)
		return err
	}

	// If we specify a parent schema to add this child schema to
	if conf.Schema != "" && conf.Schema != s.Name {
		_, ok := m.Schema(conf.Schema)
		if !ok {
			ps := NewSchema(conf.Schema)
			err := m.SchemaAdd(ps)
			if err != nil {
				u.Warnf("could not create parent schema %v", err)
				return err
			}
		}
		if err = m.SchemaAddChild(conf.Schema, s); err != nil {
			return nil
		}
		return nil
	}

	return m.SchemaAdd(s)
}
1370392
func (me identifier) Schema(schema string) IdentifierExpression {
	ret := me.clone()
	ret.schema = schema
	return ret
}
379738
func NewManifestBuilder(bs distribution.BlobService, configMediaType string, configJSON []byte) distribution.ManifestBuilder {
	mb := &builder{
		bs:              bs,
		configMediaType: configMediaType,
		configJSON:      make([]byte, len(configJSON)),
	}
	copy(mb.configJSON, configJSON)

	return mb
}
571790
func (s *Staert) LoadConfig() (interface{}, error) {
	for _, src := range s.sources {
		// Type assertion
		if flg, ok := src.(*flaeg.Flaeg); ok {
			fCmd, err := flg.GetCommand()
			if err != nil {
				return nil, err
			}

			// if fleag sub-command
			if s.command != fCmd {
				// if parseAllSources
				if fCmd.Metadata["parseAllSources"] == "true" {
					fCmdConfigType := reflect.TypeOf(fCmd.Config)
					sCmdConfigType := reflect.TypeOf(s.command.Config)
					if fCmdConfigType != sCmdConfigType {
						return nil, fmt.Errorf("command %s : Config type doesn't match with root command config type. Expected %s got %s",
							fCmd.Name, sCmdConfigType.Name(), fCmdConfigType.Name())
					}
					s.command = fCmd
				} else {
					// (not parseAllSources)
					s.command, err = flg.Parse(fCmd)
					return s.command.Config, err
				}
			}
		}
	}
	err := s.parseConfigAllSources(s.command)
	return s.command.Config, err
}
182099
func NewConfigFromString(rootLogger *logrus.Logger, input []byte) Config {
	logger := rootLogger.WithFields(logrus.Fields{"prefix": "config"})
	return newConfigFromString(logger, input)
}
1236188
func (confSrc *MemoryConfigurationSource) AddKeyValue(key string, value interface{}) error {
	if !confSrc.ChanStatus {
		<-confSrc.CallbackCheck
		confSrc.ChanStatus = true
	}

	event := new(core.Event)
	event.EventSource = confSrc.GetSourceName()
	event.Key = key
	event.Value = value

	confSrc.Lock()
	defer confSrc.Unlock()
	if _, ok := confSrc.Configurations[key]; !ok {
		event.EventType = core.Create
	} else {
		event.EventType = core.Update
	}

	confSrc.Configurations[key] = value

	if confSrc.callback != nil {
		confSrc.callback.OnEvent(event)
	}

	return nil
}
213459
func (o *ObjectConstraint) SchemaDependency(from string, c Constraint) *ObjectConstraint {
	o.deplock.Lock()
	defer o.deplock.Unlock()

	o.schemadeps[from] = c
	return o
}
44724
func (sl *SchemaLoader) Compile(rootSchema JSONLoader) (*Schema, error) {

	ref, err := rootSchema.JsonReference()

	if err != nil {
		return nil, err
	}

	d := Schema{}
	d.pool = sl.pool
	d.pool.jsonLoaderFactory = rootSchema.LoaderFactory()
	d.documentReference = ref
	d.referencePool = newSchemaReferencePool()

	var doc interface{}
	if ref.String() != "" {
		// Get document from schema pool
		spd, err := d.pool.GetDocument(d.documentReference)
		if err != nil {
			return nil, err
		}
		doc = spd.Document
	} else {
		// Load JSON directly
		doc, err = rootSchema.LoadJSON()
		if err != nil {
			return nil, err
		}
		// References need only be parsed if loading JSON directly
		//  as pool.GetDocument already does this for us if loading by reference
		err = sl.pool.parseReferences(doc, ref, true)
		if err != nil {
			return nil, err
		}
	}

	if sl.Validate {
		if err := sl.validateMetaschema(doc); err != nil {
			return nil, err
		}
	}

	draft := sl.Draft
	if sl.AutoDetect {
		_, detectedDraft, err := parseSchemaURL(doc)
		if err != nil {
			return nil, err
		}
		if detectedDraft != nil {
			draft = *detectedDraft
		}
	}

	err = d.parse(doc, draft)
	if err != nil {
		return nil, err
	}

	return &d, nil
}
1089
func RegisterSourceAsSchema(name string, source Source) error {

	// Since registry is a global, lets first lock that.
	registryMu.Lock()
	defer registryMu.Unlock()

	s := NewSchemaSource(name, source)
	source.Init()
	source.Setup(s)
	if err := registry.SchemaAdd(s); err != nil {
		return err
	}
	return discoverSchemaFromSource(s, registry.applyer)
}
303574
func (p *GRPCProvider) getDatasourceSchema(name string) providers.Schema {
	schema := p.getSchema()
	dataSchema, ok := schema.DataSources[name]
	if !ok {
		panic("unknown data source " + name)
	}
	return dataSchema
}
96846
func schemaDiff(before, after bigquery.Schema) string {
	ret, err := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
		A:        difflib.SplitLines(schemaString(before)),
		B:        difflib.SplitLines(schemaString(after)),
		FromFile: "Current",
		ToFile:   "New",
		Context:  3,
		Eol:      "\n",
	})
	if err != nil {
		// GetUnifiedDiffString returns an error only if it fails
		// to write to a bytes.Buffer, which either cannot happen or we better
		// panic.
		panic(err)
	}
	return ret
}
1174428
func HyperxlDiskAdd(ctx LibxlCtxPtr, domid uint32, source, target string, backend LibxlDiskBackend, format LibxlDiskFormat) int {
	var disk *HyperxlDiskConfig = &HyperxlDiskConfig{
		source:  C.CString(source),
		target:  C.CString(target),
		backend: (C.libxl_disk_backend)(backend),
		format:  (C.libxl_disk_format)(format),
	}
	return (int)(C.hyperxl_disk_add((*C.struct_libxl__ctx)(ctx), (C.uint32_t)(domid), (*C.struct_hyperxl_disk_config)(disk)))
}
130670
func ConfigDefaults(providerDefaults schema.Defaults) schema.Defaults {
	defaults := schema.Defaults{
		JujuApplicationPath: JujuDefaultApplicationPath,
	}
	for key, value := range providerDefaults {
		if value == schema.Omit {
			continue
		}
		defaults[key] = value
	}
	return defaults
}
975346
func (*badgerdsPlugin) DatastoreConfigParser() fsrepo.ConfigFromMap {
	return func(params map[string]interface{}) (fsrepo.DatastoreConfig, error) {
		var c datastoreConfig
		var ok bool

		c.path, ok = params["path"].(string)
		if !ok {
			return nil, fmt.Errorf("'path' field is missing or not string")
		}

		sw, ok := params["syncWrites"]
		if !ok {
			c.syncWrites = true
		} else {
			if swb, ok := sw.(bool); ok {
				c.syncWrites = swb
			} else {
				return nil, fmt.Errorf("'syncWrites' field was not a boolean")
			}
		}

		truncate, ok := params["truncate"]
		if !ok {
			c.truncate = true
		} else {
			if truncate, ok := truncate.(bool); ok {
				c.truncate = truncate
			} else {
				return nil, fmt.Errorf("'truncate' field was not a boolean")
			}
		}

		vls, ok := params["vlogFileSize"]
		if !ok {
			// default to 1GiB
			c.vlogFileSize = badgerds.DefaultOptions.ValueLogFileSize
		} else {
			if vlogSize, ok := vls.(string); ok {
				s, err := humanize.ParseBytes(vlogSize)
				if err != nil {
					return nil, err
				}
				c.vlogFileSize = int64(s)
			} else {
				return nil, fmt.Errorf("'vlogFileSize' field was not a string")
			}
		}

		return &c, nil
	}
}
1128532
func discoverSchemaFromSource(s *Schema, applyer Applyer) error {

	if s.DS == nil {
		return fmt.Errorf("Missing datasource for schema %q", s.Name)
	}
	if s.InfoSchema == nil {
		return fmt.Errorf("Missing InfoSchema for schema %q", s.Name)
	}

	if err := s.DS.Setup(s); err != nil {
		u.Errorf("Error setting up %v  %v", s.Name, err)
		return err
	}

	// For each table in source schema
	for _, tableName := range s.Tables() {
		tbl, err := s.Table(tableName)
		if err != nil || tbl == nil {
			u.Warnf("Missing table?? %q", tableName)
			continue
		}
		applyer.AddOrUpdateOnSchema(s, tbl)
	}

	return nil
}
1303660
func scopeSchemaFromBytes(schemaBytes []byte) *ScopeAddrSchema {
	return &ScopeAddrSchema{
		InternalAddrType: AddressType(schemaBytes[0]),
		ExternalAddrType: AddressType(schemaBytes[1]),
	}
}
148410
func NewConfig(attrs map[string]interface{}, schema environschema.Fields, defaults schema.Defaults) (*Config, error) {
	cfg := &Config{schema: schema, defaults: defaults}
	if err := cfg.setAttributes(attrs); err != nil {
		return nil, errors.Trace(err)
	}
	return cfg, nil
}