// Read all env (with same file loading semantics as Load) but return values as
// a map rather than automatically writing values into env
187979
func Read(filenames ...string) (envMap map[string]string, err error) {
	filenames = filenamesOrDefault(filenames)
	envMap = make(map[string]string)

	for _, filename := range filenames {
		individualEnvMap, individualErr := readFile(filename)

		if individualErr != nil {
			err = individualErr
			return // return early on a spazout
		}

		for key, value := range individualEnvMap {
			envMap[key] = value
		}
	}

	return
}
261515
func Load(path string, v interface{}) error {
	lock.Lock()
	defer lock.Unlock()
	f, err := os.Open(path)
	if err != nil {
		return err
	}
	defer f.Close()
	return Unmarshal(f, v)
}
520110
func (c *installationSiteConfig) read(path string) error {
	*c = installationSiteConfig{}
	r, err := os.Open(path)
	if err != nil {
		return err
	}
	defer r.Close()
	return json.NewDecoder(r).Decode(c)
}
1127340
func (y *YAMLLoader) Load(s interface{}) error {
	var r io.Reader

	if y.Reader != nil {
		r = y.Reader
	} else if y.Path != "" {
		file, err := getConfig(y.Path)
		if err != nil {
			return err
		}
		defer file.Close()
		r = file
	} else {
		return ErrSourceNotSet
	}

	data, err := ioutil.ReadAll(r)
	if err != nil {
		return err
	}

	return yaml.Unmarshal(data, s)
}
1334846
func (env *Env) Import(r io.Reader) error {
	scanner := bufio.NewScanner(r)
	for scanner.Scan() {
		line := scanner.Text()
		if strings.HasPrefix(line, "#") || len(line) == 0 {
			continue
		}
		l := strings.SplitN(line, "=", 2)
		if len(l) == 1 {
			return fmt.Errorf("Invalid line: %q", line)
		}
		env.data[l[0]] = l[1]

	}

	return scanner.Err()
}
358458
func (c *context) Env() map[string]string {
	env := make(map[string]string)
	for _, i := range os.Environ() {
		sep := strings.Index(i, "=")
		env[i[0:sep]] = i[sep+1:]
	}
	return env
}
668565
func (p *Project) LoadEnvFromFile(path string) error {
	p.Log.Debugf("load env from file %q", path)
	var env map[string]string

	f, err := os.Open(path)
	if err != nil {
		return err
	}
	defer f.Close()

	if err := json.NewDecoder(f).Decode(&env); err != nil {
		return err
	}

	for k, v := range env {
		p.Setenv(k, v)
	}

	return nil
}
112896
func env(key string, defaultValue string) string {
	val := os.Getenv(key)
	if len(val) == 0 {
		return defaultValue
	}
	return val
}
868186
func Bootstrap() (Env, error) {
	file, err := os.Open(".env")
	if err != nil {
		return nil, err
	}

	return Load(file)
}
1035452
func Load(file string, v interface{}) error {
	b, err := ioutil.ReadFile(file)
	if err != nil {
		return err
	}

	return Unmarshal(b, v)
}
1343181
func (e *delayedEnvironment) Get(key string) (string, bool) {
	e.Load()
	return e.env.Get(key)
}
449392
func (fkvs *FileKeyValueStore) Load(key interface{}) (interface{}, error) {
	file, err := fkvs.keySerializer(key)
	if err != nil {
		return nil, err
	}
	if _, err1 := os.Stat(file); os.IsNotExist(err1) {
		return nil, core.ErrKeyValueNotFound
	}
	bytes, err := ioutil.ReadFile(file) // nolint: gas
	if err != nil {
		return nil, err
	}
	if bytes == nil {
		return nil, core.ErrKeyValueNotFound
	}
	return fkvs.unmarshaller(bytes)
}
841152
func (env *Env) Parse(name string) (*parse.Tree, error) {
	return env.load(name)
}
628106
func LoadEnvVars() error {
	if envLoaded {
		return nil
	}
	if len(os.Getenv("ABOT_PATH")) == 0 {
		p := filepath.Join(os.Getenv("GOPATH"), "src", "github.com",
			"itsabot", "abot")
		log.Debug("ABOT_PATH not set. defaulting to", p)
		if err := os.Setenv("ABOT_PATH", p); err != nil {
			return err
		}
	}
	if len(os.Getenv("ITSABOT_URL")) == 0 {
		log.Debug("ITSABOT_URL not set, using https://www.itsabot.org")
		err := os.Setenv("ITSABOT_URL", "https://www.itsabot.org")
		if err != nil {
			return err
		}
	}
	p := filepath.Join("abot.env")
	fi, err := os.Open(p)
	if os.IsNotExist(err) {
		// Assume the user has loaded their env variables into their
		// path
		return nil
	}
	if err != nil {
		return err
	}
	defer func() {
		if err = fi.Close(); err != nil {
			log.Info("failed to close file")
		}
	}()
	scn := bufio.NewScanner(fi)
	for scn.Scan() {
		line := scn.Text()
		fields := strings.SplitN(line, "=", 2)
		if len(fields) != 2 {
			continue
		}
		key := strings.TrimSpace(fields[0])
		if len(key) == 0 {
			continue
		}
		if len(os.Getenv(fields[0])) > 0 {
			continue
		}
		val := strings.TrimSpace(fields[1])
		if len(val) >= 2 {
			if val[0] == '"' || val[0] == '\'' {
				val = val[1 : len(val)-1]
			}
		}
		if err = os.Setenv(key, val); err != nil {
			return err
		}
	}
	if err = scn.Err(); err != nil {
		return err
	}
	envLoaded = true
	return nil
}
941055
func ReadEnvironmentFile(filename string) ([]string, error) {
	// open the users environment file. if we don't find a file, move on as
	// having this file for the user is optional.
	file, err := os.Open(filename)
	if err != nil {
		log.Warnf("Unable to open environment file %v: %v, skipping", filename, err)
		return []string{}, nil
	}
	defer file.Close()

	var lineno int
	var envs []string

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		line := strings.TrimSpace(scanner.Text())

		// follow the lead of OpenSSH and don't allow more than 1,000 environment variables
		// https://github.com/openssh/openssh-portable/blob/master/session.c#L873-L874
		lineno = lineno + 1
		if lineno > teleport.MaxEnvironmentFileLines {
			log.Warnf("Too many lines in environment file %v, returning first %v lines", filename, teleport.MaxEnvironmentFileLines)
			return envs, nil
		}

		// empty lines or lines that start with # are ignored
		if line == "" || line[0] == '#' {
			continue
		}

		// split on first =, if not found, log it and continue
		idx := strings.Index(line, "=")
		if idx == -1 {
			log.Debugf("Bad line %v while reading %v: no = separator found", lineno, filename)
			continue
		}

		// split key and value and make sure that key has a name
		key := line[:idx]
		value := line[idx+1:]
		if strings.TrimSpace(key) == "" {
			log.Debugf("Bad line %v while reading %v: key without name", lineno, filename)
			continue
		}

		envs = append(envs, key+"="+value)
	}

	err = scanner.Err()
	if err != nil {
		log.Warnf("Unable to read environment file %v: %v, skipping", filename, err)
		return []string{}, nil
	}

	return envs, nil
}
542590
func (r *YAML) Read(name string) ([]byte, error) {
	p, ok := r.d[name]
	if !ok {
		return nil, errNotFound
	}
	return []byte(p), nil
}
1098019
func (c *ServerContext) GetEnv(key string) (string, bool) {
	val, ok := c.env[key]
	return val, ok
}