(
server: &str,
name: &str,
view: PolicyGetView,
output: &str,
tls: &TlsOptions,
writers: (&mut W, &mut E),
)
| 7060 | } |
| 7061 | |
| 7062 | async fn sandbox_policy_get_effective_to_writer<W, E>( |
| 7063 | server: &str, |
| 7064 | name: &str, |
| 7065 | view: PolicyGetView, |
| 7066 | output: &str, |
| 7067 | tls: &TlsOptions, |
| 7068 | writers: (&mut W, &mut E), |
| 7069 | ) -> Result<()> |
| 7070 | where |
| 7071 | W: Write + Send, |
| 7072 | E: Write + Send, |
| 7073 | { |
| 7074 | let (stdout, _stderr) = writers; |
| 7075 | let mut client = grpc_client(server, tls).await?; |
| 7076 | |
| 7077 | let sandbox = client |
| 7078 | .get_sandbox(GetSandboxRequest { |
| 7079 | name: name.to_string(), |
| 7080 | }) |
| 7081 | .await |
| 7082 | .into_diagnostic()? |
| 7083 | .into_inner() |
| 7084 | .sandbox |
| 7085 | .ok_or_else(|| miette!("sandbox missing from response"))?; |
| 7086 | let sandbox_id = sandbox.object_id(); |
| 7087 | if sandbox_id.is_empty() { |
| 7088 | return Err(miette!("sandbox missing metadata")); |
| 7089 | } |
| 7090 | |
| 7091 | let config = client |
| 7092 | .get_sandbox_config(GetSandboxConfigRequest { |
| 7093 | sandbox_id: sandbox_id.to_string(), |
| 7094 | }) |
| 7095 | .await |
| 7096 | .into_diagnostic()? |
| 7097 | .into_inner(); |
| 7098 | let policy = config |
| 7099 | .policy |
| 7100 | .as_ref() |
| 7101 | .ok_or_else(|| miette!("no active policy configured for sandbox '{name}'"))?; |
| 7102 | let policy_source = |
| 7103 | PolicySource::try_from(config.policy_source).unwrap_or(PolicySource::Sandbox); |
| 7104 | let policy_source_label = match policy_source { |
| 7105 | PolicySource::Global => "global", |
| 7106 | PolicySource::Sandbox => "sandbox", |
| 7107 | PolicySource::Unspecified => "unspecified", |
| 7108 | }; |
| 7109 | let version = if policy_source == PolicySource::Global && config.global_policy_version > 0 { |
| 7110 | config.global_policy_version |
| 7111 | } else { |
| 7112 | config.version |
| 7113 | }; |
| 7114 | |
| 7115 | match output { |
| 7116 | "json" => { |
| 7117 | let mut obj = serde_json::Map::new(); |
| 7118 | obj.insert("scope".to_string(), serde_json::json!("sandbox")); |
| 7119 | obj.insert("sandbox".to_string(), serde_json::json!(name)); |
no test coverage detected