resolveEnv sets defaults, unsets leaked credentials, resolves filesystem paths, and computes the child process environment.
()
| 429 | // resolveEnv sets defaults, unsets leaked credentials, resolves |
| 430 | // filesystem paths, and computes the child process environment. |
| 431 | func (c *devConfig) resolveEnv() error { |
| 432 | // Prevent inherited credentials from leaking into child |
| 433 | // processes or being picked up by config reads. |
| 434 | _ = os.Unsetenv("CODER_SESSION_TOKEN") |
| 435 | _ = os.Unsetenv("CODER_URL") |
| 436 | |
| 437 | var err error |
| 438 | c.projectRoot, err = os.Getwd() |
| 439 | if err != nil { |
| 440 | return xerrors.Errorf("getting working directory: %w", err) |
| 441 | } |
| 442 | c.binaryPath = filepath.Join(c.projectRoot, "build", |
| 443 | fmt.Sprintf("coder_%s_%s", runtime.GOOS, runtime.GOARCH)) |
| 444 | c.configDir = filepath.Join(c.projectRoot, ".coderv2") |
| 445 | |
| 446 | c.applyPortOffset() |
| 447 | if strings.Contains(c.accessURL, "%d") { |
| 448 | c.accessURL = fmt.Sprintf(c.accessURL, c.apiPort) |
| 449 | } |
| 450 | |
| 451 | // Compute once, reused by cmd(). |
| 452 | c.childEnv = filterEnv(os.Environ(), "CODER_SESSION_TOKEN", "CODER_URL") |
| 453 | |
| 454 | return nil |
| 455 | } |
| 456 | |
| 457 | // cmd builds an exec.Cmd rooted in the project directory with a |
| 458 | // clean child environment. The context controls process lifetime. |