Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bunch of allowable things and hreflang fix #79

Merged
merged 5 commits into from
Sep 1, 2024
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
14 changes: 9 additions & 5 deletions icann-rdap-cli/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,22 @@ fn get_related_link(rdap_response: &RdapResponse) -> Vec<&str> {
let urls: Vec<&str> = links
.iter()
.filter(|l| {
if let Some(rel) = &l.rel {
if let Some(media_type) = &l.media_type {
rel.eq_ignore_ascii_case("related")
&& media_type.eq_ignore_ascii_case(RDAP_MEDIA_TYPE)
if l.href.as_ref().is_some() {
if let Some(rel) = &l.rel {
if let Some(media_type) = &l.media_type {
rel.eq_ignore_ascii_case("related")
&& media_type.eq_ignore_ascii_case(RDAP_MEDIA_TYPE)
} else {
false
}
} else {
false
}
} else {
false
}
})
.map(|l| l.href.as_str())
.map(|l| l.href.as_ref().unwrap().as_str())
.collect::<Vec<&str>>();
urls
} else {
Expand Down
42 changes: 22 additions & 20 deletions icann-rdap-cli/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,35 @@ pub(crate) async fn do_request(
let response = rdap_url_request(&query_url, client).await?;
if !processing_params.no_cache {
if let Some(self_link) = response.rdap.get_self_link() {
if response.http_data.should_cache() {
let data = serde_json::to_string_pretty(&response)?;
let cache_contents = response.http_data.to_lines(&data)?;
let query_url = query_type.query_url(base_url)?;
let file_name = format!(
"{}.cache",
PctString::encode(query_url.chars(), URIReserved)
);
debug!("Saving response to cache file {file_name}");
let path = rdap_cache_path().join(file_name);
fs::write(path, &cache_contents)?;
if query_url != self_link.href {
if let Some(self_link_href) = &self_link.href {
if response.http_data.should_cache() {
let data = serde_json::to_string_pretty(&response)?;
let cache_contents = response.http_data.to_lines(&data)?;
let query_url = query_type.query_url(base_url)?;
let file_name = format!(
"{}.cache",
PctString::encode(self_link.href.chars(), URIReserved)
PctString::encode(query_url.chars(), URIReserved)
);
debug!("Saving response to cache file {file_name}");
let path = rdap_cache_path().join(file_name);
fs::write(path, &cache_contents)?;
if query_url != *self_link_href {
let file_name = format!(
"{}.cache",
PctString::encode(self_link_href.chars(), URIReserved)
);
debug!("Saving response to cache file {file_name}");
let path = rdap_cache_path().join(file_name);
fs::write(path, &cache_contents)?;
}
} else {
debug!("Not caching data according to server policy.");
debug!("Expires header: {:?}", &response.http_data.expires);
debug!(
"Cache-control header: {:?}",
&response.http_data.cache_control
);
}
} else {
debug!("Not caching data according to server policy.");
debug!("Expires header: {:?}", &response.http_data.expires);
debug!(
"Cache-control header: {:?}",
&response.http_data.cache_control
);
}
}
}
Expand Down
46 changes: 25 additions & 21 deletions icann-rdap-client/src/gtld/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,26 @@ fn format_registry_dates(events: &Option<Vec<Event>>) -> String {
let mut formatted_dates = String::new();
if let Some(events) = events {
for event in events {
match event.event_action.as_str() {
"last changed" => {
if let Some(event_date) = &event.event_date {
formatted_dates.push_str(&format!("Updated Date: {}\n", event_date));
if let Some(event_action) = &event.event_action {
match event_action.as_str() {
"last changed" => {
if let Some(event_date) = &event.event_date {
formatted_dates.push_str(&format!("Updated Date: {}\n", event_date));
}
}
}
"registration" => {
if let Some(event_date) = &event.event_date {
formatted_dates.push_str(&format!("Creation Date: {}\n", event_date));
"registration" => {
if let Some(event_date) = &event.event_date {
formatted_dates.push_str(&format!("Creation Date: {}\n", event_date));
}
}
}
"expiration" => {
if let Some(event_date) = &event.event_date {
formatted_dates
.push_str(&format!("Registry Expiry Date: {}\n", event_date));
"expiration" => {
if let Some(event_date) = &event.event_date {
formatted_dates
.push_str(&format!("Registry Expiry Date: {}\n", event_date));
}
}
_ => {}
}
_ => {}
}
}
}
Expand Down Expand Up @@ -163,14 +165,16 @@ fn format_dnssec_info(secure_dns: &Option<SecureDns>) -> String {
fn format_last_update_info(events: &Option<Vec<Event>>, gtld: &mut String) {
if let Some(events) = events {
for event in events {
if event.event_action == "last update of RDAP database" {
if let Some(event_date) = &event.event_date {
gtld.push_str(&format!(
">>> Last update of RDAP database: {} <<<\n",
event_date
));
if let Some(event_action) = &event.event_action {
if event_action == "last update of RDAP database" {
if let Some(event_date) = &event.event_date {
gtld.push_str(&format!(
">>> Last update of RDAP database: {} <<<\n",
event_date
));
}
break;
}
break;
}
}
}
Expand Down
18 changes: 11 additions & 7 deletions icann-rdap-client/src/gtld/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ impl ToGtldWhois for Option<Vec<Entity>> {
// Special Sauce for Registrar IANA ID and Abuse Contact
if let Some(public_ids) = &entity.public_ids {
for public_id in public_ids {
if public_id.id_type.as_str() == "IANA Registrar ID"
&& !public_id.identifier.is_empty()
{
front_formatted_data += &format!(
"Registrar IANA ID: {}\n",
public_id.identifier.clone()
);
if let Some(id_type) = &public_id.id_type {
if let Some(identifier) = &public_id.identifier {
if id_type.as_str() == "IANA Registrar ID"
&& !identifier.is_empty()
{
front_formatted_data += &format!(
"Registrar IANA ID: {}\n",
identifier.clone()
);
}
}
}
}
}
Expand Down
40 changes: 34 additions & 6 deletions icann-rdap-client/src/md/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ impl ToMd for Link {
if let Some(rel) = &self.rel {
md.push_str(&format!("[{rel}] "));
};
md.push_str(&self.href.to_owned().to_inline(params.options));
if let Some(href) = &self.href {
md.push_str(&href.to_owned().to_inline(params.options));
}
md.push(' ');
if let Some(media_type) = &self.media_type {
md.push_str(&format!("of type '{media_type}' "));
Expand All @@ -83,7 +85,14 @@ impl ToMd for Link {
md.push_str(&format!("for {value} ",));
};
if let Some(hreflang) = &self.hreflang {
md.push_str(&format!("in languages {}", hreflang.join(", ")));
match hreflang {
icann_rdap_common::response::types::HrefLang::Lang(lang) => {
md.push_str(&format!("in language {}", lang));
}
icann_rdap_common::response::types::HrefLang::Langs(langs) => {
md.push_str(&format!("in languages {}", langs.join(", ")));
}
}
};
md.push('\n');
let checks = self.get_checks(CheckParams::from_md(params, TypeId::of::<Link>()));
Expand Down Expand Up @@ -218,7 +227,12 @@ pub(crate) fn public_ids_to_table(
mut table: MultiPartTable,
) -> MultiPartTable {
for pid in publid_ids {
table = table.data_ref(&pid.id_type, &pid.identifier);
table = table.data_ref(
pid.id_type.as_ref().unwrap_or(&"(not given)".to_string()),
pid.identifier
.as_ref()
.unwrap_or(&"(not given)".to_string()),
);
}
table
}
Expand All @@ -241,7 +255,15 @@ pub(crate) fn events_to_table(
if let Some(event_actor) = &event.event_actor {
ul.push(event_actor);
}
table = table.data_ul_ref(&event.event_action.to_owned().to_words_title_case(), ul);
table = table.data_ul_ref(
&event
.event_action
.as_ref()
.unwrap_or(&"action not given".to_string())
.to_owned()
.to_words_title_case(),
ul,
);
}
table
}
Expand All @@ -261,7 +283,10 @@ pub(crate) fn links_to_table(
.as_ref()
.unwrap_or(&"Link".to_string())
.to_title_case();
let mut ul: Vec<&String> = vec![&link.href];
let mut ul: Vec<&String> = vec![];
if let Some(href) = &link.href {
ul.push(href)
}
if let Some(media_type) = &link.media_type {
ul.push(media_type)
};
Expand All @@ -273,7 +298,10 @@ pub(crate) fn links_to_table(
};
let hreflang_s;
if let Some(hreflang) = &link.hreflang {
hreflang_s = hreflang.join(", ");
hreflang_s = match hreflang {
icann_rdap_common::response::types::HrefLang::Lang(lang) => lang.to_owned(),
icann_rdap_common::response::types::HrefLang::Langs(langs) => langs.join(", "),
};
ul.push(&hreflang_s)
};
table = table.data_ul_ref(&rel, ul);
Expand Down
3 changes: 3 additions & 0 deletions icann-rdap-common/src/check/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ impl GetChecks for Domain {
.object_common
.get_sub_checks(params.from_parent(TypeId::of::<Domain>())),
);
if let Some(public_ids) = &self.public_ids {
sub_checks.append(&mut public_ids.get_sub_checks(params));
}
sub_checks
} else {
Vec::new()
Expand Down
3 changes: 3 additions & 0 deletions icann-rdap-common/src/check/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ impl GetChecks for Entity {
.object_common
.get_sub_checks(params.from_parent(TypeId::of::<Entity>())),
);
if let Some(public_ids) = &self.public_ids {
sub_checks.append(&mut public_ids.get_sub_checks(params));
}
sub_checks
} else {
Vec::new()
Expand Down
30 changes: 30 additions & 0 deletions icann-rdap-common/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ pub enum Check {
LinkSelfIsNotRdap,
#[strum(message = "RFC 9083 recommends self links for all object classes")]
LinkObjectClassHasNoSelf,
#[strum(message = "'href' property not found in Link structure as required by RFC 9083")]
LinkMissingHrefProperty,

// Variant
#[strum(message = "empty domain variant is ambiguous")]
Expand All @@ -174,6 +176,8 @@ pub enum Check {
EventDateIsAbsent,
#[strum(message = "event date is not RFC 3339 compliant")]
EventDateIsNotRfc3339,
#[strum(message = "event action is absent")]
EventActionIsAbsent,

// Notice Or Remark
#[strum(message = "RFC 9083 requires a description in a notice or remark")]
Expand Down Expand Up @@ -266,6 +270,22 @@ pub enum Check {
// Port 43
#[strum(message = "port43 appears to be empty or only whitespace")]
Port43IsEmpty,

// Public Id
#[strum(message = "publicId type is absent")]
PublicIdTypeIsAbsent,
#[strum(message = "publicId identifier is absent")]
PublicIdIdentifierIsAbsent,

// Cidr0
#[strum(message = "Cidr0 v4 prefix is absent")]
Cidr0V4PrefixIsAbsent,
#[strum(message = "Cidr0 v4 length is absent")]
Cidr0V4LengthIsAbsent,
#[strum(message = "Cidr0 v6 prefix is absent")]
Cidr0V6PrefixIsAbsent,
#[strum(message = "Cidr0 v6 length is absent")]
Cidr0V6LengthIsAbsent,
}

impl Check {
Expand All @@ -280,11 +300,13 @@ impl Check {
Check::LinkSelfHasNoType => CheckClass::SpecificationWarning,
Check::LinkSelfIsNotRdap => CheckClass::SpecificationWarning,
Check::LinkObjectClassHasNoSelf => CheckClass::SpecificationWarning,
Check::LinkMissingHrefProperty => CheckClass::SpecificationError,

Check::VariantEmptyDomain => CheckClass::SpecificationWarning,

Check::EventDateIsAbsent => CheckClass::SpecificationError,
Check::EventDateIsNotRfc3339 => CheckClass::SpecificationError,
Check::EventActionIsAbsent => CheckClass::SpecificationError,

Check::NoticeOrRemarkDescriptionIsAbsent => CheckClass::SpecificationError,

Expand Down Expand Up @@ -331,6 +353,14 @@ impl Check {
Check::VcardFnIsEmpty => CheckClass::SpecificationWarning,

Check::Port43IsEmpty => CheckClass::SpecificationError,

Check::PublicIdTypeIsAbsent => CheckClass::SpecificationError,
Check::PublicIdIdentifierIsAbsent => CheckClass::SpecificationError,

Check::Cidr0V4PrefixIsAbsent => CheckClass::SpecificationError,
Check::Cidr0V4LengthIsAbsent => CheckClass::SpecificationError,
Check::Cidr0V6PrefixIsAbsent => CheckClass::SpecificationError,
Check::Cidr0V6LengthIsAbsent => CheckClass::SpecificationError,
};
CheckItem {
check_class,
Expand Down
Loading
Loading