microsandbox-rb 0.5.8 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,8 +8,8 @@
8
8
  use magnus::{function, prelude::*, Error, RArray, RHash, RModule, Ruby};
9
9
  use microsandbox::image::{Image, ImageDetail, ImageHandle, ImagePruneReport};
10
10
 
11
- use crate::error;
12
- use crate::runtime::{block_on, ruby};
11
+ use crate::backend::with_local_backend;
12
+ use crate::runtime::ruby;
13
13
 
14
14
  fn handle_to_hash(h: &ImageHandle) -> RHash {
15
15
  let hash = ruby().hash_new();
@@ -76,12 +76,12 @@ fn report_to_hash(report: ImagePruneReport) -> RHash {
76
76
  }
77
77
 
78
78
  fn get(reference: String) -> Result<RHash, Error> {
79
- let handle = block_on(Image::get(&reference)).map_err(error::to_ruby)?;
79
+ let handle = with_local_backend(async |local| Image::get(local, &reference).await)?;
80
80
  Ok(handle_to_hash(&handle))
81
81
  }
82
82
 
83
83
  fn list() -> Result<RArray, Error> {
84
- let handles = block_on(Image::list()).map_err(error::to_ruby)?;
84
+ let handles = with_local_backend(async |local| Image::list(local).await)?;
85
85
  let arr = ruby().ary_new();
86
86
  for h in handles.iter() {
87
87
  arr.push(handle_to_hash(h))?;
@@ -90,16 +90,16 @@ fn list() -> Result<RArray, Error> {
90
90
  }
91
91
 
92
92
  fn inspect(reference: String) -> Result<RHash, Error> {
93
- let detail = block_on(Image::inspect(&reference)).map_err(error::to_ruby)?;
93
+ let detail = with_local_backend(async |local| Image::inspect(local, &reference).await)?;
94
94
  Ok(detail_to_hash(detail))
95
95
  }
96
96
 
97
97
  fn remove(reference: String, force: bool) -> Result<(), Error> {
98
- block_on(Image::remove(&reference, force)).map_err(error::to_ruby)
98
+ with_local_backend(async |local| Image::remove(local, &reference, force).await)
99
99
  }
100
100
 
101
101
  fn prune() -> Result<RHash, Error> {
102
- let report = block_on(Image::prune()).map_err(error::to_ruby)?;
102
+ let report = with_local_backend(async |local| Image::prune(local).await)?;
103
103
  Ok(report_to_hash(report))
104
104
  }
105
105
 
@@ -8,6 +8,8 @@
8
8
  //! Everything here lives under `Microsandbox::Native`; the ergonomic, idiomatic
9
9
  //! surface is the pure-Ruby layer in `lib/microsandbox/`.
10
10
 
11
+ mod agent;
12
+ mod backend;
11
13
  mod conv;
12
14
  mod error;
13
15
  mod exec;
@@ -15,6 +17,7 @@ mod image;
15
17
  mod runtime;
16
18
  mod sandbox;
17
19
  mod snapshot;
20
+ mod ssh;
18
21
  mod stream;
19
22
  mod volume;
20
23
 
@@ -29,8 +32,9 @@ fn version() -> String {
29
32
  /// Ruby Hash. Mirrors the official `all_sandbox_metrics` / `allSandboxMetrics`
30
33
  /// helpers (Python/Node/Go).
31
34
  fn all_sandbox_metrics() -> Result<RHash, Error> {
32
- let map =
33
- runtime::block_on(microsandbox::sandbox::all_sandbox_metrics()).map_err(error::to_ruby)?;
35
+ let map = backend::with_local_backend(async |local| {
36
+ microsandbox::sandbox::all_sandbox_metrics(local).await
37
+ })?;
34
38
  let hash = runtime::ruby().hash_new();
35
39
  for (name, metrics) in &map {
36
40
  hash.aset(name.as_str(), sandbox::metrics_to_hash(metrics))?;
@@ -53,9 +57,25 @@ fn set_runtime_msb_path(path: String) {
53
57
  microsandbox::config::set_sdk_msb_path(path);
54
58
  }
55
59
 
56
- /// The currently-resolved `msb` runtime path.
60
+ /// Override the resolved `libkrunfw` path (SDK tier of the resolver). Set-once
61
+ /// per process; the `MSB_LIBKRUNFW_PATH` env var still takes precedence. Mirrors
62
+ /// `set_runtime_msb_path` for the libkrunfw shared library.
63
+ fn set_runtime_libkrunfw_path(path: String) {
64
+ microsandbox::config::set_sdk_libkrunfw_path(path);
65
+ }
66
+
67
+ /// The currently-resolved `msb` runtime path. Synchronous (filesystem probes,
68
+ /// no async) — runs on the Ruby thread; resolves the path from the local
69
+ /// backend's config.
57
70
  fn resolved_msb_path() -> Result<String, Error> {
58
- let path = microsandbox::config::resolve_msb_path().map_err(error::to_ruby)?;
71
+ let backend = microsandbox::default_backend();
72
+ let local = backend.as_local().ok_or_else(|| {
73
+ error::to_ruby(microsandbox::MicrosandboxError::Unsupported {
74
+ feature: "resolved_msb_path requires a local backend".into(),
75
+ available_when: "with the local backend".into(),
76
+ })
77
+ })?;
78
+ let path = microsandbox::config::resolve_msb_path(local.config()).map_err(error::to_ruby)?;
59
79
  Ok(path.to_string_lossy().into_owned())
60
80
  }
61
81
 
@@ -70,15 +90,22 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
70
90
  native.define_singleton_method("install", function!(install, 0))?;
71
91
  native.define_singleton_method("installed?", function!(is_installed, 0))?;
72
92
  native.define_singleton_method("set_runtime_msb_path", function!(set_runtime_msb_path, 1))?;
93
+ native.define_singleton_method(
94
+ "set_runtime_libkrunfw_path",
95
+ function!(set_runtime_libkrunfw_path, 1),
96
+ )?;
73
97
  native.define_singleton_method("resolved_msb_path", function!(resolved_msb_path, 0))?;
74
98
  native.define_singleton_method("all_sandbox_metrics", function!(all_sandbox_metrics, 0))?;
75
99
 
100
+ backend::define(ruby, &native)?;
76
101
  sandbox::define(ruby, &native)?;
77
102
  exec::define(ruby, &native)?;
78
103
  stream::define(ruby, &native)?;
79
104
  snapshot::define(ruby, &native)?;
80
105
  image::define(ruby, &native)?;
81
106
  volume::define(ruby, &native)?;
107
+ agent::define(ruby, &native)?;
108
+ ssh::define(ruby, &native)?;
82
109
 
83
110
  Ok(())
84
111
  }