// convert from into normalized *Config checking for errors
// before merging generated(normalized) config with current config
8521
func normalize(opts *options, from interface{}) (*Config, Error) {
	vFrom := chaseValue(reflect.ValueOf(from))

	switch vFrom.Type() {
	case tConfig:
		return vFrom.Addr().Interface().(*Config), nil
	case tConfigMap:
		return normalizeMap(opts, vFrom)
	default:
		// try to convert vFrom into Config (rebranding)
		if v, ok := tryTConfig(vFrom); ok {
			return v.Addr().Interface().(*Config), nil
		}

		// normalize given map/struct value
		switch vFrom.Kind() {
		case reflect.Struct:
			return normalizeStruct(opts, vFrom)
		case reflect.Map:
			return normalizeMap(opts, vFrom)
		case reflect.Array, reflect.Slice:
			tmp, err := normalizeArray(opts, tagOptions{}, context{}, vFrom)
			if err != nil {
				return nil, err
			}
			c, _ := tmp.toConfig(opts)
			return c, nil
		}

	}

	return nil, raiseInvalidTopLevelType(from, opts.meta)
}
283829
func normalizeToEnvCentre(line1Start, line1End, line2Start, line2End, normPt geom.Coord) {
	// Note: All these "max" checks are inlined for performance.
	// It would be visually cleaner to do that but requires more function calls

	line1MinX := line1End[0]
	if line1Start[0] < line1End[0] {
		line1MinX = line1Start[0]
	}

	line1MinY := line1End[1]
	if line1Start[1] < line1End[1] {
		line1MinY = line1Start[1]
	}
	line1MaxX := line1End[0]
	if line1Start[0] > line1End[0] {
		line1MaxX = line1Start[0]
	}
	line1MaxY := line1End[1]
	if line1Start[1] > line1End[1] {
		line1MaxY = line1Start[1]
	}

	line2MinX := line2End[0]
	if line2Start[0] < line2End[0] {
		line2MinX = line2Start[0]
	}
	line2MinY := line2End[1]
	if line2Start[1] < line2End[1] {
		line2MinY = line2Start[1]
	}
	line2MaxX := line2End[0]
	if line2Start[0] > line2End[0] {
		line2MaxX = line2Start[0]
	}
	line2MaxY := line2End[1]
	if line2Start[1] > line2End[1] {
		line2MaxY = line2Start[1]
	}

	intMinX := line2MinX
	if line1MinX > line2MinX {
		intMinX = line1MinX
	}
	intMaxX := line2MaxX
	if line1MaxX < line2MaxX {
		intMaxX = line1MaxX
	}
	intMinY := line2MinY
	if line1MinY > line2MinY {
		intMinY = line1MinY
	}
	intMaxY := line2MaxY
	if line1MaxY < line2MaxY {
		intMaxY = line1MaxY
	}

	intMidX := (intMinX + intMaxX) / 2.0
	intMidY := (intMinY + intMaxY) / 2.0
	normPt[0] = intMidX
	normPt[1] = intMidY

	line1Start[0] -= normPt[0]
	line1Start[1] -= normPt[1]
	line1End[0] -= normPt[0]
	line1End[1] -= normPt[1]
	line2Start[0] -= normPt[0]
	line2Start[1] -= normPt[1]
	line2End[0] -= normPt[0]
	line2End[1] -= normPt[1]
}
1161646
func (f *File) Normalize() error {
	me := errors.MultiError(nil)
	for tname, t := range f.Template {
		if err := t.Normalize(); err != nil {
			me = append(me, fmt.Errorf("for template %q: %s", tname, err))
		}
	}
	if len(me) > 0 {
		return me
	}
	return nil
}
868144
func (converter PatternToListConverter) Convert(value interface{}, item AttributeAccessor) (interface{}, error) {
	result := []string{}
	i := 0
	for {
		key := AttributeExpression(strings.Replace(converter.pattern, "?", strconv.Itoa(i), 1))
		if v := item.Get(key); v != nil {
			result = append(result, v.(string))
		} else {
			break
		}
		i++
	}
	return result, nil
}
950613
func normalize(name string, conf common.Conf, scriptPath string, renderer confRenderer) (common.Conf, []byte) {
	var data []byte

	var cmds []string
	if conf.Logfile != "" {
		filename := conf.Logfile
		cmds = append(cmds, "# Set up logging.")
		cmds = append(cmds, renderer.Touch(filename, nil)...)
		// TODO(ericsnow) We should drop the assumption that the logfile
		// is syslog.
		user, group := syslogUserGroup()
		cmds = append(cmds, renderer.Chown(filename, user, group)...)
		cmds = append(cmds, renderer.Chmod(filename, 0600)...)
		cmds = append(cmds, renderer.RedirectOutput(filename)...)
		cmds = append(cmds, renderer.RedirectFD("out", "err")...)
		cmds = append(cmds,
			"",
			"# Run the script.",
		)
		// We leave conf.Logfile alone (it will be ignored during validation).
	}
	cmds = append(cmds, conf.ExecStart)

	if conf.ExtraScript != "" {
		cmds = append([]string{conf.ExtraScript}, cmds...)
		conf.ExtraScript = ""
	}
	if !isSimpleCommand(strings.Join(cmds, "\n")) {
		data = renderer.RenderScript(cmds)
		conf.ExecStart = scriptPath
	}

	if len(conf.Env) == 0 {
		conf.Env = nil
	}

	if len(conf.Limit) == 0 {
		conf.Limit = nil
	}

	if conf.Transient {
		// TODO(ericsnow) Handle Transient via systemd-run command?
		conf.ExecStopPost = commands{}.disable(name)
	}

	return conf, data
}
378899
func (c *safeConverterWrapper) Convert(in, out, context interface{}) error {
	inObject, ok := in.(runtime.Object)
	if !ok {
		return fmt.Errorf("input type %T in not valid for object conversion", in)
	}
	return c.unsafe.Convert(inObject.DeepCopyObject(), out, context)
}
287607
func (c ConversionFuncs) Merge(other ConversionFuncs) ConversionFuncs {
	merged := NewConversionFuncs()
	for k, v := range c.fns {
		merged.fns[k] = v
	}
	for k, v := range other.fns {
		merged.fns[k] = v
	}
	return merged
}
922693
func (step *StepModel) Normalize() error {
	for _, input := range step.Inputs {
		if err := input.Normalize(); err != nil {
			return err
		}
	}

	for _, output := range step.Outputs {
		if err := output.Normalize(); err != nil {
			return err
		}
	}

	normalizedMeta, err := JSONMarshallable(step.Meta)
	if err != nil {
		return err
	}
	step.Meta = normalizedMeta

	return nil
}
306007
func (d *DepsStage) Normalize() error {
	for _, d := range d.Deps {
		if err := d.Normalize(); err != nil {
			return err
		}
	}
	return nil
}
1109781
func (a *FinishAttemptReq) Normalize() error {
	if err := a.Auth.Normalize(); err != nil {
		return err
	}
	if err := a.Data.Normalize(); err != nil {
		return err
	}
	if a.Data == nil || len(a.Data.Object) == 0 {
		return errors.New("data field is required")
	}
	return nil
}
208743
func Convert_v1_EncryptionConfiguration_To_config_EncryptionConfiguration(in *EncryptionConfiguration, out *config.EncryptionConfiguration, s conversion.Scope) error {
	return autoConvert_v1_EncryptionConfiguration_To_config_EncryptionConfiguration(in, out, s)
}
1333938
func normalize(i interface{}) (int, error) {
	switch v := i.(type) {
	case int:
		return v, nil
	case int32:
		return int(v), nil
	case int64:
		return int(v), nil
	case float32:
		return int(v + 0.5), nil
	case float64:
		// We need this check here because NaN can be a float. Casting NaN to
		// int results in a large negative number. Even after you add 0.5.
		if math.IsNaN(v) {
			return -1, fmt.Errorf("Could not normalize NaN %v", v)
		}
		return int(v + 0.5), nil
	case string:
		f, err := strconv.ParseFloat(v, 64)
		if err != nil {
			return -1, err
		}
		return normalize(f)
	default:
		return -1, fmt.Errorf("Could not normalize %q", v)
	}
}
494529
func FromConfigString(config, configType string) (Provider, error) {
	v := newViper()
	m, err := readConfig(metadecoders.FormatFromString(configType), []byte(config))
	if err != nil {
		return nil, err
	}

	v.MergeConfigMap(m)

	return v, nil
}
1164205
func (v *Value_Object) Normalize() error {
	newObj, err := NormalizeJSON(v.Object, true)
	if err != nil {
		return err
	}
	v.Object = newObj
	return nil
}
681485
func (n *normalizer) Normalize(un *unstructured.Unstructured) error {
	matched := make([]normalizerPatch, 0)
	for _, patch := range n.patches {
		groupKind := un.GroupVersionKind().GroupKind()
		if groupKind == patch.groupKind &&
			(patch.name == "" || patch.name == un.GetName()) &&
			(patch.namespace == "" || patch.namespace == un.GetNamespace()) {

			matched = append(matched, patch)
		}
	}
	if len(matched) == 0 {
		return nil
	}

	docData, err := json.Marshal(un)
	if err != nil {
		return err
	}

	for _, patch := range matched {
		patchedData, err := patch.patch.Apply(docData)
		if err != nil {
			// bug?
			if strings.HasPrefix(err.Error(), "Unable to remove nonexistent key") {
				continue
			}
			return err
		}
		docData = patchedData
	}

	err = json.Unmarshal(docData, un)
	if err != nil {
		return err
	}
	return nil
}
226212
func (c Config) Merge(cfg []Config) (config Config) {

	if len(cfg) > 0 {
		config = cfg[0]
		mergo.Merge(&config, c)
	} else {
		_default := c
		config = _default
	}

	return
}
155655
func Convert_v1_SessionConfig_To_config_SessionConfig(in *v1.SessionConfig, out *config.SessionConfig, s conversion.Scope) error {
	return autoConvert_v1_SessionConfig_To_config_SessionConfig(in, out, s)
}