itsi 0.1.11 → 0.1.12

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 (293) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +1535 -45
  3. data/{sandbox/itsi_itsi_file/Itsi.rb → Itsi.rb} +19 -13
  4. data/Rakefile +8 -7
  5. data/crates/itsi_error/src/lib.rs +9 -0
  6. data/crates/itsi_rb_helpers/Cargo.toml +1 -0
  7. data/crates/itsi_rb_helpers/src/heap_value.rs +18 -0
  8. data/crates/itsi_rb_helpers/src/lib.rs +34 -7
  9. data/crates/itsi_server/Cargo.toml +69 -30
  10. data/crates/itsi_server/src/lib.rs +79 -147
  11. data/crates/itsi_server/src/{body_proxy → ruby_types/itsi_body_proxy}/big_bytes.rs +10 -5
  12. data/crates/itsi_server/src/{body_proxy/itsi_body_proxy.rs → ruby_types/itsi_body_proxy/mod.rs} +22 -3
  13. data/crates/itsi_server/src/ruby_types/itsi_grpc_request.rs +147 -0
  14. data/crates/itsi_server/src/ruby_types/itsi_grpc_response.rs +19 -0
  15. data/crates/itsi_server/src/ruby_types/itsi_grpc_stream/mod.rs +216 -0
  16. data/{gems/server/ext/itsi_server/src/request/itsi_request.rs → crates/itsi_server/src/ruby_types/itsi_http_request.rs} +101 -117
  17. data/crates/itsi_server/src/{response/itsi_response.rs → ruby_types/itsi_http_response.rs} +72 -41
  18. data/crates/itsi_server/src/ruby_types/itsi_server/file_watcher.rs +225 -0
  19. data/crates/itsi_server/src/ruby_types/itsi_server/itsi_server_config.rs +355 -0
  20. data/crates/itsi_server/src/ruby_types/itsi_server.rs +82 -0
  21. data/crates/itsi_server/src/ruby_types/mod.rs +55 -0
  22. data/crates/itsi_server/src/server/bind.rs +13 -5
  23. data/crates/itsi_server/src/server/byte_frame.rs +32 -0
  24. data/crates/itsi_server/src/server/cache_store.rs +74 -0
  25. data/crates/itsi_server/src/server/itsi_service.rs +172 -0
  26. data/crates/itsi_server/src/server/lifecycle_event.rs +3 -0
  27. data/crates/itsi_server/src/server/listener.rs +102 -2
  28. data/crates/itsi_server/src/server/middleware_stack/middleware.rs +153 -0
  29. data/crates/itsi_server/src/server/middleware_stack/middlewares/allow_list.rs +47 -0
  30. data/crates/itsi_server/src/server/middleware_stack/middlewares/auth_api_key.rs +58 -0
  31. data/crates/itsi_server/src/server/middleware_stack/middlewares/auth_basic.rs +82 -0
  32. data/crates/itsi_server/src/server/middleware_stack/middlewares/auth_jwt.rs +321 -0
  33. data/crates/itsi_server/src/server/middleware_stack/middlewares/cache_control.rs +139 -0
  34. data/crates/itsi_server/src/server/middleware_stack/middlewares/compression.rs +300 -0
  35. data/crates/itsi_server/src/server/middleware_stack/middlewares/cors.rs +287 -0
  36. data/crates/itsi_server/src/server/middleware_stack/middlewares/deny_list.rs +48 -0
  37. data/crates/itsi_server/src/server/middleware_stack/middlewares/error_response.rs +127 -0
  38. data/crates/itsi_server/src/server/middleware_stack/middlewares/etag.rs +191 -0
  39. data/crates/itsi_server/src/server/middleware_stack/middlewares/grpc_service.rs +72 -0
  40. data/crates/itsi_server/src/server/middleware_stack/middlewares/header_interpretation.rs +85 -0
  41. data/crates/itsi_server/src/server/middleware_stack/middlewares/intrusion_protection.rs +195 -0
  42. data/crates/itsi_server/src/server/middleware_stack/middlewares/log_requests.rs +82 -0
  43. data/crates/itsi_server/src/server/middleware_stack/middlewares/mod.rs +82 -0
  44. data/crates/itsi_server/src/server/middleware_stack/middlewares/proxy.rs +216 -0
  45. data/crates/itsi_server/src/server/middleware_stack/middlewares/rate_limit.rs +124 -0
  46. data/crates/itsi_server/src/server/middleware_stack/middlewares/redirect.rs +76 -0
  47. data/crates/itsi_server/src/server/middleware_stack/middlewares/request_headers.rs +43 -0
  48. data/crates/itsi_server/src/server/middleware_stack/middlewares/response_headers.rs +34 -0
  49. data/crates/itsi_server/src/server/middleware_stack/middlewares/ruby_app.rs +93 -0
  50. data/crates/itsi_server/src/server/middleware_stack/middlewares/static_assets.rs +162 -0
  51. data/crates/itsi_server/src/server/middleware_stack/middlewares/string_rewrite.rs +158 -0
  52. data/crates/itsi_server/src/server/middleware_stack/middlewares/token_source.rs +12 -0
  53. data/crates/itsi_server/src/server/middleware_stack/mod.rs +315 -0
  54. data/crates/itsi_server/src/server/mod.rs +8 -1
  55. data/crates/itsi_server/src/server/process_worker.rs +38 -12
  56. data/crates/itsi_server/src/server/rate_limiter.rs +565 -0
  57. data/crates/itsi_server/src/server/request_job.rs +11 -0
  58. data/crates/itsi_server/src/server/serve_strategy/cluster_mode.rs +119 -42
  59. data/crates/itsi_server/src/server/serve_strategy/mod.rs +9 -6
  60. data/crates/itsi_server/src/server/serve_strategy/single_mode.rs +256 -111
  61. data/crates/itsi_server/src/server/signal.rs +19 -0
  62. data/crates/itsi_server/src/server/static_file_server.rs +984 -0
  63. data/crates/itsi_server/src/server/thread_worker.rs +139 -94
  64. data/crates/itsi_server/src/server/types.rs +43 -0
  65. data/crates/itsi_server/test.md +14 -0
  66. data/crates/itsi_tracing/Cargo.toml +1 -0
  67. data/crates/itsi_tracing/src/lib.rs +216 -45
  68. data/docs/.gitignore +7 -0
  69. data/docs/.gitpod.yml +15 -0
  70. data/docs/Itsi.rb +17 -0
  71. data/docs/content/_index.md +17 -0
  72. data/docs/content/about.md +6 -0
  73. data/docs/content/docs/_index.md +18 -0
  74. data/docs/content/docs/first-page.md +9 -0
  75. data/docs/content/docs/folder/_index.md +10 -0
  76. data/docs/content/docs/folder/leaf.md +7 -0
  77. data/docs/go.mod +5 -0
  78. data/docs/go.sum +2 -0
  79. data/docs/hugo.yaml +77 -0
  80. data/examples/static_assets_example.rb +83 -0
  81. data/gems/_index.md +18 -0
  82. data/gems/scheduler/CODE_OF_CONDUCT.md +7 -0
  83. data/gems/scheduler/Cargo.lock +75 -14
  84. data/gems/scheduler/README.md +5 -0
  85. data/gems/scheduler/_index.md +7 -0
  86. data/gems/scheduler/itsi-scheduler.gemspec +4 -1
  87. data/gems/scheduler/lib/itsi/scheduler/version.rb +1 -1
  88. data/gems/scheduler/lib/itsi/scheduler.rb +2 -2
  89. data/gems/scheduler/test/test_file_io.rb +0 -1
  90. data/gems/scheduler/test/test_itsi_scheduler.rb +1 -1
  91. data/gems/server/CHANGELOG.md +5 -0
  92. data/gems/server/CODE_OF_CONDUCT.md +7 -0
  93. data/gems/server/Cargo.lock +1536 -45
  94. data/gems/server/README.md +4 -0
  95. data/gems/server/_index.md +6 -0
  96. data/gems/server/exe/itsi +33 -74
  97. data/gems/server/itsi-server.gemspec +3 -2
  98. data/gems/server/lib/itsi/{request.rb → http_request.rb} +29 -5
  99. data/gems/server/lib/itsi/http_response.rb +39 -0
  100. data/gems/server/lib/itsi/server/Itsi.rb +11 -19
  101. data/gems/server/lib/itsi/server/config/dsl.rb +506 -0
  102. data/gems/server/lib/itsi/server/config.rb +103 -8
  103. data/gems/server/lib/itsi/server/default_app/default_app.rb +38 -0
  104. data/gems/server/lib/itsi/server/grpc_interface.rb +213 -0
  105. data/gems/server/lib/itsi/server/rack/handler/itsi.rb +8 -17
  106. data/gems/server/lib/itsi/server/rack_interface.rb +23 -4
  107. data/gems/server/lib/itsi/server/scheduler_interface.rb +1 -1
  108. data/gems/server/lib/itsi/server/scheduler_mode.rb +4 -0
  109. data/gems/server/lib/itsi/server/signal_trap.rb +7 -1
  110. data/gems/server/lib/itsi/server/version.rb +1 -1
  111. data/gems/server/lib/itsi/server.rb +74 -63
  112. data/gems/server/lib/itsi/standard_headers.rb +86 -0
  113. data/gems/server/test/helpers/test_helper.rb +12 -12
  114. data/gems/server/test/test_itsi_server.rb +2 -2
  115. data/lib/itsi/version.rb +1 -1
  116. data/sandbox/itsi_file/Gemfile +11 -0
  117. data/sandbox/itsi_file/Gemfile.lock +69 -0
  118. data/sandbox/itsi_file/Itsi.rb +276 -0
  119. data/sandbox/itsi_file/error.html +2 -0
  120. data/sandbox/itsi_file/organisations_controller.rb +20 -0
  121. data/sandbox/itsi_file/public/assets/image.png +0 -0
  122. data/sandbox/itsi_file/public/assets/index.html +1 -0
  123. data/sandbox/itsi_sandbox_hanami/Gemfile.lock +2 -2
  124. data/sandbox/itsi_sandbox_rack/Gemfile.lock +2 -2
  125. data/sandbox/itsi_sandbox_rack/config.ru +2 -15
  126. data/sandbox/itsi_sandbox_rails/.dockerignore +2 -5
  127. data/sandbox/itsi_sandbox_rails/.github/workflows/ci.yml +1 -1
  128. data/sandbox/itsi_sandbox_rails/.gitignore +2 -1
  129. data/sandbox/itsi_sandbox_rails/Dockerfile +6 -9
  130. data/sandbox/itsi_sandbox_rails/Gemfile +16 -22
  131. data/sandbox/itsi_sandbox_rails/Gemfile.lock +100 -225
  132. data/sandbox/itsi_sandbox_rails/app/assets/config/manifest.js +4 -0
  133. data/sandbox/itsi_sandbox_rails/app/assets/stylesheets/application.css +11 -6
  134. data/sandbox/itsi_sandbox_rails/app/channels/application_cable/channel.rb +4 -0
  135. data/sandbox/itsi_sandbox_rails/app/channels/application_cable/connection.rb +4 -0
  136. data/sandbox/itsi_sandbox_rails/app/controllers/live_controller.rb +7 -8
  137. data/sandbox/itsi_sandbox_rails/app/controllers/uploads_controller.rb +0 -3
  138. data/sandbox/itsi_sandbox_rails/app/views/layouts/application.html.erb +2 -7
  139. data/sandbox/itsi_sandbox_rails/bin/docker-entrypoint +3 -4
  140. data/sandbox/itsi_sandbox_rails/bin/setup +8 -5
  141. data/sandbox/itsi_sandbox_rails/config/application.rb +1 -35
  142. data/sandbox/itsi_sandbox_rails/config/cable.yml +3 -10
  143. data/sandbox/itsi_sandbox_rails/config/credentials.yml.enc +1 -1
  144. data/sandbox/itsi_sandbox_rails/config/database.yml +9 -19
  145. data/sandbox/itsi_sandbox_rails/config/environment.rb +1 -1
  146. data/sandbox/itsi_sandbox_rails/config/environments/development.rb +21 -12
  147. data/sandbox/itsi_sandbox_rails/config/environments/production.rb +49 -34
  148. data/sandbox/itsi_sandbox_rails/config/environments/test.rb +19 -5
  149. data/sandbox/itsi_sandbox_rails/config/initializers/assets.rb +5 -0
  150. data/sandbox/itsi_sandbox_rails/config/initializers/filter_parameter_logging.rb +1 -1
  151. data/sandbox/itsi_sandbox_rails/config/initializers/permissions_policy.rb +13 -0
  152. data/sandbox/itsi_sandbox_rails/config/puma.rb +2 -9
  153. data/sandbox/itsi_sandbox_rails/config.ru +0 -1
  154. data/sandbox/itsi_sandbox_rails/db/migrate/20250301041554_create_posts.rb +1 -1
  155. data/sandbox/itsi_sandbox_rails/db/schema.rb +2 -2
  156. data/sandbox/itsi_sandbox_rails/lib/assets/.keep +0 -0
  157. data/sandbox/itsi_sandbox_rails/public/404.html +66 -113
  158. data/sandbox/itsi_sandbox_rails/public/406-unsupported-browser.html +65 -113
  159. data/sandbox/itsi_sandbox_rails/public/422.html +66 -113
  160. data/sandbox/itsi_sandbox_rails/public/500.html +65 -113
  161. data/sandbox/itsi_sandbox_rails/public/icon.png +0 -0
  162. data/sandbox/itsi_sandbox_rails/public/icon.svg +2 -2
  163. data/sandbox/itsi_sandbox_rails/test/channels/application_cable/connection_test.rb +13 -0
  164. data/sandbox/itsi_sandbox_roda/Gemfile.lock +3 -10
  165. data/tasks.txt +72 -35
  166. metadata +89 -139
  167. data/crates/itsi_server/src/body_proxy/mod.rs +0 -2
  168. data/crates/itsi_server/src/request/itsi_request.rs +0 -298
  169. data/crates/itsi_server/src/request/mod.rs +0 -1
  170. data/crates/itsi_server/src/response/mod.rs +0 -1
  171. data/crates/itsi_server/src/server/itsi_server.rs +0 -288
  172. data/gems/scheduler/ext/itsi_error/Cargo.lock +0 -368
  173. data/gems/scheduler/ext/itsi_error/Cargo.toml +0 -11
  174. data/gems/scheduler/ext/itsi_error/src/from.rs +0 -68
  175. data/gems/scheduler/ext/itsi_error/src/lib.rs +0 -24
  176. data/gems/scheduler/ext/itsi_instrument_entry/Cargo.toml +0 -15
  177. data/gems/scheduler/ext/itsi_instrument_entry/src/lib.rs +0 -31
  178. data/gems/scheduler/ext/itsi_rb_helpers/Cargo.lock +0 -355
  179. data/gems/scheduler/ext/itsi_rb_helpers/Cargo.toml +0 -10
  180. data/gems/scheduler/ext/itsi_rb_helpers/src/heap_value.rs +0 -121
  181. data/gems/scheduler/ext/itsi_rb_helpers/src/lib.rs +0 -201
  182. data/gems/scheduler/ext/itsi_scheduler/Cargo.toml +0 -24
  183. data/gems/scheduler/ext/itsi_scheduler/extconf.rb +0 -6
  184. data/gems/scheduler/ext/itsi_scheduler/src/itsi_scheduler/io_helpers.rs +0 -56
  185. data/gems/scheduler/ext/itsi_scheduler/src/itsi_scheduler/io_waiter.rs +0 -44
  186. data/gems/scheduler/ext/itsi_scheduler/src/itsi_scheduler/timer.rs +0 -44
  187. data/gems/scheduler/ext/itsi_scheduler/src/itsi_scheduler.rs +0 -308
  188. data/gems/scheduler/ext/itsi_scheduler/src/lib.rs +0 -38
  189. data/gems/scheduler/ext/itsi_server/Cargo.lock +0 -2956
  190. data/gems/scheduler/ext/itsi_server/Cargo.toml +0 -50
  191. data/gems/scheduler/ext/itsi_server/extconf.rb +0 -6
  192. data/gems/scheduler/ext/itsi_server/src/body_proxy/big_bytes.rs +0 -104
  193. data/gems/scheduler/ext/itsi_server/src/body_proxy/itsi_body_proxy.rs +0 -122
  194. data/gems/scheduler/ext/itsi_server/src/body_proxy/mod.rs +0 -2
  195. data/gems/scheduler/ext/itsi_server/src/env.rs +0 -43
  196. data/gems/scheduler/ext/itsi_server/src/lib.rs +0 -180
  197. data/gems/scheduler/ext/itsi_server/src/request/itsi_request.rs +0 -298
  198. data/gems/scheduler/ext/itsi_server/src/request/mod.rs +0 -1
  199. data/gems/scheduler/ext/itsi_server/src/response/itsi_response.rs +0 -357
  200. data/gems/scheduler/ext/itsi_server/src/response/mod.rs +0 -1
  201. data/gems/scheduler/ext/itsi_server/src/server/bind.rs +0 -174
  202. data/gems/scheduler/ext/itsi_server/src/server/bind_protocol.rs +0 -37
  203. data/gems/scheduler/ext/itsi_server/src/server/io_stream.rs +0 -104
  204. data/gems/scheduler/ext/itsi_server/src/server/itsi_server.rs +0 -288
  205. data/gems/scheduler/ext/itsi_server/src/server/lifecycle_event.rs +0 -9
  206. data/gems/scheduler/ext/itsi_server/src/server/listener.rs +0 -318
  207. data/gems/scheduler/ext/itsi_server/src/server/mod.rs +0 -11
  208. data/gems/scheduler/ext/itsi_server/src/server/process_worker.rs +0 -203
  209. data/gems/scheduler/ext/itsi_server/src/server/serve_strategy/cluster_mode.rs +0 -260
  210. data/gems/scheduler/ext/itsi_server/src/server/serve_strategy/mod.rs +0 -27
  211. data/gems/scheduler/ext/itsi_server/src/server/serve_strategy/single_mode.rs +0 -276
  212. data/gems/scheduler/ext/itsi_server/src/server/signal.rs +0 -74
  213. data/gems/scheduler/ext/itsi_server/src/server/thread_worker.rs +0 -399
  214. data/gems/scheduler/ext/itsi_server/src/server/tls/locked_dir_cache.rs +0 -132
  215. data/gems/scheduler/ext/itsi_server/src/server/tls.rs +0 -265
  216. data/gems/scheduler/ext/itsi_tracing/Cargo.lock +0 -274
  217. data/gems/scheduler/ext/itsi_tracing/Cargo.toml +0 -16
  218. data/gems/scheduler/ext/itsi_tracing/src/lib.rs +0 -58
  219. data/gems/server/ext/itsi_error/Cargo.lock +0 -368
  220. data/gems/server/ext/itsi_error/Cargo.toml +0 -11
  221. data/gems/server/ext/itsi_error/src/from.rs +0 -68
  222. data/gems/server/ext/itsi_error/src/lib.rs +0 -24
  223. data/gems/server/ext/itsi_instrument_entry/Cargo.toml +0 -15
  224. data/gems/server/ext/itsi_instrument_entry/src/lib.rs +0 -31
  225. data/gems/server/ext/itsi_rb_helpers/Cargo.lock +0 -355
  226. data/gems/server/ext/itsi_rb_helpers/Cargo.toml +0 -10
  227. data/gems/server/ext/itsi_rb_helpers/src/heap_value.rs +0 -121
  228. data/gems/server/ext/itsi_rb_helpers/src/lib.rs +0 -201
  229. data/gems/server/ext/itsi_scheduler/Cargo.toml +0 -24
  230. data/gems/server/ext/itsi_scheduler/extconf.rb +0 -6
  231. data/gems/server/ext/itsi_scheduler/src/itsi_scheduler/io_helpers.rs +0 -56
  232. data/gems/server/ext/itsi_scheduler/src/itsi_scheduler/io_waiter.rs +0 -44
  233. data/gems/server/ext/itsi_scheduler/src/itsi_scheduler/timer.rs +0 -44
  234. data/gems/server/ext/itsi_scheduler/src/itsi_scheduler.rs +0 -308
  235. data/gems/server/ext/itsi_scheduler/src/lib.rs +0 -38
  236. data/gems/server/ext/itsi_server/Cargo.lock +0 -2956
  237. data/gems/server/ext/itsi_server/Cargo.toml +0 -50
  238. data/gems/server/ext/itsi_server/extconf.rb +0 -6
  239. data/gems/server/ext/itsi_server/src/body_proxy/big_bytes.rs +0 -104
  240. data/gems/server/ext/itsi_server/src/body_proxy/itsi_body_proxy.rs +0 -122
  241. data/gems/server/ext/itsi_server/src/body_proxy/mod.rs +0 -2
  242. data/gems/server/ext/itsi_server/src/env.rs +0 -43
  243. data/gems/server/ext/itsi_server/src/lib.rs +0 -180
  244. data/gems/server/ext/itsi_server/src/request/mod.rs +0 -1
  245. data/gems/server/ext/itsi_server/src/response/itsi_response.rs +0 -357
  246. data/gems/server/ext/itsi_server/src/response/mod.rs +0 -1
  247. data/gems/server/ext/itsi_server/src/server/bind.rs +0 -174
  248. data/gems/server/ext/itsi_server/src/server/bind_protocol.rs +0 -37
  249. data/gems/server/ext/itsi_server/src/server/io_stream.rs +0 -104
  250. data/gems/server/ext/itsi_server/src/server/itsi_server.rs +0 -288
  251. data/gems/server/ext/itsi_server/src/server/lifecycle_event.rs +0 -9
  252. data/gems/server/ext/itsi_server/src/server/listener.rs +0 -318
  253. data/gems/server/ext/itsi_server/src/server/mod.rs +0 -11
  254. data/gems/server/ext/itsi_server/src/server/process_worker.rs +0 -203
  255. data/gems/server/ext/itsi_server/src/server/serve_strategy/cluster_mode.rs +0 -260
  256. data/gems/server/ext/itsi_server/src/server/serve_strategy/mod.rs +0 -27
  257. data/gems/server/ext/itsi_server/src/server/serve_strategy/single_mode.rs +0 -276
  258. data/gems/server/ext/itsi_server/src/server/signal.rs +0 -74
  259. data/gems/server/ext/itsi_server/src/server/thread_worker.rs +0 -399
  260. data/gems/server/ext/itsi_server/src/server/tls/locked_dir_cache.rs +0 -132
  261. data/gems/server/ext/itsi_server/src/server/tls.rs +0 -265
  262. data/gems/server/ext/itsi_tracing/Cargo.lock +0 -274
  263. data/gems/server/ext/itsi_tracing/Cargo.toml +0 -16
  264. data/gems/server/ext/itsi_tracing/src/lib.rs +0 -58
  265. data/gems/server/lib/itsi/server/options_dsl.rb +0 -401
  266. data/gems/server/lib/itsi/stream_io.rb +0 -38
  267. data/location_dsl.rb +0 -381
  268. data/sandbox/itsi_sandbox_rails/.kamal/hooks/docker-setup.sample +0 -3
  269. data/sandbox/itsi_sandbox_rails/.kamal/hooks/post-app-boot.sample +0 -3
  270. data/sandbox/itsi_sandbox_rails/.kamal/hooks/post-deploy.sample +0 -14
  271. data/sandbox/itsi_sandbox_rails/.kamal/hooks/post-proxy-reboot.sample +0 -3
  272. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-app-boot.sample +0 -3
  273. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-build.sample +0 -51
  274. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-connect.sample +0 -47
  275. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-deploy.sample +0 -109
  276. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-proxy-reboot.sample +0 -3
  277. data/sandbox/itsi_sandbox_rails/.kamal/secrets +0 -17
  278. data/sandbox/itsi_sandbox_rails/bin/dev +0 -2
  279. data/sandbox/itsi_sandbox_rails/bin/jobs +0 -6
  280. data/sandbox/itsi_sandbox_rails/bin/kamal +0 -27
  281. data/sandbox/itsi_sandbox_rails/bin/thrust +0 -5
  282. data/sandbox/itsi_sandbox_rails/config/cache.yml +0 -16
  283. data/sandbox/itsi_sandbox_rails/config/deploy.yml +0 -116
  284. data/sandbox/itsi_sandbox_rails/config/queue.yml +0 -18
  285. data/sandbox/itsi_sandbox_rails/config/recurring.yml +0 -10
  286. data/sandbox/itsi_sandbox_rails/db/cable_schema.rb +0 -11
  287. data/sandbox/itsi_sandbox_rails/db/cache_schema.rb +0 -14
  288. data/sandbox/itsi_sandbox_rails/db/queue_schema.rb +0 -129
  289. data/sandbox/itsi_sandbox_rails/public/400.html +0 -114
  290. data/sandbox/itsi_sandbox_rails/test/fixtures/posts.yml +0 -9
  291. data/sandbox/itsi_sandbox_rails/test/models/post_test.rb +0 -7
  292. /data/{sandbox/itsi_sandbox_rails/script/.keep → crates/_index.md} +0 -0
  293. /data/gems/server/lib/itsi/{index.html → server/default_app/index.html} +0 -0
