itsi 0.2.21.rc2 → 0.2.21

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +20 -0
  3. data/CHANGELOG.md +1 -1
  4. data/Cargo.lock +2 -2
  5. data/Dockerfile +2 -2
  6. data/crates/itsi_acme/src/caches/no.rs +1 -1
  7. data/crates/itsi_acme/src/caches/test.rs +3 -3
  8. data/crates/itsi_acme/src/config.rs +6 -6
  9. data/crates/itsi_acme/src/lib.rs +1 -1
  10. data/crates/itsi_error/src/lib.rs +32 -15
  11. data/crates/itsi_rb_helpers/src/heap_value.rs +2 -2
  12. data/crates/itsi_scheduler/Cargo.toml +1 -1
  13. data/crates/itsi_scheduler/src/itsi_scheduler.rs +1 -1
  14. data/crates/itsi_server/Cargo.toml +1 -1
  15. data/crates/itsi_server/src/ruby_types/itsi_body_proxy/big_bytes.rs +10 -3
  16. data/crates/itsi_server/src/ruby_types/itsi_body_proxy/mod.rs +10 -6
  17. data/crates/itsi_server/src/ruby_types/itsi_grpc_call.rs +7 -5
  18. data/crates/itsi_server/src/ruby_types/itsi_grpc_response_stream/mod.rs +2 -2
  19. data/crates/itsi_server/src/ruby_types/itsi_http_request.rs +10 -7
  20. data/crates/itsi_server/src/ruby_types/itsi_http_response.rs +13 -5
  21. data/crates/itsi_server/src/ruby_types/itsi_server/file_watcher.rs +6 -6
  22. data/crates/itsi_server/src/ruby_types/itsi_server/itsi_server_config.rs +15 -11
  23. data/crates/itsi_server/src/ruby_types/itsi_server.rs +2 -2
  24. data/crates/itsi_server/src/server/middleware_stack/middleware.rs +1 -1
  25. data/crates/itsi_server/src/server/middleware_stack/middlewares/compression.rs +1 -3
  26. data/crates/itsi_server/src/server/middleware_stack/middlewares/mod.rs +2 -2
  27. data/crates/itsi_server/src/server/middleware_stack/middlewares/proxy.rs +2 -2
  28. data/crates/itsi_server/src/server/middleware_stack/middlewares/redirect.rs +1 -1
  29. data/crates/itsi_server/src/server/middleware_stack/middlewares/ruby_app.rs +17 -7
  30. data/crates/itsi_server/src/server/middleware_stack/mod.rs +12 -12
  31. data/crates/itsi_server/src/server/serve_strategy/cluster_mode.rs +4 -3
  32. data/crates/itsi_server/src/services/password_hasher.rs +1 -1
  33. data/crates/itsi_server/src/services/static_file_server.rs +3 -4
  34. data/gems/scheduler/Cargo.lock +4006 -550
  35. data/gems/scheduler/lib/itsi/scheduler/version.rb +1 -1
  36. data/gems/server/Cargo.lock +28 -1
  37. data/gems/server/lib/itsi/server/version.rb +1 -1
  38. data/lib/itsi/version.rb +1 -1
  39. metadata +6 -5
@@ -27,7 +27,7 @@ impl ItsiServer {
27
27
  ) -> Result<()> {
28
28
  let ruby = Ruby::get().map_err(|_| {
29
29
  magnus::Error::new(
30
- magnus::exception::runtime_error(),
30
+ magnus::Ruby::get().unwrap().exception_runtime_error(),
31
31
  "Failed to acquire Ruby VM handle",
32
32
  )
33
33
  })?;
@@ -49,7 +49,7 @@ impl ItsiServer {
49
49
  fn config(&self) -> Result<Arc<ItsiServerConfig>> {
50
50
  self.config.lock().as_ref().cloned().ok_or_else(|| {
51
51
  magnus::Error::new(
52
- magnus::exception::runtime_error(),
52
+ magnus::Ruby::get().unwrap().exception_runtime_error(),
53
53
  "Itsi::Server not initialized",
54
54
  )
55
55
  })
@@ -159,7 +159,7 @@ impl Eq for Middleware {}
159
159
 
160
160
  impl PartialOrd for Middleware {
161
161
  fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
162
- Some(self.variant_order().cmp(&other.variant_order()))
162
+ Some(self.cmp(other))
163
163
  }
164
164
  }
165
165
 
@@ -293,9 +293,7 @@ impl MiddlewareLayer for Compression {
293
293
  };
294
294
  HttpBody::full(Bytes::from(compressed_bytes))
295
295
  } else {
296
- let stream = body
297
- .into_data_stream()
298
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e));
296
+ let stream = body.into_data_stream().map_err(std::io::Error::other);
299
297
  let async_read_fut = StreamReader::new(stream);
