@@ -34,19 +34,19 @@ func NewDocker(execer agentexec.Execer) Lister {
34
34
}
35
35
}
36
36
37
- // ContainerEnvInfoer is an implementation of agentssh.EnvInfoer that returns
37
+ // DockerEnvInfoer is an implementation of agentssh.EnvInfoer that returns
38
38
// information about a container.
39
- type ContainerEnvInfoer struct {
39
+ type DockerEnvInfoer struct {
40
40
container string
41
41
user * user.User
42
42
userShell string
43
43
env []string
44
44
}
45
45
46
46
// 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
50
50
51
51
if containerUser == "" {
52
52
// 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
93
93
return nil , xerrors .Errorf ("get container user: invalid line in /etc/passwd: %q" , foundLine )
94
94
}
95
95
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
97
97
// comma-separated list of fields. The first field is the user's full name.
98
98
gecos := strings .Split (passwdFields [4 ], "," )
99
99
fullName := ""
100
100
if len (gecos ) > 1 {
101
101
fullName = gecos [0 ]
102
102
}
103
103
104
- cei .user = & user.User {
104
+ dei .user = & user.User {
105
105
Gid : passwdFields [3 ],
106
106
HomeDir : passwdFields [5 ],
107
107
Name : fullName ,
108
108
Uid : passwdFields [2 ],
109
109
Username : containerUser ,
110
110
}
111
- cei .userShell = passwdFields [6 ]
111
+ dei .userShell = passwdFields [6 ]
112
112
113
113
// We need to inspect the container labels for remoteEnv and append these to
114
114
// the resulting docker exec command.
@@ -117,58 +117,57 @@ func EnvInfo(ctx context.Context, execer agentexec.Execer, container, containerU
117
117
if err != nil { // best effort.
118
118
return nil , xerrors .Errorf ("read devcontainer remoteEnv: %w" , err )
119
119
}
120
- cei .env = env
120
+ dei .env = env
121
121
122
- return & cei , nil
122
+ return & dei , nil
123
123
}
124
124
125
- func (cei * ContainerEnvInfoer ) CurrentUser () (* user.User , error ) {
125
+ func (dei * DockerEnvInfoer ) CurrentUser () (* user.User , error ) {
126
126
// Clone the user so that the caller can't modify it
127
- u := * cei .user
127
+ u := * dei .user
128
128
return & u , nil
129
129
}
130
130
131
- func (* ContainerEnvInfoer ) Environ () []string {
131
+ func (* DockerEnvInfoer ) Environ () []string {
132
132
// Return a clone of the environment so that the caller can't modify it
133
133
return os .Environ ()
134
134
}
135
135
136
- func (* ContainerEnvInfoer ) UserHomeDir () (string , error ) {
136
+ func (* DockerEnvInfoer ) UserHomeDir () (string , error ) {
137
137
// We default the working directory of the command to the user's home
138
138
// directory. Since this came from inside the container, we cannot guarantee
139
139
// that this exists on the host. Return the "real" home directory of the user
140
140
// instead.
141
141
return os .UserHomeDir ()
142
142
}
143
143
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
146
146
}
147
147
148
- func (cei * ContainerEnvInfoer ) ModifyCommand (cmd string , args ... string ) (string , []string ) {
148
+ func (dei * DockerEnvInfoer ) ModifyCommand (cmd string , args ... string ) (string , []string ) {
149
149
// Wrap the command with `docker exec` and run it as the container user.
150
150
// There is some additional munging here regarding the container user and environment.
151
- // return WrapDockerExecPTY(dei.container, dei.user.Username)(cmd, args...)
152
151
dockerArgs := []string {
153
152
"exec" ,
154
153
// The assumption is that this command will be a shell command, so allocate a PTY.
155
154
"--interactive" ,
156
155
"--tty" ,
157
156
// Run the command as the user in the container.
158
157
"--user" ,
159
- cei .user .Username ,
158
+ dei .user .Username ,
160
159
// Set the working directory to the user's home directory as a sane default.
161
160
"--workdir" ,
162
- cei .user .HomeDir ,
161
+ dei .user .HomeDir ,
163
162
}
164
163
165
164
// Append the environment variables from the container.
166
- for _ , e := range cei .env {
165
+ for _ , e := range dei .env {
167
166
dockerArgs = append (dockerArgs , "--env" , e )
168
167
}
169
168
170
169
// Append the container name and the command.
171
- dockerArgs = append (dockerArgs , cei .container , cmd )
170
+ dockerArgs = append (dockerArgs , dei .container , cmd )
172
171
return "docker" , append (dockerArgs , args ... )
173
172
}
174
173
0 commit comments