MCPcopy Index your code
hub / github.com/coder/coder / resolveEnv

Method resolveEnv

scripts/develop/main.go:431–455  ·  view source on GitHub ↗

resolveEnv sets defaults, unsets leaked credentials, resolves filesystem paths, and computes the child process environment.

()

Source from the content-addressed store, hash-verified

429// resolveEnv sets defaults, unsets leaked credentials, resolves
430// filesystem paths, and computes the child process environment.
431func (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.

Calls 5

applyPortOffsetMethod · 0.95
filterEnvFunction · 0.85
EnvironMethod · 0.65
ErrorfMethod · 0.45
ContainsMethod · 0.45