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

Dev #91

Merged
merged 30 commits into from
Dec 3, 2024
Merged

Dev #91

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4b1d638
addressing part of #2
anewton1998 Oct 8, 2024
9b2aa43
rearranged the caching code to always work for query urls even if sel…
anewton1998 Oct 10, 2024
cbff94f
added registry processing plus consolidated code
anewton1998 Oct 10, 2024
2ea52bf
fixing issue with exit codes and registery and registrar processing
anewton1998 Oct 10, 2024
67a1567
initial work on registered redactions
anewton1998 Oct 21, 2024
afc919e
redaction by registration
anewton1998 Oct 23, 2024
84bf73d
added protection of pathLang not being jsonpath
anewton1998 Oct 23, 2024
6cb5e56
fixes #87
anewton1998 Oct 24, 2024
b621c41
removing whitespace lines in notices and remarks
anewton1998 Oct 24, 2024
26a618e
reformatting of the links in markdown
anewton1998 Oct 24, 2024
c18549a
adds summary information to objects and some other UI cleanups
anewton1998 Oct 30, 2024
e06ba7c
updating dependencies
anewton1998 Oct 30, 2024
41e89c8
adding cors and hsts headers
anewton1998 Oct 31, 2024
9b95025
added extension identifiers and method to ask if in conformance array
anewton1998 Oct 31, 2024
4bbebcd
adds enumstring and display to checkclass and check
anewton1998 Oct 31, 2024
8b8eccc
added checks for cors and must use https with icann tig
anewton1998 Nov 2, 2024
deb1262
accomodate servers that do string instead of array of strings for des…
anewton1998 Nov 3, 2024
d6e8bb8
add icannerror to check args and fix check for rfc9083 description check
anewton1998 Nov 3, 2024
6039eaa
added cors headers to spec warn in accordance with RFC 7480.
anewton1998 Nov 5, 2024
d8d6a97
content type checks
anewton1998 Nov 10, 2024
b9dc39b
normalizing jsonpath dependencies
anewton1998 Dec 1, 2024
a6861c7
renamed files from cache to httpdata to be more descriptive
anewton1998 Dec 1, 2024
9e0bf6b
fixes issue #86
anewton1998 Dec 1, 2024
553b638
removing as #10 was done a long time ago.
anewton1998 Dec 1, 2024
7bc2028
option to query IANA for TLDs
anewton1998 Dec 1, 2024
9e8d8d8
fixed some of the autnum classifications and added tests.
anewton1998 Dec 2, 2024
709cc60
fixes a bug where iana was always the bootstrap... oops!
anewton1998 Dec 2, 2024
0ebdaff
added INR backup bootstrap and made the TLD lookup follow the same pa…
anewton1998 Dec 2, 2024
1bf8df6
Merge pull request #90 from icann/andy_dev
anewton1998 Dec 3, 2024
82e33f5
bumping to 0.0.19
anewton1998 Dec 3, 2024
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
1,356 changes: 700 additions & 656 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions 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.18"
version = "0.0.19"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/icann/icann-rdap"
Expand Down Expand Up @@ -81,6 +81,10 @@ http = "1.0"
# hyper (http implementation used by axum)
hyper = { version = "1.0", features = ["full"] }

# JSONPath
jsonpath-rust = "=0.5.0"
jsonpath_lib = "0.3.0"

# internationalized domain names for applications
idna = "0.5"

Expand Down Expand Up @@ -122,7 +126,7 @@ strum = "0.24"
strum_macros = "0.24"

# terminal markdown generator
termimad = "0.26"
termimad = "0.31"

# error macros
thiserror = "1.0"
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.18", path = "../icann-rdap-client" }
icann-rdap-common = { version = "0.0.18", path = "../icann-rdap-common" }
icann-rdap-client = { version = "0.0.19", path = "../icann-rdap-client" }
icann-rdap-common = { version = "0.0.19", path = "../icann-rdap-common" }

anyhow.workspace = true
clap.workspace = true
Expand Down
83 changes: 71 additions & 12 deletions icann-rdap-cli/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,33 @@ use icann_rdap_client::query::{
qtype::QueryType,
};
use icann_rdap_common::{
cache::HttpData,
httpdata::HttpData,
iana::{BootstrapRegistry, IanaRegistry, IanaRegistryType},
};
use reqwest::Client;
use tracing::debug;

use crate::{dirs::bootstrap_cache_path, error::CliError};

/// Defines the type of bootstrapping to use.
pub(crate) enum BootstrapType {
None,
/// Use RFC 9224 bootstrapping.
///
/// This is the typical bootstrapping for RDAP as defined by RFC 9224.
Rfc9224,

/// Use the supplied URL.
///
/// Essentially, this means no bootstrapping as the client is being given
/// a full URL.
Url(String),
Tag(String),

/// Use a hint.
///
/// This will try to find an authoritative server by cycling through the various
/// bootstrap registries in the following order: object tags, TLDs, IP addresses,
/// ASNs.
Hint(String),
}

