1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use std::{collections::HashMap, path::Path, sync::Arc};
use crate::{
config::Spec,
connector::{Connector, ConnectorInbox},
keystore::KeyStore,
};
use anyhow::Context;
#[cfg(feature = "python")]
use python::PythonConnector;
#[cfg(feature = "python")]
pub mod python;
#[cfg(feature = "sandbox")]
pub mod sandbox;
#[cfg(not(feature = "sandbox"))]
pub mod unsandbox;
pub async fn spawn_connector(
shortname: &str,
spec: &Spec,
prefix: &Path,
env: &HashMap<String, String>,
// binary_cache: &BinaryCache,
keystore: Option<Arc<dyn KeyStore>>,
) -> Result<(Arc<dyn Connector>, ConnectorInbox), anyhow::Error> {
let (outbox, inbox) = tokio::sync::broadcast::channel(64);
// let lockfile = load_lockfile().await?;
// let Some(connector_type) = lockfile::resolve_lock_entry(&lockfile, connector_type, binary_cache).await? else {
// bail!("No such entry in lockfile: {:?}", connector_type)
// };
match spec {
Spec::Binary { path, protocol } => match protocol {
crate::config::Protocol::Tarpc => Ok((
Arc::new(
unsandbox::launch_server_binary(spec, shortname, prefix, env, outbox, keystore)
.await
.context("launch_server_binary()")?,
) as Arc<dyn Connector>,
inbox,
)),
},
Spec::Cargo { protocol, .. } => match protocol {
crate::config::Protocol::Tarpc => Ok((
Arc::new(
unsandbox::launch_server_binary(spec, shortname, prefix, env, outbox, keystore)
.await
.context("launch_server_binary()")?,
) as Arc<dyn Connector>,
inbox,
)),
},
Spec::CargoLocal { protocol, .. } => match protocol {
crate::config::Protocol::Tarpc => Ok((
Arc::new(
unsandbox::launch_server_binary(spec, shortname, prefix, env, outbox, keystore)
.await
.context("launch_server_binary()")?,
) as Arc<dyn Connector>,
inbox,
)),
},
}
// match &connector_type {
// // TODO we need to inject env vars for python connectors!
// #[cfg(feature = "python")]
// super::r#type::ConnectorType::Python(path_buf, class_name) => Ok((
// PythonConnector::new(&format!("{}:{}", path_buf.to_string_lossy(), class_name), prefix, outbox).await?,
// inbox,
// )),
// #[cfg(not(feature = "python"))]
// super::r#type::ConnectorType::Python(path_buf, class_name) => {
// bail!("Python support not enabled.");
// }
// super::r#type::ConnectorType::LockFile(path_buf, short_name) => {
// bail!("Lockfile entry resolved to a lockfile entry {:?}", connector_type);
// }
// #[cfg(not(feature = "sandbox"))]
// super::r#type::ConnectorType::BinaryTarpc(binary_path, short_name) => Ok((
// Box::new(
// unsandbox::launch_server_binary(binary_path, short_name, prefix, env, outbox, keystore)
// .await
// .context("launch_server_binary()")?,
// ) as Box<dyn Connector>,
// inbox,
// )),
// #[cfg(feature = "sandbox")]
// super::r#type::ConnectorType::BinaryTarpc(binary_path, short_name) => Ok((
// Box::new(
// sandbox::launch_server_binary_sandboxed(binary_path, &short_name, prefix, &env, outbox, keystore)
// .await
// .context("launch_server_binary_sandboxed()")?,
// ) as Box<dyn Connector>,
// inbox,
// )),
// }
}