(
sandbox: &DriverSandbox,
config: &DockerDriverRuntimeConfig,
)
| 2089 | } |
| 2090 | |
| 2091 | async 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 | |
| 2127 | fn cleanup_sandbox_token_file(sandbox: &DriverSandbox, config: &DockerDriverRuntimeConfig) { |
| 2128 | cleanup_sandbox_token_file_by_id(&sandbox.id, config); |
no test coverage detected