pub(crate) async fn get_base_url(
Expand All @@ -40,17 +55,61 @@ pub(crate) async fn get_base_url(
let store = FileCacheBootstrapStore;

match bootstrap_type {
BootstrapType::None => Ok(qtype_to_bootstrap_url(client, &store, query_type, |reg| {
BootstrapType::Rfc9224 => Ok(qtype_to_bootstrap_url(client, &store, query_type, |reg| {
debug!("Fetching IANA registry {}", reg.url())
})
.await?),
BootstrapType::Url(url) => Ok(url.to_owned()),
BootstrapType::Tag(tag) => {
BootstrapType::Hint(hint) => {
fetch_bootstrap(&IanaRegistryType::RdapObjectTags, client, &store, |_reg| {
debug!("Fetching IANA RDAP Object Tag Registry")
})
.await?;
Ok(store.get_tag_urls(tag)?.preferred_url()?)
if let Ok(urls) = store.get_tag_urls(hint) {
Ok(urls.preferred_url()?)
} else {
fetch_bootstrap(
&IanaRegistryType::RdapBootstrapDns,
client,
&store,
|_reg| debug!("Fetching IANA RDAP DNS Registry"),
)
.await?;
if let Ok(urls) = store.get_dns_urls(hint) {
Ok(urls.preferred_url()?)
} else {
fetch_bootstrap(
&IanaRegistryType::RdapBootstrapIpv4,
client,
&store,
|_reg| debug!("Fetching IANA RDAP IPv4 Registry"),
)
.await?;
if let Ok(urls) = store.get_ipv4_urls(hint) {
Ok(urls.preferred_url()?)
} else {
fetch_bootstrap(
&IanaRegistryType::RdapBootstrapIpv6,
client,
&store,
|_reg| debug!("Fetching IANA RDAP IPv6 Registry"),
)
.await?;
if let Ok(urls) = store.get_ipv6_urls(hint) {
Ok(urls.preferred_url()?)
} else {
fetch_bootstrap(
&IanaRegistryType::RdapBootstrapAsn,
client,
&store,
|_reg| debug!("Fetching IANA RDAP ASN Registry"),
)
.await?;
Ok(store.get_asn_urls(hint)?.preferred_url()?)
}
}
}
}
}
}
}
Expand Down Expand Up @@ -138,7 +197,7 @@ where
mod test {
use icann_rdap_client::query::{bootstrap::PreferredUrl, qtype::QueryType};
use icann_rdap_common::{
cache::HttpData,
httpdata::HttpData,
iana::{IanaRegistry, IanaRegistryType},
};
use serial_test::serial;
Expand Down Expand Up @@ -190,7 +249,7 @@ mod test {
bs.put_bootstrap_registry(
&IanaRegistryType::RdapBootstrapDns,
iana,
HttpData::now().host("example.com").build(),
HttpData::example().build(),
)
.expect("put iana registry");

Expand Down Expand Up @@ -244,7 +303,7 @@ mod test {
bs.put_bootstrap_registry(
&IanaRegistryType::RdapBootstrapAsn,
iana,
HttpData::now().host("example.com").build(),
HttpData::example().build(),
)
.expect("put iana registry");

Expand Down Expand Up @@ -298,7 +357,7 @@ mod test {
bs.put_bootstrap_registry(
&IanaRegistryType::RdapBootstrapIpv4,
iana,
HttpData::now().host("example.com").build(),
HttpData::example().build(),
)
.expect("put iana registry");

Expand Down Expand Up @@ -352,7 +411,7 @@ mod test {
bs.put_bootstrap_registry(
&IanaRegistryType::RdapBootstrapIpv6,
iana,
HttpData::now().host("example.com").build(),
HttpData::example().build(),
)
.expect("put iana registry");

Expand Down Expand Up @@ -409,7 +468,7 @@ mod test {
bs.put_bootstrap_registry(
&IanaRegistryType::RdapObjectTags,
iana,
HttpData::now().host("example.com").build(),
HttpData::example().build(),
)
.expect("put iana registry");

Expand Down
38 changes: 38 additions & 0 deletions icann-rdap-cli/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use std::process::{ExitCode, Termination};

use icann_rdap_client::RdapClientError;
use icann_rdap_common::iana::IanaResponseError;
use minus::MinusError;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum CliError {
#[error("No errors encountered")]
Success,
#[error(transparent)]
RdapClient(#[from] RdapClientError),
#[error(transparent)]
Expand All @@ -25,4 +29,38 @@ pub enum CliError {
InvalidBootstrap,
#[error("Bootstrap not found")]
BootstrapNotFound,
#[error("No registrar found")]
NoRegistrarFound,
#[error("No registry found")]
NoRegistryFound,
}

impl Termination for CliError {
fn report(self) -> std::process::ExitCode {
let exit_code: u8 = match self {
// Success
CliError::Success => 0,

// Internal Errors
CliError::Termimad(_) => 10,
CliError::Minus(_) => 11,

// I/O Errors
CliError::IoError(_) => 40,
CliError::RdapClient(_) => 41,

// RDAP Errors
CliError::Json(_) => 100,
CliError::Iana(_) => 101,
CliError::InvalidBootstrap => 102,
CliError::BootstrapNotFound => 103,
CliError::NoRegistrarFound => 104,
CliError::NoRegistryFound => 105,

// User Errors
CliError::UnknownOutputType => 200,
CliError::ErrorOnChecks => 201,
};
ExitCode::from(exit_code)
}
}
Loading
Loading