Skip to main content

forge_workspace/
systemone.rs

1//! The System One decision tools' workspace leg: the boot-time client
2//! construction, shared by the real boot and the testing stubs so both
3//! agree on trust handling.
4
5use std::path::Path;
6
7use forge_system_one::{SystemOneClient, SystemOneConfig};
8
9use crate::error::WorkspaceError;
10
11/// Build the decision client for a loaded `[systemone]` section; `None`
12/// keeps the tools unregistered for every session. The client goes
13/// through the same TLS-trust helper the Slack and Gotify legs use, so
14/// a NODE_EXTRA_CA_CERTS bundle behaves identically for decisions.
15pub(crate) fn client_for(
16    config: Option<&SystemOneConfig>,
17    forge_toml: &Path,
18) -> Result<Option<SystemOneClient>, WorkspaceError> {
19    let Some(config) = config else {
20        return Ok(None);
21    };
22    let http = forge_agent::http_trust::with_extra_roots(reqwest::Client::builder())
23        .build()
24        .map_err(|error| WorkspaceError::ConfigInvalid {
25            path: forge_toml.to_path_buf(),
26            message: format!("systemone http client: {error}"),
27        })?;
28    Ok(Some(SystemOneClient::new(config, http)))
29}