diff options
| author | tv <tv@krebsco.de> | 2026-12-01 00:52:20 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-01 00:52:20 +0000 |
| commit | 30eb9a31ec7e4cf0ef683c86edb28ffc6fa3d54e (patch) | |
| tree | 82a3abb64b8ca02f79a76121d3f3a38c82f4fece | |
| parent | 54f070ef0f905f867a24dece72f667be23f9f843 (diff) | |
enstate: --pack warns of an entry from text with placeholders
Text loses its trailing line breaks, which a key or a certificate rarely
should; a whole-value source (cmd:…, file:…, or a table) takes an entry
byte-exact. The warning says so, and the entry goes in as asked.
| -rw-r--r-- | src/main.rs | 4 | ||||
| -rw-r--r-- | src/pack.rs | 15 | ||||
| -rw-r--r-- | tests/receptor.rs | 4 |
3 files changed, 18 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 8d3830b..5ae94e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -229,7 +229,9 @@ fn run() -> Result<ExitCode> { if command == "pack" { let out = out.context("--pack needs --out DIR")?; let schema = settings.schema.as_deref().map(Schema::load).transpose()?; - enstate::pack::pack(path.as_deref().unwrap(), &out, schema.as_ref())?; + for warning in enstate::pack::pack(path.as_deref().unwrap(), &out, schema.as_ref())? { + eprintln!("enstate: warning: {warning}"); + } return Ok(ExitCode::SUCCESS); } let store = Store::new( diff --git a/src/pack.rs b/src/pack.rs index 67603d6..dda4f6a 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -78,8 +78,9 @@ impl SourceList { } /// Packs the source list at `path` into a submission in `out` (which must not exist, -/// or be empty), checked against `schema` if one is given. -pub fn pack(path: &Path, out: &Path, schema: Option<&Schema>) -> Result<()> { +/// or be empty), checked against `schema` if one is given. Returns warnings: an +/// entry whose source is text with placeholders loses its trailing line breaks. +pub fn pack(path: &Path, out: &Path, schema: Option<&Schema>) -> Result<Vec<String>> { let list = SourceList::load(path)?; let dir = path .parent() @@ -104,10 +105,18 @@ pub fn pack(path: &Path, out: &Path, schema: Option<&Schema>) -> Result<()> { let mut entries: BTreeMap<String, Vec<u8>> = BTreeMap::new(); let mut records: BTreeMap<String, Map<String, Value>> = BTreeMap::new(); let mut specs = Vec::new(); + let mut warnings = Vec::new(); for (address, item) in &items { if let Some(source) = &item.source { let importer = importer(source, &dir, address.key.is_none()) .with_context(|| format!("item {address}"))?; + if address.key.is_none() && importer.is_interpolation() { + warnings.push(format!( + "item {address}: its source is text with placeholders, which loses \ + trailing line breaks; for the entry as it is, a whole-value source \ + (cmd:…, file:…, or a table) takes it byte-exact" + )); + } let imported = importer .fetch() .with_context(|| format!("item {address}: {}", importer.describe()))?; @@ -169,7 +178,7 @@ pub fn pack(path: &Path, out: &Path, schema: Option<&Schema>) -> Result<()> { content::write_file(&out.join(submission::MANIFEST), &manifest_bytes, 0o600)?; // What was written is a submission the receptor reads. submission::Submission::load(out)?; - Ok(()) + Ok(warnings) } /// The importer `source` describes, in `dir`: raw for an entry, JSON for a record. diff --git a/tests/receptor.rs b/tests/receptor.rs index 8bbadf4..56a1666 100644 --- a/tests/receptor.rs +++ b/tests/receptor.rs @@ -435,7 +435,9 @@ fn pack_from_sources() { let path = host.root.join("sources.json"); std::fs::write(&path, list.to_string()).unwrap(); let out = host.root.join("packed"); - enstate::pack::pack(&path, &out, Some(&schema.0)).unwrap(); + let warnings = enstate::pack::pack(&path, &out, Some(&schema.0)).unwrap(); + assert_eq!(warnings.len(), 1, "{warnings:?}"); + assert!(warnings[0].starts_with("item secrets/extra: its source is text with placeholders")); // Byte-exact entries: trailing line breaks stay. assert_eq!( std::fs::read(out.join("channels/secrets/a.key")).unwrap(), |