300
298
  let reader = BufReader::new(async_read_fut);
301
299
  match compression_method {
@@ -43,9 +43,9 @@ pub use error_response::ErrorResponse;
43
43
  pub use etag::ETag;
44
44
  pub use intrusion_protection::IntrusionProtection;
45
45
  pub use log_requests::LogRequests;
46
- use magnus::{error::Result, Ruby};
47
46
  use magnus::rb_sys::AsRawValue;
48
47
  use magnus::Value;
48
+ use magnus::{error::Result, Ruby};
49
49
  pub use max_body::MaxBody;
50
50
  pub use proxy::Proxy;
51
51
  pub use rate_limit::RateLimit;
@@ -90,7 +90,7 @@ pub trait FromValue: Sized + Send + Sync + 'static {
90
90
 
91
91
  let ruby = Ruby::get().map_err(|_| {
92
92
  magnus::Error::new(
93
- magnus::exception::runtime_error(),
93
+ magnus::Ruby::get().unwrap().exception_runtime_error(),
94
94
  "Failed to acquire Ruby VM handle",
95
95
  )
96
96
  })?;
@@ -280,14 +280,14 @@ impl MiddlewareLayer for Proxy {
280
280
  .build()
281
281
  .map_err(|e| {
282
282
  magnus::Error::new(
283
- magnus::exception::runtime_error(),
283
+ magnus::Ruby::get().unwrap().exception_runtime_error(),
284
284
  format!("Failed to build Reqwest client: {}", e),
285
285
  )
286
286
  })?,
287
287
  )
288
288
  .map_err(|_e| {
289
289
  magnus::Error::new(
290
- magnus::exception::standard_error(),
290
+ magnus::Ruby::get().unwrap().exception_standard_error(),
291
291
  "Failed to save resolver backends",
292
292
  )
293
293
  })?;
@@ -42,7 +42,7 @@ impl Redirect {
42
42
  *response.status_mut() = self.redirect_type.status_code();
43
43
  let destination = self.to.rewrite_request(req, context).parse().map_err(|e| {
44
44
  magnus::Error::new(
45
- magnus::exception::standard_error(),
45
+ magnus::Ruby::get().unwrap().exception_standard_error(),
46
46
  format!("Invalid Rewrite String: {:?}: {}", self.to, e),
47
47
  )
48
48
  })?;
@@ -8,7 +8,7 @@ use async_trait::async_trait;
8
8
  use derive_more::Debug;
9
9
  use either::Either;
10
10
  use itsi_rb_helpers::{HeapVal, HeapValue};
11
- use magnus::{block::Proc, error::Result, value::ReprValue, Symbol};
11
+ use magnus::{block::Proc, error::Result, value::ReprValue};
12
12
  use regex::Regex;
13
13
  use std::str::FromStr;
14
14
  use std::sync::atomic::Ordering;
@@ -44,23 +44,33 @@ impl FromStr for RequestType {
44
44
 
45
45
  impl RubyApp {
46
46
  pub fn from_value(params: HeapVal) -> magnus::error::Result<Arc<Self>> {
47
- let app = params.funcall::<_, _, Proc>(Symbol::new("[]"), ("app_proc",))?;
47
+ let app = params
48
+ .funcall::<_, _, Proc>(magnus::Ruby::get().unwrap().to_symbol("[]"), ("app_proc",))?;
48
49
  let sendfile = params
49
- .funcall::<_, _, bool>(Symbol::new("[]"), ("sendfile",))
50
+ .funcall::<_, _, bool>(magnus::Ruby::get().unwrap().to_symbol("[]"), ("sendfile",))
50
51
  .unwrap_or(true);
51
52
  let nonblocking = params
52
- .funcall::<_, _, bool>(Symbol::new("[]"), ("nonblocking",))
53
+ .funcall::<_, _, bool>(
54
+ magnus::Ruby::get().unwrap().to_symbol("[]"),
55
+ ("nonblocking",),
56
+ )
53
57
  .unwrap_or(false);
54
58
  let base_path_src = params
55
- .funcall::<_, _, String>(Symbol::new("[]"), ("base_path",))
59
+ .funcall::<_, _, String>(magnus::Ruby::get().unwrap().to_symbol("[]"), ("base_path",))
56
60
  .unwrap_or("".to_owned());
57
61
  let script_name = params
58
- .funcall::<_, _, Option<String>>(Symbol::new("[]"), ("script_name",))
62
+ .funcall::<_, _, Option<String>>(
63
+ magnus::Ruby::get().unwrap().to_symbol("[]"),
64
+ ("script_name",),
65
+ )
59
66
  .unwrap_or(None);
60
67
  let base_path = Regex::new(&base_path_src).unwrap();
61
68
 
62
69
  let request_type: RequestType = params
63
- .funcall::<_, _, String>(Symbol::new("[]"), ("request_type",))
70
+ .funcall::<_, _, String>(
71
+ magnus::Ruby::get().unwrap().to_symbol("[]"),
72
+ ("request_type",),
73
+ )
64
74
  .unwrap_or("http".to_string())
65
75
  .parse()
66
76
  .unwrap_or(RequestType::Http);
@@ -49,7 +49,7 @@ impl StringMatch {
49
49
  let src_str = value.funcall::<_, _, String>("source", ())?;
50
50
  let regex = Regex::new(&src_str).map_err(|e| {
51
51
  magnus::Error::new(
52
- magnus::exception::standard_error(),
52
+ magnus::Ruby::get().unwrap().exception_standard_error(),
53
53
  format!("Invalid regexp: {}", e),
54
54
  )
55
55
  })?;
@@ -142,7 +142,7 @@ impl MiddlewareSet {
142
142
  let mut routes = vec![];
143
143
  for (index, route) in RArray::from_value(*routes_raw)
144
144
  .ok_or(magnus::Error::new(
145
- magnus::exception::standard_error(),
145
+ magnus::Ruby::get().unwrap().exception_standard_error(),
146
146
  format!("Routes must be an array. Got {:?}", routes_raw),
147
147
  ))?
148
148
  .into_iter()
@@ -152,18 +152,18 @@ impl MiddlewareSet {
152
152
  let route_raw = route_hash
153
153
  .get("route")
154
154
  .ok_or(magnus::Error::new(
155
- magnus::exception::standard_error(),
155
+ magnus::Ruby::get().unwrap().exception_standard_error(),
156
156
  "Route is missing :route key",
157
157
  ))?
158
158
  .funcall::<_, _, String>("source", ())?;
159
159
 
160
160
  let middleware =
161
161
  RHash::from_value(route_hash.get("middleware").ok_or(magnus::Error::new(
162
- magnus::exception::standard_error(),
162
+ magnus::Ruby::get().unwrap().exception_standard_error(),
163
163
  "Route is missing middleware key",
164
164
  ))?)
165
165
  .ok_or(magnus::Error::new(
166
- magnus::exception::standard_error(),
166
+ magnus::Ruby::get().unwrap().exception_standard_error(),
167
167
  format!("middleware must be a hash. Got {:?}", routes_raw),
168
168
  ))?;
169
169
 
@@ -179,7 +179,7 @@ impl MiddlewareSet {
179
179
  RArray::from_value(value)
180
180
  .ok_or_else(|| {
181
181
  magnus::Error::new(
182
- magnus::exception::type_error(),
182
+ magnus::Ruby::get().unwrap().exception_type_error(),
183
183
  "Expected array",
184
184
  )
185
185
  })
@@ -232,7 +232,7 @@ impl MiddlewareSet {
232
232
  Ok(Self {
233
233
  route_set: RegexSet::new(&routes).map_err(|e| {
234
234
  magnus::Error::new(
235
- magnus::exception::standard_error(),
235
+ magnus::Ruby::get().unwrap().exception_standard_error(),
236
236
  format!("Failed to create route set: {}", e),
237
237
  )
238
238
  })?,
@@ -243,7 +243,7 @@ impl MiddlewareSet {
243
243
  .collect::<std::result::Result<Vec<Regex>, regex::Error>>()
244
244
  .map_err(|e| {
245
245
  magnus::Error::new(
246
- magnus::exception::standard_error(),
246
+ magnus::Ruby::get().unwrap().exception_standard_error(),
247
247
  format!("Failed to create route set: {}", e),
248
248
  )
249
249
  })?
@@ -254,7 +254,7 @@ impl MiddlewareSet {
254
254
  })
255
255
  } else {
256
256
  Err(magnus::Error::new(
257
- magnus::exception::standard_error(),
257
+ magnus::Ruby::get().unwrap().exception_standard_error(),
258
258
  "Failed to create middleware stack",
259
259
  ))
260
260
  }
@@ -286,7 +286,7 @@ impl MiddlewareSet {
286
286
  self.route_set
287
287
  );
288
288
  Err(magnus::Error::new(
289
- magnus::exception::standard_error(),
289
+ magnus::Ruby::get().unwrap().exception_standard_error(),
290
290
  format!(
291
291
  "No matching middleware stack found for request: {:?}",
292
292
  request
@@ -338,7 +338,7 @@ impl MiddlewareSet {
338
338
  "app" => Ok(Middleware::RubyApp(RubyApp::from_value(parameters.into())?)),
339
339
  "proxy" => Ok(Middleware::Proxy(Proxy::from_value(parameters)?)),
340
340
  _ => Err(magnus::Error::new(
341
- magnus::exception::standard_error(),
341
+ magnus::Ruby::get().unwrap().exception_standard_error(),
342
342
  format!("Unknown filter type: {}", mw_type),
343
343
  )),
344
344
  }
@@ -349,7 +349,7 @@ impl MiddlewareSet {
349
349
  match result {
350
350
  Ok(result) => Ok(result),
351
351
  Err(err) => Err(magnus::Error::new(
352
- magnus::exception::standard_error(),
352
+ magnus::Ruby::get().unwrap().exception_standard_error(),
353
353
  format!(
354
354
  "Failed to instantiate middleware of type {}, due to {}",
355
355
  middleware_type, err
@@ -145,9 +145,10 @@ impl ClusterMode {
145
145
 
146
146
  call_with_gvl(|_| {
147
147
  create_ruby_thread(move || {
148
- call_without_gvl(move || match worker_clone.boot(self_clone) {
149
- Err(err) => error!("Worker boot failed {:?}", err),
150
- _ => {}
148
+ call_without_gvl(move || {
149
+ if let Err(err) = worker_clone.boot(self_clone) {
150
+ error!("Worker boot failed {:?}", err);
151
+ }
151
152
  })
152
153
  });
153
154
  });
@@ -28,7 +28,7 @@ pub enum HashAlgorithm {
28
28
  pub fn create_password_hash(password: String, algo: Value) -> Result<String> {
29
29
  let ruby = Ruby::get().map_err(|_| {
30
30
  magnus::Error::new(
31
- magnus::exception::runtime_error(),
31
+ magnus::Ruby::get().unwrap().exception_runtime_error(),
32
32
  "Failed to acquire Ruby VM handle",
33
33
  )
34
34
  })?;
@@ -598,8 +598,7 @@ impl StaticFileServer {
598
598
  }
599
599
  }
600
600
  }
601
- if index_file.is_some() {
602
- let index_path = index_file.unwrap();
601
+ if let Some(index_path) = index_file {
603
602
  self.key_to_path
604
603
  .lock()
605
604
  .insert(key.to_string(), index_path.clone());
@@ -1254,8 +1253,8 @@ async fn generate_directory_listing(
1254
1253
  });
1255
1254
 
1256
1255
  // Serialize the JSON object to a pretty-printed string.
1257
- let json_string = serde_json::to_string_pretty(&json_obj)
1258
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
1256
+ let json_string =
1257
+ serde_json::to_string_pretty(&json_obj).map_err(std::io::Error::other)?;
1259
1258
 
1260
1259
  Ok(json_string)
1261
1260
  }