(
sandbox: &DriverSandbox,
)
| 89 | } |
| 90 | |
| 91 | async fn write_sandbox_token_file( |
| 92 | sandbox: &DriverSandbox, |
| 93 | ) -> Result<Option<PathBuf>, ComputeDriverError> { |
| 94 | let Some(spec) = sandbox.spec.as_ref() else { |
| 95 | return Ok(None); |
| 96 | }; |
| 97 | if spec.sandbox_token.is_empty() { |
| 98 | return Ok(None); |
| 99 | } |
| 100 | let path = sandbox_token_host_path(&sandbox.id)?; |
| 101 | if let Some(parent) = path.parent() { |
| 102 | openshell_core::paths::create_dir_restricted(parent).map_err(|err| { |
| 103 | ComputeDriverError::Message(format!( |
| 104 | "create sandbox token directory {} failed: {err}", |
| 105 | parent.display() |
| 106 | )) |
| 107 | })?; |
| 108 | } |
| 109 | tokio::fs::write(&path, format!("{}\n", spec.sandbox_token)) |
| 110 | .await |
| 111 | .map_err(|err| { |
| 112 | ComputeDriverError::Message(format!( |
| 113 | "write sandbox token file {} failed: {err}", |
| 114 | path.display() |
| 115 | )) |
| 116 | })?; |
| 117 | openshell_core::paths::set_file_owner_only(&path).map_err(|err| { |
| 118 | ComputeDriverError::Message(format!( |
| 119 | "restrict sandbox token file {} failed: {err}", |
| 120 | path.display() |
| 121 | )) |
| 122 | })?; |
| 123 | Ok(Some(path)) |
| 124 | } |
| 125 | |
| 126 | fn cleanup_sandbox_token_file(sandbox_id: &str) { |
| 127 | let Ok(path) = sandbox_token_host_path(sandbox_id) else { |
no test coverage detected