use std::sync::Arc;
use base::interface::exec::{ExecProviders, SubprocessEnv};
use crate::{GroupLedger, LocalFileSystem, LocalProcess, PlatformSandbox};
pub fn local_providers() -> ExecProviders {
local_providers_with(SubprocessEnv::default())
}
pub fn local_providers_with(env: SubprocessEnv) -> ExecProviders {
ExecProviders {
process: Arc::new(LocalProcess::new(env)),
filesystem: Arc::new(LocalFileSystem),
#[cfg(feature = "http")]
network: Arc::new(crate::LocalNetwork::default()),
#[cfg(not(feature = "http"))]
network: Arc::new(NoNetwork),
sandbox: Arc::new(PlatformSandbox),
}
}
pub fn local_providers_with_ledger(env: SubprocessEnv, ledger: Arc<GroupLedger>) -> ExecProviders {
ExecProviders {
process: Arc::new(LocalProcess::with_ledger(env, ledger)),
..local_providers()
}
}
#[cfg(not(feature = "http"))]
struct NoNetwork;
#[cfg(not(feature = "http"))]
#[async_trait::async_trait]
impl base::interface::exec::Network for NoNetwork {
async fn send(
&self,
_: base::interface::exec::HttpRequest,
_: base::interface::exec::Origin,
) -> Result<base::interface::exec::HttpResponse, base::interface::exec::ExecError> {
Err(base::interface::exec::ExecError::Unavailable(
"this build of `platform` has no HTTP client (feature `http`)".into(),
))
}
fn permits(&self, _: &str, _: base::interface::exec::Origin) -> bool {
false
}
}