Skip to content

Commit

Permalink
Merge pull request #61 from icann/dev
Browse files Browse the repository at this point in the history
Release 0.0.16
  • Loading branch information
anewton1998 authored Mar 15, 2024
2 parents 5f945c8 + a621ebc commit 19de4d9
Show file tree
Hide file tree
Showing 45 changed files with 1,529 additions and 63 deletions.
11 changes: 7 additions & 4 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = [
resolver = "2"

[workspace.package]
version = "0.0.15"
version = "0.0.16"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/icann/icann-rdap"
Expand Down Expand Up @@ -78,6 +78,9 @@ http = "1.0"
# hyper (http implementation used by axum)
hyper = { version = "1.0", features = ["full"] }

# internationalized domain names for applications
idna = "0.5"

# for use prefixmap
ipnet = { version = "2.9", features = ["json"] }

Expand Down
4 changes: 2 additions & 2 deletions icann-rdap-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ path = "src/main.rs"

[dependencies]

icann-rdap-client = { version = "0.0.15", path = "../icann-rdap-client" }
icann-rdap-common = { version = "0.0.15", path = "../icann-rdap-common" }
icann-rdap-client = { version = "0.0.16", path = "../icann-rdap-client" }
icann-rdap-common = { version = "0.0.16", path = "../icann-rdap-common" }

anyhow.workspace = true
clap.workspace = true
Expand Down
20 changes: 15 additions & 5 deletions icann-rdap-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,22 @@ For more advanced usage, run `rdap --help` which should yield the extensive help
Paging Output
-------------

By default, the client will attempt to determine if paging the output (showing information one page at a time)
is appropriate. This is done by attempting to determine if the terminal is interactive or not. If the terminal
is not interactive, paging will be turned off otherwise it will be on.
The client has a built-in (embedded) pager. Use of this pager is controlled via the `RDAP_PAGING`
environment variable and the `-P` command argument.

It takes three values:

* "embedded" - use the built-in pager
* "auto" - use the built-in pager if the program is being run from a terminal
* "none" - use no paging

You can explicitly control this behavior using the `-P` command argument such as `-P none` to specify no paging.
This is also controlled via the `RDAP_PAGING` environmental variable (see configuration below).
For example, `-P embedded` will default to using the built-in pager.

By default, the client will not use a pager.

When set to "auto", the client determines if a pager is appropriate.
This is done by attempting to determine if the terminal is interactive or not. If the terminal
is not interactive, paging will be turned off otherwise it will be on.

Output Format
-------------
Expand Down
6 changes: 5 additions & 1 deletion icann-rdap-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct Cli {
required = false,
env = "RDAP_PAGING",
value_enum,
default_value_t = PagerType::Auto,
default_value_t = PagerType::None,
)]
page_output: PagerType,

Expand Down Expand Up @@ -240,6 +240,9 @@ enum QtypeArg {
/// Domain Lookup
Domain,

/// A-Label Domain Lookup
ALabel,

/// Entity Lookup
Entity,

Expand Down Expand Up @@ -520,6 +523,7 @@ fn query_type_from_cli(cli: &Cli) -> QueryType {
QtypeArg::V6Cidr => QueryType::IpV6Cidr(query_value),
QtypeArg::Autnum => QueryType::AsNumber(query_value),
QtypeArg::Domain => QueryType::Domain(query_value),
QtypeArg::ALabel => QueryType::ALable(query_value),
QtypeArg::Entity => QueryType::Entity(query_value),
QtypeArg::Ns => QueryType::Nameserver(query_value),
QtypeArg::EntityName => QueryType::EntityNameSearch(query_value),
Expand Down
36 changes: 20 additions & 16 deletions icann-rdap-cli/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,29 +213,33 @@ fn do_output<'a, W: std::io::Write>(
}),
)?;
}
OutputType::Markdown => writeln!(
write,
"{}",
response.rdap.to_md(MdParams {
heading_level: 1,
root: &response.rdap,
parent_type: response.rdap.get_type(),
check_types: &processing_params.check_types,
options: &MdOptions {
text_style_char: '_',
style_in_justify: true,
..MdOptions::default()
},
req_data,
})
)?,
OutputType::Markdown => {
writeln!(
write,
"{}",
response.rdap.to_md(MdParams {
heading_level: 1,
root: &response.rdap,
parent_type: response.rdap.get_type(),
check_types: &processing_params.check_types,
options: &MdOptions {
text_style_char: '_',
style_in_justify: true,
..MdOptions::default()
},
req_data,
})
)?;
}
_ => {} // do nothing
};

let checks = response.rdap.get_checks(CheckParams {
do_subchecks: true,
root: &response.rdap,
parent_type: response.rdap.get_type(),
});

