Expand description
§vynil-core
Generic Rust toolbox combining a Rhai scripting engine and a Handlebars templating engine, with optional Kubernetes / OCI / S3 / HTTP handlers.
Extracted from the vynil workspace so it can be reused
by other projects (kuberest, kydah, …) without pulling in vynil’s business abstractions
(CRDs, package model, instance controllers).
Status: API is not yet stable — expect breaking changes before
1.0.
§Features
| Feature | Default | What it adds |
|---|---|---|
rhai | ✅ | engine::Script engine + every other module’s Rhai bindings |
hbs | ✅ | hbs::HandleBars engine |
hbs-scripting | ✅ | register_helper_dir / rhai_register_helper_dir (handlebars/script_helper). Implies hbs + rhai. Keep it separate because script_helper pulls smartstring which breaks String + &String in some graphs (see hbs docs) |
http | ✅ | http::RestClient (reqwest) + http_mock::RestClientMock. Implies rhai |
crypto | ✅ | argon_hash / bcrypt_hash / gen_private_key helpers (Handlebars + Rhai) |
k8s | ❌ | Generic K8s handlers (k8s::K8sGeneric, k8s::K8sObject, …) + mocks. Implies rhai |
oci | ❌ | oci::Registry + OCI mock. Implies rhai |
s3 | ❌ | S3 helpers (s3::s3_get_yaml, s3::s3_list_keys). Implies rhai |
fs | ❌ | Filesystem access from Rhai (file_read, file_write, …) |
shell | ❌ | Shell execution (shell::run / shell::get_out + Rhai shell_run) |
password | ❌ | gen_password / gen_password_alphanum (opt-in to avoid name collisions) |
# default: Rhai + Handlebars + HTTP + crypto
vynil-core = "0.7"
# Kubernetes project
vynil-core = { version = "0.7", features = ["k8s"] }
# Handlebars only, no Rhai/smartstring in the graph
vynil-core = { version = "0.7", default-features = false, features = ["hbs", "crypto"] }§Quick start
vynil_core::set_client_name(|| "my-app.example.com".to_string());
// Rhai
let mut script = vynil_core::engine::Script::new_bare(vec!["scripts/".into()]);
script.engine.register_fn("my_fn", |s: String| s.len() as i64);
// script.run_file(&std::path::PathBuf::from("scripts/run.rhai"))?;
// Handlebars
let mut hbs = vynil_core::hbs::HandleBars::new();
let out = hbs.render("Hello {{ name }}!", &serde_json::json!({"name": "world"})).unwrap();
assert_eq!(out, "Hello world!");§Client identity
vynil-core does not assume an identity. Call set_client_name once at startup
before any HTTP or Kubernetes call, otherwise those calls panic with an actionable message.
vynil_core::set_client_name(|| "my-app.example.com".to_string());
assert!(vynil_core::client_name_is_set());§Rhai helpers (injected by engine::Script::new_bare)
Common: sha256, log_debug/info/warn/error, url_encode, get_env, to_decimal,
base64_encode/decode, json_encode/decode, basename, dirname.
Additional, feature-gated: yaml_encode/decode, semver_from + inc_*, glob,
date_now/format, crc32_hash/bcrypt_hash/argon, gen_private_key,
gen_password (feature password), file_* (feature fs), shell_* (feature shell),
Registry / s3_* / RestClient / k8s_* when their feature is enabled.
Scripts also get assert and import_run / import_template shims for optional imports.
§Handlebars helpers (injected by hbs::HandleBars::new)
See hbs::CORE_HBS_HELPERS for the full list. Highlights: base64_encode/decode,
url_encode, to_decimal, header_basic, crc32_hash, argon_hash/bcrypt_hash/gen_private_key
(feature crypto), gen_password* (feature password), plus the handlebars_misc_helpers
set and the vendored json_to_str / str_to_json / json_query family.
§Crate boundaries
This crate stays generic: no dependency on vynil, kuberest or kydah, no default
client name, no CRDs or vynil-specific Handlebars helpers.
Re-exports§
pub use client_name::client_name_is_set;pub use client_name::get_client_name;pub use client_name::set_client_name;pub use semver::Semver;pub use engine::Script;rhaipub use hbs::HandleBars;hbspub use k8s::update_cache;k8s
Modules§
- chrono
- Date/time helpers (
DateTimeHandler). Date/time helper for Rhai. - client_
name - Global client identity (
User-Agent/ field-manager). Global client identity used as HTTPUser-Agentand Kubernetes field-manager. - engine
rhai - Rhai scripting engine (
engine::Script) and its registered helpers. Rhai scripting engine. - glob
rhai - Glob matching (
globRhai helper). Glob matching helper for Rhai (globfunction wrappingwildmatch). - hashes
- Hash helpers (crc32, bcrypt, argon2).
Hash helpers:
crc32_hash(always),bcrypt_hash/Argon(featurecrypto). - hbs
hbs - Handlebars templating engine (
hbs::HandleBars) and its helpers. Handlebars templating engine. - http
http - HTTP client (
http::RestClient). HTTP client (RestClient) and free helpers (http_get_yaml,headers_get). - http_
mock http - Mock HTTP client for tests (
http_mock::RestClientMock). Mock HTTP client for tests — Rhai-compatible drop-in forcrate::http::RestClient. - k8s
k8s - Kubernetes handlers (
K8sGeneric,K8sObject, …). Kubernetes handlers. - k8s_
mock k8s - Mock Kubernetes helpers. Mock Kubernetes handlers for tests.
- key
crypto - Private key generation (RSA / ed25519 via OpenSSL). Private key generation (RSA / ed25519 via OpenSSL).
- oci
oci - OCI registry client (
oci::Registry). OCI registry helpers (Registry) and auth utilities. - oci_
mock oci - Mock OCI helpers.
Mock OCI registry for tests. See
crate::oci::Registryfor the real client. - password
- Password generation. Password generation with per-class minimums.
- s3
s3 - S3 helpers (
s3_get_yaml,s3_list_keys). S3 helpers (s3_get_yaml,s3_list_keys) exposed to Rhai. - semver
- Semver parsing and mutation. Semver parsing and bumping.
- shell
shell - Shell execution helpers. Shell execution helpers.
- yaml
- YAML ↔ JSON helpers. YAML ↔ JSON / Rhai helpers.
Macros§
Enums§
- Error
- Errors returned by
vynil-coreoperations.
Functions§
- error_
chain - Render an error together with its full
source()chain, e.g.error sending request for url (...): dns error: failed to lookup address information: .... - rhai_
err rhai - Convert a
Errorinto a RhaiEvalAltResult, including its fullsource()chain (seeerror_chain) so the real cause of a connection-level failure isn’t swallowed. - rhai_
err_ str rhai - Convert a string into a Rhai
EvalAltResult.