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
//! Construction of cloud-backed sandbox handles.
use std::sync::Arc;
use super::{Sandbox, SandboxConfig};
//--------------------------------------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------------------------------------
impl Sandbox {
/// Build an outer `Sandbox` from a [`CloudCreateSandboxResponse`](crate::backend::CloudCreateSandboxResponse)
/// HTTP response plus the originating [`SandboxConfig`].
pub(crate) fn from_cloud(
backend: Arc<dyn crate::backend::Backend>,
cloud: crate::backend::CloudCreateSandboxResponse,
config: SandboxConfig,
) -> Self {
let state = crate::backend::SandboxCloudState {
id: cloud.id,
org_id: cloud.org_id,
created_at: cloud.created_at,
};
Self::from_cloud_state(backend, state, cloud.name, config)
}
/// Build an outer `Sandbox` from cloud state already captured by a
/// [`SandboxHandle`](super::SandboxHandle). Cloud agent operations establish their own
/// authenticated WebSocket lazily, so reconnecting does not need to hold
/// an eager agent client.
pub(crate) fn from_cloud_state(
backend: Arc<dyn crate::backend::Backend>,
state: crate::backend::SandboxCloudState,
name: String,
config: SandboxConfig,
) -> Self {
let backend = backend
.with_agent_identity(&name, &state.id)
.unwrap_or(backend);
Self {
backend,
inner: Arc::new(crate::backend::SandboxInner::Cloud(state)),
name,
config,
}
}
}