let req_res = RequestResponse {
checks,
req_data,
Expand Down
19 changes: 19 additions & 0 deletions icann-rdap-cli/tests/integration/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::test_jig::TestJig;
#[case("foo.example", "foo.example")]
#[case("foo.example", "foo.example.")]
#[case("foo.example", "FOO.EXAMPLE")]
#[case("foó.example", "foó.example")] // unicode
#[tokio::test(flavor = "multi_thread")]
async fn GIVEN_domain_WHEN_query_THEN_success(#[case] db_domain: &str, #[case] q_domain: &str) {
// GIVEN
Expand Down Expand Up @@ -156,3 +157,21 @@ async fn GIVEN_url_WHEN_query_THEN_success() {
let assert = test_jig.cmd.assert();
assert.success();
}

#[tokio::test(flavor = "multi_thread")]
async fn GIVEN_idn_WHEN_query_a_label_THEN_success() {
// GIVEN
let mut test_jig = TestJig::new().await;
let mut tx = test_jig.mem.new_tx().await.expect("new transaction");
tx.add_domain(&Domain::basic().ldh_name("xn--caf-dma.example").build())
.await
.expect("add domain in tx");
tx.commit().await.expect("tx commit");

// WHEN
test_jig.cmd.arg("-t").arg("a-label").arg("café.example");

// THEN
let assert = test_jig.cmd.assert();
assert.success();
}
3 changes: 2 additions & 1 deletion icann-rdap-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ An RDAP client library.

[dependencies]

icann-rdap-common = { version = "0.0.15", path = "../icann-rdap-common" }
icann-rdap-common = { version = "0.0.16", path = "../icann-rdap-common" }

buildstructor.workspace = true
cidr-utils.workspace = true
chrono.workspace = true
const_format.workspace = true
idna.workspace = true
lazy_static.workspace = true
pct-str.workspace = true
regex.workspace = true
Expand Down
5 changes: 5 additions & 0 deletions icann-rdap-client/src/md/autnum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ impl ToMd for Autnum {
.to_md(params.from_parent(typeid)),
);

// redacted
if let Some(redacted) = &self.object_common.redacted {
md.push_str(&redacted.as_slice().to_md(params.from_parent(typeid)));
}

md.push('\n');
md
}
Expand Down
5 changes: 5 additions & 0 deletions icann-rdap-client/src/md/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ impl ToMd for Domain {
md.push_str(&network.to_md(params.next_level()));
}

// redacted
if let Some(redacted) = &self.object_common.redacted {
md.push_str(&redacted.as_slice().to_md(params.from_parent(typeid)));
}

md.push('\n');
md
}
Expand Down
5 changes: 5 additions & 0 deletions icann-rdap-client/src/md/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ impl ToMd for Entity {
.to_md(params.from_parent(typeid)),
);

// redacted
if let Some(redacted) = &self.object_common.redacted {
md.push_str(&redacted.as_slice().to_md(params.from_parent(typeid)));
}

md.push('\n');
md
}
Expand Down
1 change: 1 addition & 0 deletions icann-rdap-client/src/md/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod error;
pub mod help;
pub mod nameserver;
pub mod network;
pub mod redacted;
pub mod search;
pub mod string;
pub mod table;
Expand Down
6 changes: 6 additions & 0 deletions icann-rdap-client/src/md/nameserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ impl ToMd for Nameserver {
.entities
.to_md(params.from_parent(typeid)),
);

// redacted
if let Some(redacted) = &self.object_common.redacted {
md.push_str(&redacted.as_slice().to_md(params.from_parent(typeid)));
}

md.push('\n');
md
}
Expand Down
6 changes: 6 additions & 0 deletions icann-rdap-client/src/md/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ impl ToMd for Network {
.entities
.to_md(params.from_parent(typeid)),
);

// redacted
if let Some(redacted) = &self.object_common.redacted {
md.push_str(&redacted.as_slice().to_md(params.from_parent(typeid)));
}

md.push('\n');
md
}
Expand Down
63 changes: 63 additions & 0 deletions icann-rdap-client/src/md/redacted.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use icann_rdap_common::response::redacted::Redacted;

use super::{string::StringUtil, table::MultiPartTable, MdOptions, MdParams, ToMd};

impl ToMd for &[Redacted] {
fn to_md(&self, params: MdParams) -> String {
let mut md = String::new();

// header
let header_text = "Redacted".to_string();
md.push_str(&header_text.to_header(params.heading_level, params.options));

// multipart data
let mut table = MultiPartTable::new();
table = table.header_ref(&"Fields");

for (index, redacted) in self.iter().enumerate() {
let options = MdOptions {
text_style_char: '*',
..Default::default()
};

// make the name bold
let name = "Redaction";
let b_name = name.to_bold(&options);
// build the table
table = table.and_data_ref(&b_name, &Some((index + 1).to_string()));

// Get the data itself
let name_data = redacted
.name
.description
.clone()
.or(redacted.name.type_field.clone());
let method_data = redacted.method.as_ref().map(|m| m.to_string());
let reason_data = redacted.reason.as_ref().map(|m| m.to_string());

// Special case the 'column' fields
table = table
.and_data_ref(&"name".to_title_case(), &name_data)
.and_data_ref(&"prePath".to_title_case(), &redacted.pre_path)
.and_data_ref(&"postPath".to_title_case(), &redacted.post_path)
.and_data_ref(
&"replacementPath".to_title_case(),
&redacted.replacement_path,
)
.and_data_ref(&"pathLang".to_title_case(), &redacted.path_lang)
.and_data_ref(&"method".to_title_case(), &method_data)
.and_data_ref(&"reason".to_title_case(), &reason_data);

// we don't have these right now but if we put them in later we will need them
// let check_params = CheckParams::from_md(params, typeid);
// let mut checks = redacted.object_common.get_sub_checks(check_params);
// checks.push(redacted.get_checks(check_params));
// table = checks_to_table(checks, table, params);
}

// render table
md.push_str(&table.to_md(params));
md.push('\n');
md
}
}
Loading

0 comments on commit 19de4d9

Please sign in to comment.