| 3458 | } |
| 3459 | |
| 3460 | pub async fn sandbox_provider_attach( |
| 3461 | server: &str, |
| 3462 | name: &str, |
| 3463 | provider: &str, |
| 3464 | tls: &TlsOptions, |
| 3465 | ) -> Result<()> { |
| 3466 | let mut client = grpc_client(server, tls).await?; |
| 3467 | |
| 3468 | // Fetch current sandbox to get resource_version for CAS |
| 3469 | let sandbox = client |
| 3470 | .get_sandbox(GetSandboxRequest { |
| 3471 | name: name.to_string(), |
| 3472 | }) |
| 3473 | .await |
| 3474 | .into_diagnostic()? |
| 3475 | .into_inner() |
| 3476 | .sandbox |
| 3477 | .ok_or_else(|| miette::miette!("sandbox not found"))?; |
| 3478 | |
| 3479 | let resource_version = sandbox.metadata.as_ref().map_or(0, |m| m.resource_version); |
| 3480 | |
| 3481 | let response = match client |
| 3482 | .attach_sandbox_provider(AttachSandboxProviderRequest { |
| 3483 | sandbox_name: name.to_string(), |
| 3484 | provider_name: provider.to_string(), |
| 3485 | expected_resource_version: resource_version, |
| 3486 | }) |
| 3487 | .await |
| 3488 | { |
| 3489 | Ok(response) => response.into_inner(), |
| 3490 | Err(status) if status.code() == Code::Aborted => { |
| 3491 | return Err(miette::miette!( |
| 3492 | "Failed to attach provider: sandbox was modified by another operation.\n\ |
| 3493 | Please retry the command." |
| 3494 | ) |
| 3495 | .with_source_code(status.message().to_string())); |
| 3496 | } |
| 3497 | Err(e) => return Err(e).into_diagnostic(), |
| 3498 | }; |
| 3499 | |
| 3500 | if response.attached { |
| 3501 | println!( |
| 3502 | "{} Attached provider {} to sandbox {}", |
| 3503 | "✓".green().bold(), |
| 3504 | provider, |
| 3505 | name |
| 3506 | ); |
| 3507 | } else { |
| 3508 | println!("Provider {provider} is already attached to sandbox {name}."); |
| 3509 | } |
| 3510 | Ok(()) |
| 3511 | } |
| 3512 | |
| 3513 | pub async fn sandbox_provider_detach( |
| 3514 | server: &str, |