Skip to content

Commit bf101d3

Browse files
committed
PR comments again
1 parent 06b9b7e commit bf101d3

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

agent/agentcontainers/containers_dockercli.go

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ func NewDocker(execer agentexec.Execer) Lister {
3434
}
3535
}
3636

37-
// ContainerEnvInfoer is an implementation of agentssh.EnvInfoer that returns
37+
// DockerEnvInfoer is an implementation of agentssh.EnvInfoer that returns
3838
// information about a container.
39-
type ContainerEnvInfoer struct {
39+
type DockerEnvInfoer struct {
4040
container string
4141
user *user.User
4242
userShell string
4343
env []string
4444
}
4545

4646
// EnvInfo returns information about the environment of a container.
47-
func EnvInfo(ctx context.Context, execer agentexec.Execer, container, containerUser string) (*ContainerEnvInfoer, error) {
48-
var cei ContainerEnvInfoer
49-
cei.container = container
47+
func EnvInfo(ctx context.Context, execer agentexec.Execer, container, containerUser string) (*DockerEnvInfoer, error) {
48+
var dei DockerEnvInfoer
49+
dei.container = container
5050

5151
if containerUser == "" {
5252
// Get the "default" user of the container if no user is specified.
@@ -93,22 +93,22 @@ func EnvInfo(ctx context.Context, execer agentexec.Execer, container, containerU
9393
return nil, xerrors.Errorf("get container user: invalid line in /etc/passwd: %q", foundLine)
9494
}
9595

96-
// The fourth entry in /etc/passwd contains GECOS information, which is a
96+
// The fifth entry in /etc/passwd contains GECOS information, which is a
9797
// comma-separated list of fields. The first field is the user's full name.
9898
gecos := strings.Split(passwdFields[4], ",")
9999
fullName := ""
100100
if len(gecos) > 1 {
101101
fullName = gecos[0]
102102
}
103103

104-
cei.user = &user.User{
104+
dei.user = &user.User{
105105
Gid: passwdFields[3],
106106
HomeDir: passwdFields[5],
107107
Name: fullName,
108108
Uid: passwdFields[2],
109109
Username: containerUser,
110110
}
111-
cei.userShell = passwdFields[6]
111+
dei.userShell = passwdFields[6]
112112

113113
// We need to inspect the container labels for remoteEnv and append these to
114114
// the resulting docker exec command.
@@ -117,58 +117,57 @@ func EnvInfo(ctx context.Context, execer agentexec.Execer, container, containerU
117117
if err != nil { // best effort.
118118
return nil, xerrors.Errorf("read devcontainer remoteEnv: %w", err)
119119
}
120-
cei.env = env
120+
dei.env = env
121121

122-
return &cei, nil
122+
return &dei, nil
123123
}
124124

125-
func (cei *ContainerEnvInfoer) CurrentUser() (*user.User, error) {
125+
func (dei *DockerEnvInfoer) CurrentUser() (*user.User, error) {
126126
// Clone the user so that the caller can't modify it
127-
u := *cei.user
127+
u := *dei.user
128128
return &u, nil
129129
}
130130

131-
func (*ContainerEnvInfoer) Environ() []string {
131+
func (*DockerEnvInfoer) Environ() []string {
132132
// Return a clone of the environment so that the caller can't modify it
133133
return os.Environ()
134134
}
135135

136-
func (*ContainerEnvInfoer) UserHomeDir() (string, error) {
136+
func (*DockerEnvInfoer) UserHomeDir() (string, error) {
137137
// We default the working directory of the command to the user's home
138138
// directory. Since this came from inside the container, we cannot guarantee
139139
// that this exists on the host. Return the "real" home directory of the user
140140
// instead.
141141
return os.UserHomeDir()
142142
}
143143

144-
func (cei *ContainerEnvInfoer) UserShell(string) (string, error) {
145-
return cei.userShell, nil
144+
func (dei *DockerEnvInfoer) UserShell(string) (string, error) {
145+
return dei.userShell, nil
146146
}
147147

148-
func (cei *ContainerEnvInfoer) ModifyCommand(cmd string, args ...string) (string, []string) {
148+
func (dei *DockerEnvInfoer) ModifyCommand(cmd string, args ...string) (string, []string) {
149149
// Wrap the command with `docker exec` and run it as the container user.
150150
// There is some additional munging here regarding the container user and environment.
151-
// return WrapDockerExecPTY(dei.container, dei.user.Username)(cmd, args...)
152151
dockerArgs := []string{
153152
"exec",
154153
// The assumption is that this command will be a shell command, so allocate a PTY.
155154
"--interactive",
156155
"--tty",
157156
// Run the command as the user in the container.
158157
"--user",
159-
cei.user.Username,
158+
dei.user.Username,
160159
// Set the working directory to the user's home directory as a sane default.
161160
"--workdir",
162-
cei.user.HomeDir,
161+
dei.user.HomeDir,
163162
}
164163

165164
// Append the environment variables from the container.
166-
for _, e := range cei.env {
165+
for _, e := range dei.env {
167166
dockerArgs = append(dockerArgs, "--env", e)
168167
}
169168

170169
// Append the container name and the command.
171-
dockerArgs = append(dockerArgs, cei.container, cmd)
170+
dockerArgs = append(dockerArgs, dei.container, cmd)
172171
return "docker", append(dockerArgs, args...)
173172
}
174173

0 commit comments

Comments
 (0)