// EnvVarsToMap constructs a map of environment name to value from a slice
// of env vars.
762796
func EnvVarsToMap(envs []EnvVar) map[string]string {
	result := map[string]string{}
	for _, env := range envs {
		result[env.Name] = env.Value
	}
	return result
}
1044900
func (opts *Options) valuesMap(m map[string]interface{}) (map[string]interface{}, error) {
	for _, skv := range opts.Values {
		if err := strvals.ParseInto(skv, m); err != nil {
			return nil, err
		}
	}
	return m, nil
}
463050
func manipulateEnv(path *pathexp.PathExp) []string {
	env := filterEnv()

	org := path.Org.Components()
	project := path.Project.Components()
	envs := path.Envs.Components()
	services := path.Services.Components()

	env = append(env, "TORUS_ORG="+org[0])
	env = append(env, "TORUS_PROJECT="+project[0])
	env = append(env, "TORUS_ENVIRONMENT="+envs[0])
	env = append(env, "TORUS_SERVICE="+services[0])

	return env
}
1319712
func (e *Env) NewEnv() *Env {
	return &Env{
		env:    make(map[string]reflect.Value),
		typ:    make(map[string]reflect.Type),
		parent: e,
		name:   e.name,
	}
}
1369964
func (envSerModel *EnvironmentItemOptionsModel) ParseFromInterfaceMap(input map[string]interface{}) error {
	for keyStr, value := range input {

		switch keyStr {
		case "title":
			envSerModel.Title = parseutil.CastToStringPtr(value)
		case "description":
			envSerModel.Description = parseutil.CastToStringPtr(value)
		case "summary":
			envSerModel.Summary = parseutil.CastToStringPtr(value)
		case "category":
			envSerModel.Category = parseutil.CastToStringPtr(value)
		case "value_options":
			castedValue, ok := value.([]string)
			if !ok {
				// try with []interface{} instead and cast the
				//  items to string
				castedValue = []string{}
				interfArr, ok := value.([]interface{})
				if !ok {
					return fmt.Errorf("invalid value type (%#v) for key: %s", value, keyStr)
				}
				for _, interfItm := range interfArr {
					castedItm, ok := interfItm.(string)
					if !ok {
						castedItm = parseutil.CastToString(interfItm)
						if castedItm == "" {
							return fmt.Errorf("not a string value (%#v) in value_options", interfItm)
						}
					}
					castedValue = append(castedValue, castedItm)
				}
			}
			envSerModel.ValueOptions = castedValue
		case "is_required":
			castedBoolPtr, ok := parseutil.CastToBoolPtr(value)
			if !ok {
				return fmt.Errorf("failed to parse bool value (%#v) for key (%s)", value, keyStr)
			}
			envSerModel.IsRequired = castedBoolPtr
		case "is_expand":
			castedBoolPtr, ok := parseutil.CastToBoolPtr(value)
			if !ok {
				return fmt.Errorf("failed to parse bool value (%#v) for key (%s)", value, keyStr)
			}
			envSerModel.IsExpand = castedBoolPtr
		case "is_sensitive":
			castedBoolPtr, ok := parseutil.CastToBoolPtr(value)
			if !ok {
				return fmt.Errorf("failed to parse bool value (%#v) for key (%s)", value, keyStr)
			}
			envSerModel.IsSensitive = castedBoolPtr
		case "is_dont_change_value":
			castedBoolPtr, ok := parseutil.CastToBoolPtr(value)
			if !ok {
				return fmt.Errorf("failed to parse bool value (%#v) for key (%s)", value, keyStr)
			}
			envSerModel.IsDontChangeValue = castedBoolPtr
		case "is_template":
			castedBoolPtr, ok := parseutil.CastToBoolPtr(value)
			if !ok {
				return fmt.Errorf("failed to parse bool value (%#v) for key (%s)", value, keyStr)
			}
			envSerModel.IsTemplate = castedBoolPtr
		case "skip_if_empty":
			castedBoolPtr, ok := parseutil.CastToBoolPtr(value)
			if !ok {
				return fmt.Errorf("failed to parse bool value (%#v) for key (%s)", value, keyStr)
			}
			envSerModel.SkipIfEmpty = castedBoolPtr
		case "unset":
			castedBoolPtr, ok := parseutil.CastToBoolPtr(value)
			if !ok {
				return fmt.Errorf("failed to parse bool value (%#v) for key (%s)", value, keyStr)
			}
			envSerModel.Unset = castedBoolPtr
		case "meta":
			castedMapStringInterface, ok := parseutil.CastToMapStringInterface(value)
			if !ok {
				return fmt.Errorf("failed to parse map[string]interface{} value (%#v) for key (%s)", value, keyStr)
			}
			envSerModel.Meta = castedMapStringInterface
		default:
			// intentional no-op case -- we just ignore unrecognized fields
		}
	}
	return nil
}
1066310
func envList(key, def string) []string {
	v := os.Getenv(key)
	if v == "" {
		v = def
	}
	return strings.Fields(v)
}
1227828
func dimsToMap(dims producers.Dimensions) map[string]string {
	results := map[string]string{
		"mesos_id":            dims.MesosID,
		"cluster_id":          dims.ClusterID,
		"container_id":        dims.ContainerID,
		"executor_id":         dims.ExecutorID,
		"framework_name":      dims.FrameworkName,
		"framework_id":        dims.FrameworkID,
		"framework_role":      dims.FrameworkRole,
		"framework_principal": dims.FrameworkPrincipal,
		"task_name":           dims.TaskName,
		"task_id":             dims.TaskID,
		"hostname":            dims.Hostname,
	}
	for k, v := range dims.Labels {
		results[k] = v
	}
	return results
}
419883
func copyEnvVars(prefix string) {
	prefix = strings.ToUpper(prefix)
	ps := prefix + "_"
	for _, e := range os.Environ() {
		kv := strings.SplitN(e, "=", 2)
		if len(kv) == 2 {
			k, v := kv[0], kv[1]
			if strings.HasPrefix(k, prefix) && !strings.HasPrefix(k, ps) {
				k2 := strings.Replace(k, prefix, ps, 1)
				os.Setenv(k2, v)
			}
		}
	}
}
265711
func (t *TaskEnv) Map() map[string]string {
	m := make(map[string]string, len(t.EnvMap))
	for k, v := range t.EnvMap {
		m[k] = v
	}

	return m
}
486561
func MapToList(envMap map[string]string) []string {
	out := []string{}
	for k, v := range envMap {
		out = append(out, k+"="+v)
	}
	return out
}
917736
func NewEnv() *Env {
	return &Env{
		env:    make(map[string]reflect.Value),
		typ:    make(map[string]reflect.Type),
		parent: nil,
	}
}
94403
func Env(key string, defaultValue string) string {
	val := os.Getenv(key)
	if len(val) == 0 {
		return defaultValue
	}
	return val
}
912782
func argsToEnv(from map[string]interface{}, to map[string]string) error {

	for k, v := range from {
		t := reflect.TypeOf(v)
		vv := reflect.ValueOf(v)

		k = "PLUGIN_" + strings.ToUpper(k)

		switch t.Kind() {
		case reflect.Bool:
			to[k] = strconv.FormatBool(vv.Bool())

		case reflect.String:
			to[k] = vv.String()

		case reflect.Int, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int8:
			to[k] = fmt.Sprintf("%v", vv.Int())

		case reflect.Float32, reflect.Float64:
			to[k] = fmt.Sprintf("%v", vv.Float())

		case reflect.Map:
			yml, _ := yaml.Marshal(vv.Interface())
			out, _ := json.YAMLToJSON(yml)
			to[k] = string(out)

		case reflect.Slice:
			out, err := yaml.Marshal(vv.Interface())
			if err != nil {
				return err
			}

			in := []string{}
			err = yaml.Unmarshal(out, &in)
			if err == nil {
				to[k] = strings.Join(in, ",")
			} else {
				out, err = json.YAMLToJSON(out)
				if err != nil {
					return err
				}
				to[k] = string(out)
			}
		}
	}

	return nil
}
1279593
func dotEnv(in string) (interface{}, error) {
	env, err := godotenv.Unmarshal(in)
	if err != nil {
		return nil, err
	}
	out := make(map[string]interface{})
	for k, v := range env {
		out[k] = v
	}
	return out, nil
}
725593
func (c *Config) EnvVars() map[string]string {
	vars := make(map[string]string, len(c.Params))
	for _, p := range c.Params {
		k, v := p.EnvVars()
		vars[k] = v
	}
	return vars
}
378537
func setEnv(cmd *exec.Cmd, envs map[string]string) {
	env := os.Environ()
	cmd.Env = make([]string, 0, len(env)+len(envs))
outer:
	for _, e := range env {
		for k := range envs {
			if strings.HasPrefix(e, k+"=") {
				continue outer
			}
		}
		cmd.Env = append(cmd.Env, e)
	}
	for k, v := range envs {
		cmd.Env = append(cmd.Env, k+"="+v)
	}
}
542846
func createEnvCacheMap(env []string) map[string]int {
	envMap := make(map[string]int, len(env))
	for i, val := range env {
		envMap[val] = i
	}
	return envMap
}