MCPcopy Index your code
hub / github.com/devcontainers/cli / getContainerProperties

Function getContainerProperties

src/spec-common/injectHeadless.ts:211–275  ·  view source on GitHub ↗
(options: {
	params: ResolverParameters;
	createdAt: string | undefined;
	startedAt: string | undefined;
	remoteWorkspaceFolder: string | undefined;
	containerUser: string | undefined;
	containerGroup: string | undefined;
	containerEnv: NodeJS.ProcessEnv | undefined;
	remoteExec: ExecFunction;
	remotePtyExec: PtyExecFunction;
	remoteExecAsRoot: ExecFunction | undefined;
	rootShellServer: ShellServer | undefined;
})

Source from the content-addressed store, hash-verified

209}
210
211export async function getContainerProperties(options: {
212 params: ResolverParameters;
213 createdAt: string | undefined;
214 startedAt: string | undefined;
215 remoteWorkspaceFolder: string | undefined;
216 containerUser: string | undefined;
217 containerGroup: string | undefined;
218 containerEnv: NodeJS.ProcessEnv | undefined;
219 remoteExec: ExecFunction;
220 remotePtyExec: PtyExecFunction;
221 remoteExecAsRoot: ExecFunction | undefined;
222 rootShellServer: ShellServer | undefined;
223}) {
224 let { params, createdAt, startedAt, remoteWorkspaceFolder, containerUser, containerGroup, containerEnv, remoteExec, remotePtyExec, remoteExecAsRoot, rootShellServer } = options;
225 let shellServer: ShellServer;
226 if (rootShellServer && containerUser === 'root') {
227 shellServer = rootShellServer;
228 } else {
229 shellServer = await launch(remoteExec, params.output, params.sessionId);
230 }
231 if (!containerEnv) {
232 const PATH = (await shellServer.exec('echo $PATH')).stdout.trim();
233 containerEnv = PATH ? { PATH } : {};
234 }
235 if (!containerUser) {
236 containerUser = await getUser(shellServer);
237 }
238 if (!remoteExecAsRoot && containerUser === 'root') {
239 remoteExecAsRoot = remoteExec;
240 }
241 const osRelease = await getOSRelease(shellServer);
242 const passwdUser = await getUserFromPasswdDB(shellServer, containerUser);
243 if (!passwdUser) {
244 params.output.write(toWarningText(`User ${containerUser} not found with 'getent passwd'.`));
245 }
246 const shell = await getUserShell(containerEnv, passwdUser);
247 const homeFolder = await getHomeFolder(shellServer, containerEnv, passwdUser);
248 const userDataFolder = getUserDataFolder(homeFolder, params);
249 let rootShellServerP: Promise<ShellServer> | undefined;
250 if (rootShellServer) {
251 rootShellServerP = Promise.resolve(rootShellServer);
252 } else if (containerUser === 'root') {
253 rootShellServerP = Promise.resolve(shellServer);
254 }
255 const containerProperties: ContainerProperties = {
256 createdAt,
257 startedAt,
258 osRelease,
259 user: containerUser,
260 gid: containerGroup || passwdUser?.gid,
261 env: containerEnv,
262 shell,
263 homeFolder,
264 userDataFolder,
265 remoteWorkspaceFolder,
266 remoteExec,
267 remotePtyExec,
268 remoteExecAsRoot,

Callers 1

Calls 10

launchFunction · 0.90
getUserFunction · 0.85
getOSReleaseFunction · 0.85
getUserFromPasswdDBFunction · 0.85
toWarningTextFunction · 0.85
getUserShellFunction · 0.85
getHomeFolderFunction · 0.85
getUserDataFolderFunction · 0.85
execMethod · 0.65
writeMethod · 0.65

Tested by

no test coverage detected