(
server: &str,
name: &str,
policy_path: &str,
wait: bool,
timeout_secs: u64,
tls: &TlsOptions,
)
| 6641 | } |
| 6642 | |
| 6643 | pub async fn sandbox_policy_set( |
| 6644 | server: &str, |
| 6645 | name: &str, |
| 6646 | policy_path: &str, |
| 6647 | wait: bool, |
| 6648 | timeout_secs: u64, |
| 6649 | tls: &TlsOptions, |
| 6650 | ) -> Result<()> { |
| 6651 | let policy = load_sandbox_policy(Some(policy_path))? |
| 6652 | .ok_or_else(|| miette::miette!("No policy loaded from {policy_path}"))?; |
| 6653 | |
| 6654 | let mut client = grpc_client(server, tls).await?; |
| 6655 | |
| 6656 | // Get current version so we can detect no-ops. |
| 6657 | let current_version = client |
| 6658 | .get_sandbox_policy_status(GetSandboxPolicyStatusRequest { |
| 6659 | name: name.to_string(), |
| 6660 | version: 0, |
| 6661 | global: false, |
| 6662 | }) |
| 6663 | .await |
| 6664 | .ok() |
| 6665 | .and_then(|r| r.into_inner().revision) |
| 6666 | .map_or(0, |r| r.version); |
| 6667 | |
| 6668 | let response = client |
| 6669 | .update_config(UpdateConfigRequest { |
| 6670 | name: name.to_string(), |
| 6671 | policy: Some(policy), |
| 6672 | setting_key: String::new(), |
| 6673 | setting_value: None, |
| 6674 | delete_setting: false, |
| 6675 | global: false, |
| 6676 | merge_operations: vec![], |
| 6677 | expected_resource_version: 0, |
| 6678 | }) |
| 6679 | .await |
| 6680 | .into_diagnostic()?; |
| 6681 | |
| 6682 | let resp = response.into_inner(); |
| 6683 | |
| 6684 | if resp.version == current_version { |
| 6685 | eprintln!( |
| 6686 | "{} Policy unchanged (version {}, hash: {})", |
| 6687 | "·".dimmed(), |
| 6688 | resp.version, |
| 6689 | &resp.policy_hash[..12] |
| 6690 | ); |
| 6691 | return Ok(()); |
| 6692 | } |
| 6693 | |
| 6694 | eprintln!( |
| 6695 | "{} Policy version {} submitted (hash: {})", |
| 6696 | "✓".green().bold(), |
| 6697 | resp.version, |
| 6698 | &resp.policy_hash[..12] |
| 6699 | ); |
| 6700 |
no test coverage detected