MCPcopy
hub / github.com/wavetermdev/waveterm / ParseEnvironmentFile

Function ParseEnvironmentFile

pkg/util/pamparse/pamparse.go:21–38  ·  view source on GitHub ↗

Parses a file in the format of /etc/environment. Accepts a path to the file and returns a map of environment variables.

(path string)

Source from the content-addressed store, hash-verified

19
20// Parses a file in the format of /etc/environment. Accepts a path to the file and returns a map of environment variables.
21func ParseEnvironmentFile(path string) (map[string]string, error) {
22 rtn := make(map[string]string)
23 file, err := os.Open(path)
24 if err != nil {
25 return nil, err
26 }
27 defer file.Close()
28 scanner := bufio.NewScanner(file)
29 for scanner.Scan() {
30 line := scanner.Text()
31 key, val := parseEnvironmentLine(line)
32 if key == "" {
33 continue
34 }
35 rtn[key] = val
36 }
37 return rtn, nil
38}
39
40// Parses a file in the format of /etc/security/pam_env.conf or ~/.pam_environment. Accepts a path to the file and returns a map of environment variables.
41func ParseEnvironmentConfFile(path string, opts *PamParseOpts) (map[string]string, error) {

Callers 2

tryGetPamEnvVarsFunction · 0.92
TestParseEnvironmentFileFunction · 0.92

Calls 4

parseEnvironmentLineFunction · 0.85
OpenMethod · 0.80
ScanMethod · 0.80
CloseMethod · 0.65

Tested by 1

TestParseEnvironmentFileFunction · 0.74