Skip to content

feat(agent/agentcontainers): add ContainerEnvInfoer #16623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 24, 2025
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
  • Loading branch information
johnstcn and mafredri authored Feb 19, 2025
commit 7fd24be9ea2f43b5f518c8acd50e5754f026e405
12 changes: 3 additions & 9 deletions agent/agentcontainers/containers_dockercli.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func EnvInfo(ctx context.Context, execer agentexec.Execer, container, containerU
// Parse the output of /etc/passwd. It looks like this:
// postgres:x:999:999::/var/lib/postgresql:/bin/bash
passwdFields := strings.Split(foundLine, ":")
if len(passwdFields) < 7 {
if len(passwdFields) != 7 {
return nil, xerrors.Errorf("get container user: invalid line in /etc/passwd: %q", foundLine)
}

Expand Down Expand Up @@ -144,14 +144,8 @@ func EnvInfo(ctx context.Context, execer agentexec.Execer, container, containerU

func (dei *ContainerEnvInfoer) CurrentUser() (*user.User, error) {
// Clone the user so that the caller can't modify it
u := &user.User{
Gid: dei.user.Gid,
HomeDir: dei.user.HomeDir,
Name: dei.user.Name,
Uid: dei.user.Uid,
Username: dei.user.Username,
}
return u, nil
u := *dei.user
return &u, nil
}

func (dei *ContainerEnvInfoer) Environ() []string {
Expand Down
Loading