Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 68 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ thiserror = "1.0.49"
serde = { version = "1.0.199", features = ["derive"] }
clap = { version = "4.5.1", features = ["derive"] }
pkarr = { version = "3.8.0"}
domain = {version = "0.10.3", features = ["zonefile", "bytes"]}
domain = {version = "0.11.0", features = ["zonefile", "bytes"]}
bytes = "1.7.1"
chrono = "0.4.38"
shellexpand = "3.1.0"
Expand All @@ -23,4 +23,4 @@ reqwest = { version="0.12.12", default-features = false, features = ["json", "ru
rand = {version = "0.8"}

[dev-dependencies]

tempfile = "3.20.0"
19 changes: 10 additions & 9 deletions cli/src/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ async fn fill_dyndns_variables(zone: &mut String) -> Result<(), anyhow::Error> {
Ok(())
}

async fn read_zone_file(matches: &ArgMatches, pubkey: &str) -> SimpleZone {
let unexpanded_path: &String = matches.get_one("zonefile").unwrap();
let csv_path_str: String = shellexpand::full(unexpanded_path).expect("Valid shell path.").into();
async fn read_zone_file(zone_file_path: &str, pubkey: &str) -> SimpleZone {
let csv_path_str: String = shellexpand::full(zone_file_path).expect("Valid shell path.").into();
let path = Path::new(&csv_path_str);
let path = PathBuf::from(path);

Expand All @@ -64,13 +63,12 @@ async fn read_zone_file(matches: &ArgMatches, pubkey: &str) -> SimpleZone {
zone.unwrap()
}

fn read_seed_file(matches: &ArgMatches) -> Keypair {
let unexpanded_path: &String = matches.get_one("seed").unwrap();
let expanded_path: String = shellexpand::full(unexpanded_path).expect("Valid shell path.").into();
fn read_seed_file(seed_file_path: &str) -> Keypair {
let expanded_path: String = shellexpand::full(seed_file_path).expect("Valid shell path.").into();
let path = Path::new(&expanded_path);
let path = PathBuf::from(path);

let seed = read_to_string(path);
let seed = std::fs::read_to_string(path);
if let Err(e) = seed {
eprintln!("Failed to read seed at {expanded_path}. {e}");
std::process::exit(1);
Expand All @@ -95,11 +93,14 @@ fn parse_seed(seed: &str) -> Keypair {
}

pub async fn cli_publish(matches: &ArgMatches) {
let keypair = read_seed_file(matches);
let seed_file_path: &String = matches.get_one("seed").expect("--seed file path is required");
let zone_file_path: &String = matches.get_one("zonefile").expect("--zonefile file path is required");

let keypair = read_seed_file(seed_file_path.as_str());
let pubkey = keypair.to_z32();
let client = construct_pkarr_client();

let zone = read_zone_file(matches, &pubkey).await;
let zone = read_zone_file(zone_file_path.as_str(), &pubkey).await;
println!("{}", zone.packet);
let packet = zone.packet.parsed();
let packet = SignedPacket::new(&keypair, &packet.answers, Timestamp::now());
Expand Down
61 changes: 59 additions & 2 deletions cli/src/simple_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,12 @@ $TTL 300
}

domain::rdata::ZoneRecordData::Txt(val) => {
let value = val.to_string();
let mut txt = pkarr::dns::rdata::TXT::new();
txt.add_string(value.as_str())?;

for bytes in val.iter() {
let ascii = std::str::from_utf8(bytes).unwrap();
txt.add_string(ascii)?;
}
let rdata: pkarr::dns::rdata::RData = pkarr::dns::rdata::RData::TXT(txt);

let rr = ResourceRecord::new(simple_name, pkarr::dns::CLASS::IN, ttl, rdata);
Expand Down Expand Up @@ -234,4 +237,58 @@ _text IN TXT hero=satoshi";

println!("{:#?}", packet.answers);
}

#[test]
fn test_read_zone_txt1() {
let raw_records = "foo IN TXT \"key1=1\" \"key2=2\"";

let zone = SimpleZone::read(raw_records.to_string(), "123456").unwrap();
let packet = zone.packet.parsed();

let entry = packet.answers.first().unwrap();

match &entry.rdata {
pkarr::dns::rdata::RData::TXT(txt) => {
let value1 = txt.clone().attributes().get("key1").unwrap().clone().unwrap();
assert_eq!(value1, "1");
let value2 = txt.clone().attributes().get("key2").unwrap().clone().unwrap();
assert_eq!(value2, "2");
}
_ => panic!("Expected TXT record, got {:?}", entry.rdata),
}
}

#[test]
fn test_read_zone_txt2() {
let raw_records = "foo IN TXT key=value";

let zone = SimpleZone::read(raw_records.to_string(), "123456").unwrap();
let packet = zone.packet.parsed();
let entry = packet.answers.last().unwrap();

match &entry.rdata {
pkarr::dns::rdata::RData::TXT(txt) => {
let value = txt.clone().attributes().get("key").unwrap().clone().unwrap();
assert_eq!(value, "value");
}
_ => panic!("Expected TXT record, got {:?}", entry.rdata),
}
}

#[test]
fn test_read_zone_txt3() {
let raw_records = "foo IN TXT \"key=value\"";

let zone = SimpleZone::read(raw_records.to_string(), "123456").unwrap();
let packet = zone.packet.parsed();
let entry = packet.answers.last().unwrap();

match &entry.rdata {
pkarr::dns::rdata::RData::TXT(txt) => {
let value = txt.clone().attributes().get("key").unwrap().clone().unwrap();
assert_eq!(value, "value");
}
_ => panic!("Expected TXT record, got {:?}", entry.rdata),
}
}
}
Loading