Skip to content
This repository was archived by the owner on Apr 13, 2026. It is now read-only.

Commit 35393cb

Browse files
committed
feat: enhance CSV handling for firewall rules export
- Updated the CSV writing functionality to use `WriterBuilder`, allowing for more control over header inclusion. - Added a header row with exact column names for better clarity in the exported CSV files. - Ensured that the CSV output aligns with the expected format for firewall rules. - All changes have been tested, and the CSV export functionality is working as intended.
1 parent 10824f3 commit 35393cb

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/io/csv.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::generator::{FirewallRule, VlanConfig};
44
use crate::Result;
5-
use csv::{Reader, Writer};
5+
use csv::{Reader, Writer, WriterBuilder};
66
use lazy_static::lazy_static;
77
use serde::{Deserialize, Serialize};
88
use std::collections::HashSet;
@@ -276,9 +276,25 @@ impl From<FirewallRuleCsvRecord> for FirewallRule {
276276
/// Write firewall rules to a CSV file
277277
pub fn write_firewall_rules_csv<P: AsRef<Path>>(rules: &[FirewallRule], path: P) -> Result<()> {
278278
let file = File::create(path)?;
279-
let mut writer = Writer::from_writer(file);
280-
281-
// Write header and records
279+
let mut writer = WriterBuilder::new().has_headers(false).from_writer(file);
280+
281+
// Write header row with exact column names
282+
writer.write_record([
283+
"rule_id",
284+
"source",
285+
"destination",
286+
"protocol",
287+
"ports",
288+
"action",
289+
"direction",
290+
"description",
291+
"log",
292+
"vlan_id",
293+
"priority",
294+
"interface",
295+
])?;
296+
297+
// Write records
282298
for rule in rules {
283299
let record = FirewallRuleCsvRecord::from(rule);
284300
writer.serialize(record)?;

0 commit comments

Comments
 (0)