// mergeEnvLists merges the two environment lists such that
// variables with the same name in "in" replace those in "out".
173057
func mergeEnvLists(in, out []string) []string {
NextVar:
	for _, inkv := range in {
		k := strings.SplitAfterN(inkv, "=", 2)[0]
		for i, outkv := range out {
			if strings.HasPrefix(outkv, k) {
				out[i] = inkv
				continue NextVar
			}
		}
		out = append(out, inkv)
	}
	return out
}
357436
func replaceEnvVars(src string) (string, error) {
	r, err := regexp.Compile(`\${([A-Z_]+)}`)
	if err != nil {
		return "", err
	}
	envs := r.FindAllString(src, -1)
	for _, varname := range envs {
		evar := os.Getenv(varname[2 : len(varname)-1])
		if evar == "" {
			return "", errors.New(fmt.Sprintf("error: env var %s not defined", varname))
		}
		src = strings.Replace(src, varname, evar, -1)
	}
	return src, nil
}
358927
func (e *EnvironmentsClient) List(ctx context.Context, orgIDs, projectIDs, teamIDs []identity.ID, names []string) ([]envelope.Environment, error) {
	v := &url.Values{}
	for _, id := range orgIDs {
		v.Add("org_id", id.String())
	}
	for _, id := range projectIDs {
		v.Add("project_id", id.String())
	}
	for _, id := range teamIDs {
		v.Add("team_id", id.String())
	}
	for _, n := range names {
		v.Add("name", n)
	}

	var envs []envelope.Environment
	err := e.client.RoundTrip(ctx, "GET", "/envs", v, nil, &envs)
	return envs, err
}
928801
func copyEnvVarSlice(in []corev1.EnvVar) []corev1.EnvVar {
	out := make([]corev1.EnvVar, len(in))
	copy(out, in)
	return out
}
696959
func NewEnvJSONList(jsonStr string) (EnvsJSONListModel, error) {
	list := EnvsJSONListModel{}
	if err := json.Unmarshal([]byte(jsonStr), &list); err != nil {
		return EnvsJSONListModel{}, err
	}
	return list, nil
}
896414
func addSourceEnvVars(source buildv1.BuildSource, output *[]corev1.EnvVar) {
	sourceVars := []corev1.EnvVar{}
	if source.Git != nil {
		sourceVars = append(sourceVars, corev1.EnvVar{Name: "SOURCE_REPOSITORY", Value: source.Git.URI})
		sourceVars = append(sourceVars, corev1.EnvVar{Name: "SOURCE_URI", Value: source.Git.URI})
	}
	if len(source.ContextDir) > 0 {
		sourceVars = append(sourceVars, corev1.EnvVar{Name: "SOURCE_CONTEXT_DIR", Value: source.ContextDir})
	}
	if source.Git != nil && len(source.Git.Ref) > 0 {
		sourceVars = append(sourceVars, corev1.EnvVar{Name: "SOURCE_REF", Value: source.Git.Ref})
	}
	*output = append(*output, sourceVars...)
}
152626
func (ini *INI) Merge(from *INI, override bool) {
	for section, kv := range from.sections {
		for key, value := range kv {
			_, found := ini.SectionGet(section, key)
			if override || !found {
				ini.SectionSet(section, key, value)
			}
		}
	}
}
195624
func EnvBool(envVar string, defaultValue bool) bool {
	return envBool(os.Getenv, envVar, defaultValue)
}
517056
func (p *Pod) EmptyEnvs() *Pod {
	p.Env = make(map[string]string)
	return p
}
286940
func (t *Template) WithEnv(e map[string]string) *Template {
	t.fields[env] = e
	return t
}
911216
func merge(envs ...map[string]string) map[string]string {
	merged := make(map[string]string)
	for _, env := range envs {
		for k, v := range env {
			merged[k] = v
		}
	}
	return merged
}
1345058
func mergeEnv(sysEnv []string, cmdEnv map[string]string) []string {

	// sort keys so that duplicates are filtered in deterministic order
	keys := make([]string, 0, len(cmdEnv))
	for k := range cmdEnv {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	var env []string
	seen := make(map[string]bool) // seen env keys

	// add vars from cmdEnv - skipping duplicates
	for _, k := range keys {
		v := cmdEnv[k] // value
		uk := strings.ToUpper(k)
		if !seen[uk] {
			env = append(env, k+"="+v)
			seen[uk] = true
		}
	}
	// add vars from sysEnv - skipping duplicates and keys present in cmdEnv
	for _, kv := range sysEnv {
		if n := strings.IndexByte(kv, '='); n != -1 {
			k := kv[:n] // key
			uk := strings.ToUpper(k)
			if !seen[uk] {
				env = append(env, kv)
				seen[uk] = true
			}
		}
	}
	return env
}
1290708
func (p *PodContainer) EmptyEnvs() *PodContainer {
	p.Env = make(map[string]string)
	return p
}
72416
func setEnvvars(envBuilder *taskenv.Builder, fsi drivers.FSIsolation, taskDir *allocdir.TaskDir, conf *cconfig.Config) {
	// Set driver-specific environment variables
	switch fsi {
	case drivers.FSIsolationNone:
		// Use host paths
		envBuilder.SetAllocDir(taskDir.SharedAllocDir)
		envBuilder.SetTaskLocalDir(taskDir.LocalDir)
		envBuilder.SetSecretsDir(taskDir.SecretsDir)
	default:
		// filesystem isolation; use container paths
		envBuilder.SetAllocDir(allocdir.SharedAllocContainerPath)
		envBuilder.SetTaskLocalDir(allocdir.TaskLocalContainerPath)
		envBuilder.SetSecretsDir(allocdir.TaskSecretsContainerPath)
	}

	// Set the host environment variables for non-image based drivers
	if fsi != drivers.FSIsolationImage {
		filter := strings.Split(conf.ReadDefault("env.blacklist", cconfig.DefaultEnvBlacklist), ",")
		envBuilder.SetHostEnvvars(filter)
	}
}
288345
func expandEnv(s string) (interface{}, error) {
	raw := os.ExpandEnv(s)
	var jsonMap map[string]interface{}
	if len(raw) == 0 || (raw[0] != '{' && raw[0] != '[') {
		return raw, errNotJSON
	}
	err := json.Unmarshal([]byte(raw), &jsonMap)
	if err != nil {
		var jsonSlice []interface{}
		errS := json.Unmarshal([]byte(raw), &jsonSlice)
		if errS != nil {
			return raw, err
		}
		return jsonSlice, nil
	}
	return toInfMap(jsonMap), nil
}
826407
func AppendPathEnv(env string, v ...string) (path string) {
	if path = strings.Join(v[:], pls); env != "" {
		if path != "" {
			path = pls + path
		}
		path = env + path
	}
	return
}
932722
func ReplacePathEnvs(env *[]string, name string, v ...string) error {
	return pp(func(_ string, v ...string) string {
		return strings.Join(v, pls)
	}, env, name, v...)
}