@@ -1,265 +0,0 @@
1
- use base64::{engine::general_purpose, Engine as _};
2
- use itsi_error::Result;
3
- use itsi_tracing::info;
4
- use locked_dir_cache::LockedDirCache;
5
- use rcgen::{
6
- generate_simple_self_signed, CertificateParams, CertifiedKey, DnType, KeyPair, SanType,
7
- };
8
- use rustls::{
9
- pki_types::{CertificateDer, PrivateKeyDer},
10
- ClientConfig, RootCertStore,
11
- };
12
- use rustls_pemfile::{certs, pkcs8_private_keys};
13
- use std::{
14
- collections::HashMap,
15
- fs,
16
- io::{BufReader, Error},
17
- sync::Arc,
18
- };
19
- use tokio::sync::Mutex;
20
- use tokio_rustls::{rustls::ServerConfig, TlsAcceptor};
21
- use tokio_rustls_acme::{AcmeAcceptor, AcmeConfig, AcmeState};
22
-
23
- use crate::env::{
24
- ITSI_ACME_CACHE_DIR, ITSI_ACME_CA_PEM_PATH, ITSI_ACME_CONTACT_EMAIL, ITSI_ACME_DIRECTORY_URL,
25
- ITSI_LOCAL_CA_DIR,
26
- };
27
- mod locked_dir_cache;
28
-
29
- #[derive(Clone)]
30
- pub enum ItsiTlsAcceptor {
31
- Manual(TlsAcceptor),
32
- Automatic(
33
- AcmeAcceptor,
34
- Arc<Mutex<AcmeState<Error>>>,
35
- Arc<ServerConfig>,
36
- ),
37
- }
38
-
39
- /// Generates a TLS configuration based on either :
40
- /// * Input "cert" and "key" options (either paths or Base64-encoded strings) or
41
- /// * Performs automatic certificate generation/retrieval. Generated certs use an internal self-signed Isti CA.
42
- ///
43
- /// If a non-local host or optional domain parameter is provided,
44
- /// an automated certificate will attempt to be fetched using let's encrypt.
45
- pub fn configure_tls(
46
- host: &str,
47
- query_params: &HashMap<String, String>,
48
- ) -> Result<ItsiTlsAcceptor> {
49
- let domains = query_params
50
- .get("domains")
51
- .map(|v| v.split(',').map(String::from).collect::<Vec<_>>())
52
- .or_else(|| query_params.get("domain").map(|v| vec![v.to_string()]));
53
-
54
- if query_params.get("cert").is_some_and(|c| c == "acme") {
55
- if let Some(domains) = domains {
56
- let directory_url = &*ITSI_ACME_DIRECTORY_URL;
57
- info!(
58
- domains = format!("{:?}", domains),
59
- directory_url, "Requesting acme cert"
60
- );
61
- let acme_contact_email = query_params
62
- .get("acme_email")
63
- .map(|s| s.to_string())
64
- .or_else(|| (*ITSI_ACME_CONTACT_EMAIL).as_ref().ok().map(|s| s.to_string()))
65
- .ok_or_else(|| itsi_error::ItsiError::ArgumentError(
66
- "acme_email query param or ITSI_ACME_CONTACT_EMAIL must be set before you can auto-generate let's encrypt certificates".to_string(),
67
- ))?;
68
-
69
- let acme_config = AcmeConfig::new(domains)
70
- .contact([format!("mailto:{}", acme_contact_email)])
71
- .cache(LockedDirCache::new(&*ITSI_ACME_CACHE_DIR))
72
- .directory(directory_url);
73
-
74
- let acme_state = if let Ok(ca_pem_path) = &*ITSI_ACME_CA_PEM_PATH {
75
- let mut root_cert_store = RootCertStore::empty();
76
-
77
- let ca_pem = fs::read(ca_pem_path).expect("failed to read CA pem file");
78
- let mut ca_reader = BufReader::new(&ca_pem[..]);
79
- let der_certs: Vec<CertificateDer> = certs(&mut ca_reader)
80
- .collect::<std::result::Result<Vec<CertificateDer>, _>>()
81
- .map_err(|e| {
82
- itsi_error::ItsiError::ArgumentError(format!(
83
- "Invalid ACME CA Pem path {:?}",
84
- e
85
- ))
86
- })?;
87
- root_cert_store.add_parsable_certificates(der_certs);
88
-
89
- let client_config = ClientConfig::builder()
90
- .with_root_certificates(root_cert_store)
91
- .with_no_client_auth();
92
- acme_config
93
- .client_tls_config(Arc::new(client_config))
94
- .state()
95
- } else {
96
- acme_config.state()
97
- };
98
-
99
- let mut rustls_config = ServerConfig::builder()
100
- .with_no_client_auth()
101
- .with_cert_resolver(acme_state.resolver());
102
-
103
- rustls_config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
104
-
105
- let acceptor = acme_state.acceptor();
106
- return Ok(ItsiTlsAcceptor::Automatic(
107
- acceptor,
108
- Arc::new(Mutex::new(acme_state)),
109
- Arc::new(rustls_config),
110
- ));
111
- }
112
- }
113
- let (certs, key) = if let (Some(cert_path), Some(key_path)) =
114
- (query_params.get("cert"), query_params.get("key"))
115
- {
116
- // Load from file or Base64
117
- let certs = load_certs(cert_path);
118
- let key = load_private_key(key_path);
119
- (certs, key)
120
- } else {
121
- generate_ca_signed_cert(domains.unwrap_or(vec![host.to_owned()]))?
122
- };
123
-
124
- let mut config = ServerConfig::builder()
125
- .with_no_client_auth()
126
- .with_single_cert(certs, key)
127
- .expect("Failed to build TLS config");
128
-
129
- config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
130
- Ok(ItsiTlsAcceptor::Manual(TlsAcceptor::from(Arc::new(config))))
131
- }
132
-
133
- pub fn load_certs(path: &str) -> Vec<CertificateDer<'static>> {
134
- let data = if let Some(stripped) = path.strip_prefix("base64:") {
135
- general_purpose::STANDARD
136
- .decode(stripped)
137
- .expect("Invalid base64 certificate")
138
- } else {
139
- fs::read(path).expect("Failed to read certificate file")
140
- };
141
-
142
- if data.starts_with(b"-----BEGIN ") {
143
- let mut reader = BufReader::new(&data[..]);
144
- let certs_der: Vec<Vec<u8>> = certs(&mut reader)
145
- .map(|r| {
146
- r.map(|der| der.as_ref().to_vec())
147
- .map_err(itsi_error::ItsiError::from)
148
- })
149
- .collect::<Result<_>>()
150
- .expect("Failed to parse certificate file");
151
- certs_der
152
- .into_iter()
153
- .map(|vec| {
154
- // Convert the owned Vec<u8> into a CertificateDer and force 'static.
155
- unsafe { std::mem::transmute(CertificateDer::from(vec)) }
156
- })
157
- .collect()
158
- } else {
159
- vec![CertificateDer::from(data)]
160
- }
161
- }
162
-
163
- /// Loads a private key from a file or Base64.
164
- pub fn load_private_key(path: &str) -> PrivateKeyDer<'static> {
165
- let key_data = if let Some(stripped) = path.strip_prefix("base64:") {
166
- general_purpose::STANDARD
167
- .decode(stripped)
168
- .expect("Invalid base64 private key")
169
- } else {
170
- fs::read(path).expect("Failed to read private key file")
171
- };
172
-
173
- if key_data.starts_with(b"-----BEGIN ") {
174
- let mut reader = BufReader::new(&key_data[..]);
175
- let keys: Vec<Vec<u8>> = pkcs8_private_keys(&mut reader)
176
- .map(|r| {
177
- r.map(|key| key.secret_pkcs8_der().to_vec())
178
- .map_err(itsi_error::ItsiError::from)
179
- })
180
- .collect::<Result<_>>()
181
- .expect("Failed to parse private key");
182
- if !keys.is_empty() {
183
- return PrivateKeyDer::try_from(keys[0].clone()).unwrap();
184
- }
185
- }
186
- PrivateKeyDer::try_from(key_data).unwrap()
187
- }
188
-
189
- pub fn generate_ca_signed_cert(
190
- domains: Vec<String>,
191
- ) -> Result<(Vec<CertificateDer<'static>>, PrivateKeyDer<'static>)> {
192
- info!(
193
- domains = format!("{}", domains.join(", ")),
194
- "Self signed cert",
195
- );
196
- info!(
197
- "Add {} to your system's trusted cert store to resolve certificate errors.",
198
- format!("{}/itsi_dev_ca.crt", ITSI_LOCAL_CA_DIR.to_str().unwrap())
199
- );
200
- info!("Dev CA path can be overridden by setting env var: `ITSI_LOCAL_CA_DIR`.");
201
- let (ca_key_pem, ca_cert_pem) = get_or_create_local_dev_ca()?;
202
-
203
- let ca_kp = KeyPair::from_pem(&ca_key_pem).expect("Failed to load CA key");
204
- let ca_cert = CertificateParams::from_ca_cert_pem(&ca_cert_pem)
205
- .expect("Failed to parse embedded CA certificate")
206
- .self_signed(&ca_kp)
207
- .expect("Failed to self-sign embedded CA cert");
208
-
209
- let ee_key = KeyPair::generate_for(&rcgen::PKCS_ECDSA_P256_SHA256).unwrap();
210
- let mut ee_params = CertificateParams::default();
211
-
212
- use std::net::IpAddr;
213
-
214
- ee_params.subject_alt_names = domains
215
- .iter()
216
- .map(|domain| {
217
- if let Ok(ip) = domain.parse::<IpAddr>() {
218
- SanType::IpAddress(ip)
219
- } else {
220
- SanType::DnsName(domain.clone().try_into().unwrap())
221
- }
222
- })
223
- .collect();
224
-
225
- ee_params
226
- .distinguished_name
227
- .push(DnType::CommonName, domains[0].clone());
228
-
229
- ee_params.use_authority_key_identifier_extension = true;
230
-
231
- let ee_cert = ee_params.signed_by(&ee_key, &ca_cert, &ca_kp).unwrap();
232
- let ee_cert_der = ee_cert.der().to_vec();
233
- let ee_cert = CertificateDer::from(ee_cert_der);
234
- let ca_cert = CertificateDer::from(ca_cert.der().to_vec());
235
- Ok((
236
- vec![ee_cert, ca_cert],
237
- PrivateKeyDer::try_from(ee_key.serialize_der()).unwrap(),
238
- ))
239
- }
240
-
241
- fn get_or_create_local_dev_ca() -> Result<(String, String)> {
242
- let ca_dir = &*ITSI_LOCAL_CA_DIR;
243
- fs::create_dir_all(ca_dir)?;
244
-
245
- let key_path = ca_dir.join("itsi_dev_ca.key");
246
- let cert_path = ca_dir.join("itsi_dev_ca.crt");
247
-
248
- if key_path.exists() && cert_path.exists() {
249
- // Already have a local CA
250
- let key_pem = fs::read_to_string(&key_path)?;
251
- let cert_pem = fs::read_to_string(&cert_path)?;
252
-
253
- Ok((key_pem, cert_pem))
254
- } else {
255
- let subject_alt_names = vec!["dev.itsi.fyi".to_string(), "localhost".to_string()];
256
-
257
- let CertifiedKey { cert, key_pair } =
258
- generate_simple_self_signed(subject_alt_names).unwrap();
259
-
260
- fs::write(&key_path, key_pair.serialize_pem())?;
261
- fs::write(&cert_path, cert.pem())?;
262
-
263
- Ok((key_pair.serialize_pem(), cert.pem()))
264
- }
265
- }
@@ -1,274 +0,0 @@
1
- # This file is automatically @generated by Cargo.
2
- # It is not intended for manual editing.
3
- version = 4
4
-
5
- [[package]]
6
- name = "aho-corasick"
7
- version = "1.1.3"
8
- source = "registry+https://github.com/rust-lang/crates.io-index"
9
- checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
10
- dependencies = [
11
- "memchr",
12
- ]
13
-
14
- [[package]]
15
- name = "cfg-if"
16
- version = "1.0.0"
17
- source = "registry+https://github.com/rust-lang/crates.io-index"
18
- checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
19
-
20
- [[package]]
21
- name = "itsi_tracing"
22
- version = "0.1.0"
23
- dependencies = [
24
- "tracing",
25
- "tracing-subscriber",
26
- ]
27
-
28
- [[package]]
29
- name = "lazy_static"
30
- version = "1.5.0"
31
- source = "registry+https://github.com/rust-lang/crates.io-index"
32
- checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
33
-
34
- [[package]]
35
- name = "log"
36
- version = "0.4.26"
37
- source = "registry+https://github.com/rust-lang/crates.io-index"
38
- checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e"
39
-
40
- [[package]]
41
- name = "matchers"
42
- version = "0.1.0"
43
- source = "registry+https://github.com/rust-lang/crates.io-index"
44
- checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
45
- dependencies = [
46
- "regex-automata 0.1.10",
47
- ]
48
-
49
- [[package]]
50
- name = "memchr"
51
- version = "2.7.4"
52
- source = "registry+https://github.com/rust-lang/crates.io-index"
53
- checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
54
-
55
- [[package]]
56
- name = "nu-ansi-term"
57
- version = "0.46.0"
58
- source = "registry+https://github.com/rust-lang/crates.io-index"
59
- checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
60
- dependencies = [
61
- "overload",
62
- "winapi",
63
- ]
64
-
65
- [[package]]
66
- name = "once_cell"
67
- version = "1.20.3"
68
- source = "registry+https://github.com/rust-lang/crates.io-index"
69
- checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
70
-
71
- [[package]]
72
- name = "overload"
73
- version = "0.1.1"
74
- source = "registry+https://github.com/rust-lang/crates.io-index"
75
- checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
76
-
77
- [[package]]
78
- name = "pin-project-lite"
79
- version = "0.2.16"
80
- source = "registry+https://github.com/rust-lang/crates.io-index"
81
- checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
82
-
83
- [[package]]
84
- name = "proc-macro2"
85
- version = "1.0.93"
86
- source = "registry+https://github.com/rust-lang/crates.io-index"
87
- checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
88
- dependencies = [
89
- "unicode-ident",
90
- ]
91
-
92
- [[package]]
93
- name = "quote"
94
- version = "1.0.38"
95
- source = "registry+https://github.com/rust-lang/crates.io-index"
96
- checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
97
- dependencies = [
98
- "proc-macro2",
99
- ]
100
-
101
- [[package]]
102
- name = "regex"
103
- version = "1.11.1"
104
- source = "registry+https://github.com/rust-lang/crates.io-index"
105
- checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
106
- dependencies = [
107
- "aho-corasick",
108
- "memchr",
109
- "regex-automata 0.4.9",
110
- "regex-syntax 0.8.5",
111
- ]
112
-
113
- [[package]]
114
- name = "regex-automata"
115
- version = "0.1.10"
116
- source = "registry+https://github.com/rust-lang/crates.io-index"
117
- checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
118
- dependencies = [
119
- "regex-syntax 0.6.29",
120
- ]
121
-
122
- [[package]]
123
- name = "regex-automata"
124
- version = "0.4.9"
125
- source = "registry+https://github.com/rust-lang/crates.io-index"
126
- checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
127
- dependencies = [
128
- "aho-corasick",
129
- "memchr",
130
- "regex-syntax 0.8.5",
131
- ]
132
-
133
- [[package]]
134
- name = "regex-syntax"
135
- version = "0.6.29"
136
- source = "registry+https://github.com/rust-lang/crates.io-index"
137
- checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
138
-
139
- [[package]]
140
- name = "regex-syntax"
141
- version = "0.8.5"
142
- source = "registry+https://github.com/rust-lang/crates.io-index"
143
- checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
144
-
145
- [[package]]
146
- name = "sharded-slab"
147
- version = "0.1.7"
148
- source = "registry+https://github.com/rust-lang/crates.io-index"
149
- checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
150
- dependencies = [
151
- "lazy_static",
152
- ]
153
-
154
- [[package]]
155
- name = "smallvec"
156
- version = "1.14.0"
157
- source = "registry+https://github.com/rust-lang/crates.io-index"
158
- checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd"
159
-
160
- [[package]]
161
- name = "syn"
162
- version = "2.0.98"
163
- source = "registry+https://github.com/rust-lang/crates.io-index"
164
- checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1"
165
- dependencies = [
166
- "proc-macro2",
167
- "quote",
168
- "unicode-ident",
169
- ]
170
-
171
- [[package]]
172
- name = "thread_local"
173
- version = "1.1.8"
174
- source = "registry+https://github.com/rust-lang/crates.io-index"
175
- checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
176
- dependencies = [
177
- "cfg-if",
178
- "once_cell",
179
- ]
180
-
181
- [[package]]
182
- name = "tracing"
183
- version = "0.1.41"
184
- source = "registry+https://github.com/rust-lang/crates.io-index"
185
- checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
186
- dependencies = [
187
- "pin-project-lite",
188
- "tracing-attributes",
189
- "tracing-core",
190
- ]
191
-
192
- [[package]]
193
- name = "tracing-attributes"
194
- version = "0.1.28"
195
- source = "registry+https://github.com/rust-lang/crates.io-index"
196
- checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d"
197
- dependencies = [
198
- "proc-macro2",
199
- "quote",
200
- "syn",
201
- ]
202
-
203
- [[package]]
204
- name = "tracing-core"
205
- version = "0.1.33"
206
- source = "registry+https://github.com/rust-lang/crates.io-index"
207
- checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c"
208
- dependencies = [
209
- "once_cell",
210
- "valuable",
211
- ]
212
-
213
- [[package]]
214
- name = "tracing-log"
215
- version = "0.2.0"
216
- source = "registry+https://github.com/rust-lang/crates.io-index"
217
- checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
218
- dependencies = [
219
- "log",
220
- "once_cell",
221
- "tracing-core",
222
- ]
223
-
224
- [[package]]
225
- name = "tracing-subscriber"
226
- version = "0.3.19"
227
- source = "registry+https://github.com/rust-lang/crates.io-index"
228
- checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008"
229
- dependencies = [
230
- "matchers",
231
- "nu-ansi-term",
232
- "once_cell",
233
- "regex",
234
- "sharded-slab",
235
- "smallvec",
236
- "thread_local",
237
- "tracing",
238
- "tracing-core",
239
- "tracing-log",
240
- ]
241
-
242
- [[package]]
243
- name = "unicode-ident"
244
- version = "1.0.17"
245
- source = "registry+https://github.com/rust-lang/crates.io-index"
246
- checksum = "00e2473a93778eb0bad35909dff6a10d28e63f792f16ed15e404fca9d5eeedbe"
247
-
248
- [[package]]
249
- name = "valuable"
250
- version = "0.1.1"
251
- source = "registry+https://github.com/rust-lang/crates.io-index"
252
- checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
253
-
254
- [[package]]
255
- name = "winapi"
256
- version = "0.3.9"
257
- source = "registry+https://github.com/rust-lang/crates.io-index"
258
- checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
259
- dependencies = [
260
- "winapi-i686-pc-windows-gnu",
261
- "winapi-x86_64-pc-windows-gnu",
262
- ]
263
-
264
- [[package]]
265
- name = "winapi-i686-pc-windows-gnu"
266
- version = "0.4.0"
267
- source = "registry+https://github.com/rust-lang/crates.io-index"
268
- checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
269
-
270
- [[package]]
271
- name = "winapi-x86_64-pc-windows-gnu"
272
- version = "0.4.0"
273
- source = "registry+https://github.com/rust-lang/crates.io-index"
274
- checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
@@ -1,16 +0,0 @@
1
- [package]
2
- name = "itsi_tracing"
3
- version = "0.1.0"
4
- edition = "2024"
5
-
6
- [dependencies]
7
- tracing = { version = "0.1.41", features = ["attributes"] }
8
- tracing-subscriber = { version = "0.3.19", features = [
9
- "env-filter",
10
- "std",
11
- "fmt",
12
- "json",
13
- "ansi",
14
- ] }
15
- tracing-attributes = "0.1"
16
- atty = "0.2.14"
@@ -1,58 +0,0 @@
1
- use std::env;
2
-
3
- use atty::{Stream, is};
4
- use tracing::level_filters::LevelFilter;
5
- pub use tracing::{debug, error, info, trace, warn};
6
- pub use tracing_attributes::instrument; // Explicitly export from tracing-attributes
7
- use tracing_subscriber::{
8
- EnvFilter, Layer,
9
- fmt::{self, format},
10
- layer::SubscriberExt,
11
- };
12
-
13
- #[instrument]
14
- pub fn init() {
15
- let env_filter = EnvFilter::builder()
16
- .with_env_var("ITSI_LOG")
17
- .try_from_env()
18
- .unwrap_or_else(|_| EnvFilter::new("info"));
19
-
20
- let format = fmt::format()
21
- .compact()
22
- .with_file(false)
23
- .with_level(true)
24
- .with_line_number(false)
25
- .with_source_location(false)
26
- .with_target(false)
27
- .with_thread_ids(false);
28
-
29
- let is_tty = is(Stream::Stdout);
30
-
31
- let subscriber = tracing_subscriber::fmt()
32
- .event_format(format)
33
- .with_env_filter(env_filter);
34
-
35
- if (is_tty && env::var("ITSI_LOG_PLAIN").is_err()) || env::var("ITSI_LOG_ANSI").is_ok() {
36
- subscriber.with_ansi(true).init();
37
- } else {
38
- subscriber
39
- .fmt_fields(format::JsonFields::default())
40
- .event_format(fmt::format().json())
41
- .init();
42
- }
43
- }
44
-
45
- pub fn run_silently<F, R>(f: F) -> R
46
- where
47
- F: FnOnce() -> R,
48
- {
49
- // Build a minimal subscriber that filters *everything* out
50
- let no_op_subscriber =
51
- tracing_subscriber::registry().with(fmt::layer().with_filter(LevelFilter::OFF));
52
-
53
- // Turn that subscriber into a `Dispatch`
54
- let no_op_dispatch = tracing::dispatcher::Dispatch::new(no_op_subscriber);
55
-
56
- // Temporarily set `no_op_dispatch` as the *default* within this closure
57
- tracing::dispatcher::with_default(&no_op_dispatch, f)
58
- }