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

Function sandbox_ssh_proxy

crates/openshell-cli/src/ssh.rs:1322–1397  ·  view source on GitHub ↗

Run the SSH proxy, connecting stdin/stdout to the gateway.

(
    gateway_url: &str,
    sandbox_id: &str,
    token: &str,
    tls: &TlsOptions,
)

Source from the content-addressed store, hash-verified

1320
1321/// Run the SSH proxy, connecting stdin/stdout to the gateway.
1322pub async fn sandbox_ssh_proxy(
1323 gateway_url: &str,
1324 sandbox_id: &str,
1325 token: &str,
1326 tls: &TlsOptions,
1327) -> Result<()> {
1328 let server = grpc_server_from_ssh_gateway_url(gateway_url)?;
1329 let mut client = grpc_client(&server, tls).await?;
1330
1331 let (tx, rx) = tokio::sync::mpsc::channel::<TcpForwardFrame>(16);
1332 tx.send(TcpForwardFrame {
1333 payload: Some(openshell_core::proto::tcp_forward_frame::Payload::Init(
1334 TcpForwardInit {
1335 sandbox_id: sandbox_id.to_string(),
1336 service_id: format!("ssh-proxy:{sandbox_id}"),
1337 target: Some(tcp_forward_init::Target::Ssh(SshRelayTarget {})),
1338 authorization_token: token.to_string(),
1339 },
1340 )),
1341 })
1342 .await
1343 .map_err(|_| miette::miette!("failed to initialize SSH forward stream"))?;
1344
1345 let mut response = client
1346 .forward_tcp(ReceiverStream::new(rx))
1347 .await
1348 .into_diagnostic()?
1349 .into_inner();
1350
1351 let stdin = tokio::io::stdin();
1352 let stdout = tokio::io::stdout();
1353
1354 let to_remote = tokio::spawn(async move {
1355 let mut stdin = stdin;
1356 let mut buf = vec![0u8; 64 * 1024];
1357 while let Ok(n) = stdin.read(&mut buf).await {
1358 if n == 0 {
1359 break;
1360 }
1361 if tx
1362 .send(TcpForwardFrame {
1363 payload: Some(openshell_core::proto::tcp_forward_frame::Payload::Data(
1364 buf[..n].to_vec(),
1365 )),
1366 })
1367 .await
1368 .is_err()
1369 {
1370 break;
1371 }
1372 }
1373 });
1374 let from_remote = tokio::spawn(async move {
1375 let mut stdout = stdout;
1376 loop {
1377 let Ok(Some(frame)) = response.message().await else {
1378 break;
1379 };

Callers 2

mainFunction · 0.85

Calls 9

grpc_clientFunction · 0.85
messageMethod · 0.80
abortMethod · 0.80
spawnFunction · 0.50
forward_tcpMethod · 0.45
readMethod · 0.45
is_emptyMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected