(app: &mut App)
| 1989 | } |
| 1990 | |
| 1991 | async fn refresh_global_settings(app: &mut App) { |
| 1992 | let req = openshell_core::proto::GetGatewayConfigRequest {}; |
| 1993 | let result = |
| 1994 | tokio::time::timeout(Duration::from_secs(5), app.client.get_gateway_config(req)).await; |
| 1995 | match result { |
| 1996 | Ok(Err(e)) => { |
| 1997 | tracing::warn!("failed to fetch global settings: {}", e.message()); |
| 1998 | } |
| 1999 | Err(_) => { |
| 2000 | tracing::warn!("get gateway settings timed out"); |
| 2001 | } |
| 2002 | Ok(Ok(resp)) => { |
| 2003 | let inner = resp.into_inner(); |
| 2004 | app.apply_global_settings(inner.settings, inner.settings_revision); |
| 2005 | } |
| 2006 | } |
| 2007 | |
| 2008 | // Check for active global policy. |
| 2009 | let policy_req = openshell_core::proto::ListSandboxPoliciesRequest { |
| 2010 | name: String::new(), |
| 2011 | limit: 1, |
| 2012 | offset: 0, |
| 2013 | global: true, |
| 2014 | }; |
| 2015 | if let Ok(Ok(resp)) = tokio::time::timeout( |
| 2016 | Duration::from_secs(5), |
| 2017 | app.client.list_sandbox_policies(policy_req), |
| 2018 | ) |
| 2019 | .await |
| 2020 | { |
| 2021 | let revisions = resp.into_inner().revisions; |
| 2022 | if let Some(latest) = revisions.first() { |
| 2023 | let status = |
| 2024 | openshell_core::proto::PolicyStatus::try_from(latest.status).unwrap_or_default(); |
| 2025 | app.global_policy_active = status == openshell_core::proto::PolicyStatus::Loaded; |
| 2026 | app.global_policy_version = latest.version; |
| 2027 | } else { |
| 2028 | app.global_policy_active = false; |
| 2029 | app.global_policy_version = 0; |
| 2030 | } |
| 2031 | } |
| 2032 | } |
| 2033 | |
| 2034 | fn spawn_set_global_setting(app: &App, tx: mpsc::UnboundedSender<Event>) { |
| 2035 | let Some(ref edit) = app.setting_edit else { |
no test coverage detected