MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / write_sandbox_token_file

Function write_sandbox_token_file

crates/openshell-driver-docker/src/lib.rs:2091–2125  ·  view source on GitHub ↗
(
    sandbox: &DriverSandbox,
    config: &DockerDriverRuntimeConfig,
)

Source from the content-addressed store, hash-verified

2089}
2090
2091async fn write_sandbox_token_file(
2092 sandbox: &DriverSandbox,
2093 config: &DockerDriverRuntimeConfig,
2094) -> Result<bool, Status> {
2095 let Some(spec) = sandbox.spec.as_ref() else {
2096 return Ok(false);
2097 };
2098 if spec.sandbox_token.is_empty() {
2099 return Ok(false);
2100 }
2101 let path = sandbox_token_host_path(sandbox, config)?;
2102 if let Some(parent) = path.parent() {
2103 openshell_core::paths::create_dir_restricted(parent).map_err(|err| {
2104 Status::internal(format!(
2105 "create sandbox token directory {} failed: {err}",
2106 parent.display()
2107 ))
2108 })?;
2109 }
2110 tokio::fs::write(&path, format!("{}\n", spec.sandbox_token))
2111 .await
2112 .map_err(|err| {
2113 Status::internal(format!(
2114 "write sandbox token file {} failed: {err}",
2115 path.display()
2116 ))
2117 })?;
2118 openshell_core::paths::set_file_owner_only(&path).map_err(|err| {
2119 Status::internal(format!(
2120 "restrict sandbox token file {} failed: {err}",
2121 path.display()
2122 ))
2123 })?;
2124 Ok(true)
2125}
2126
2127fn cleanup_sandbox_token_file(sandbox: &DriverSandbox, config: &DockerDriverRuntimeConfig) {
2128 cleanup_sandbox_token_file_by_id(&sandbox.id, config);

Callers 1

Calls 4

create_dir_restrictedFunction · 0.85
set_file_owner_onlyFunction · 0.85
sandbox_token_host_pathFunction · 0.70
is_emptyMethod · 0.45

Tested by

no test coverage detected