Skip to content

Commit 0ebdaff

Browse files
committed
added INR backup bootstrap and made the TLD lookup follow the same pattern
1 parent 709cc60 commit 0ebdaff

File tree

4 files changed

+106
-31
lines changed

4 files changed

+106
-31
lines changed

icann-rdap-cli/src/bootstrap.rs

-4
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ pub(crate) enum BootstrapType {
3939
/// bootstrap registries in the following order: object tags, TLDs, IP addresses,
4040
/// ASNs.
4141
Hint(String),
42-
43-
/// Use IANA.
44-
Iana,
4542
}
4643

4744
pub(crate) async fn get_base_url(
@@ -114,7 +111,6 @@ pub(crate) async fn get_base_url(
114111
}
115112
}
116113
}
117-
BootstrapType::Iana => Ok("https://rdap.iana.org".to_string()),
118114
}
119115
}
120116

icann-rdap-cli/src/main.rs

+50-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use bootstrap::BootstrapType;
22
use clap::builder::styling::AnsiColor;
33
use clap::builder::Styles;
4-
use icann_rdap_common::check::string::StringCheck;
54
use icann_rdap_common::check::CheckClass;
65
use icann_rdap_common::client::create_client;
76
use icann_rdap_common::client::ClientConfig;
7+
use query::InrBackupBootstrap;
88
use query::ProcessType;
99
use query::ProcessingParams;
10+
use query::TldLookup;
1011
use std::io::IsTerminal;
1112
use std::str::FromStr;
1213
use tracing::error;
@@ -110,17 +111,30 @@ struct Cli {
110111
#[arg(short = 'B', long, required = false, env = "RDAP_BASE_URL")]
111112
base_url: Option<String>,
112113

113-
/// Default to IANA for TLD lookups.
114+
/// Specify where to send TLD queries.
114115
///
115-
/// When querying for TLDs, use IANA as the authoritative server.
116+
/// Defaults to IANA.
116117
#[arg(
117118
long,
118119
required = false,
119120
env = "RDAP_TLD_LOOKUP",
120121
value_enum,
121-
default_value_t = TldLookup::Iana,
122+
default_value_t = TldLookupArg::Iana,
122123
)]
123-
tld_lookup: TldLookup,
124+
tld_lookup: TldLookupArg,
125+
126+
/// Specify a backup INR bootstrap.
127+
///
128+
/// This is used as a backup when the bootstrapping process cannot find an authoritative
129+
/// server for IP addresses and Autonomous System Numbers. Defaults to ARIN.
130+
#[arg(
131+
long,
132+
required = false,
133+
env = "RDAP_INR_BACKUP_BOOTSTRAP",
134+
value_enum,
135+
default_value_t = InrBackupBootstrapArg::Arin,
136+
)]
137+
inr_backup_bootstrap: InrBackupBootstrapArg,
124138

125139
/// Output format.
126140
///
@@ -388,14 +402,23 @@ enum PagerType {
388402
}
389403

390404
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
391-
enum TldLookup {
405+
enum TldLookupArg {
392406
/// Use IANA for TLD lookups.
393407
Iana,
394408

395409
/// No TLD specific lookups.
396410
None,
397411
}
398412

413+
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
414+
enum InrBackupBootstrapArg {
415+
/// Use ARIN when no INR bootstrap can be found.
416+
Arin,
417+
418+
/// No backup for INR bootstraps.
419+
None,
420+
}
421+
399422
impl From<&LogLevel> for LevelFilter {
400423
fn from(log_level: &LogLevel) -> Self {
401424
match log_level {
@@ -431,24 +454,7 @@ pub async fn wrapped_main() -> Result<(), CliError> {
431454

432455
let level = LevelFilter::from(&cli.log_level);
433456

434-
let mut bootstrap_type = if let Some(ref tag) = cli.base {
435-
BootstrapType::Hint(tag.to_string())
436-
} else if let Some(ref base_url) = cli.base_url {
437-
BootstrapType::Url(base_url.to_string())
438-
} else {
439-
BootstrapType::Rfc9224
440-
};
441-
442-
let mut query_type = query_type_from_cli(&cli);
443-
// if using IANA for tld queries, adjust the domain name to not start with '.'
444-
if let TldLookup::Iana = cli.tld_lookup {
445-
if let QueryType::Domain(ref domain) = query_type {
446-
if domain.is_tld() {
447-
query_type = QueryType::Domain(domain.trim_start_matches('.').to_string());
448-
bootstrap_type = BootstrapType::Iana;
449-
}
450-
}
451-
}
457+
let query_type = query_type_from_cli(&cli);
452458

453459
let use_pager = match cli.page_output {
454460
PagerType::Embedded => true,
@@ -499,11 +505,31 @@ pub async fn wrapped_main() -> Result<(), CliError> {
499505
.collect::<Vec<CheckClass>>()
500506
};
501507

508+
let bootstrap_type = if let Some(ref tag) = cli.base {
509+
BootstrapType::Hint(tag.to_string())
510+
} else if let Some(ref base_url) = cli.base_url {
511+
BootstrapType::Url(base_url.to_string())
512+
} else {
513+
BootstrapType::Rfc9224
514+
};
515+
516+
let tld_lookup = match cli.tld_lookup {
517+
TldLookupArg::Iana => TldLookup::Iana,
518+
TldLookupArg::None => TldLookup::None,
519+
};
520+
521+
let inr_backup_bootstrap = match cli.inr_backup_bootstrap {
522+
InrBackupBootstrapArg::Arin => InrBackupBootstrap::Arin,
523+
InrBackupBootstrapArg::None => InrBackupBootstrap::None,
524+
};
525+
502526
let processing_params = ProcessingParams {
503527
bootstrap_type,
504528
output_type,
505529
check_types,
506530
process_type,
531+
tld_lookup,
532+
inr_backup_bootstrap,
507533
error_on_checks: cli.error_on_checks,
508534
no_cache: cli.no_cache,
509535
max_cache_age: cli.max_cache_age,

icann-rdap-cli/src/query.rs

+53-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use icann_rdap_common::check::string::StringCheck;
12
use icann_rdap_common::check::traverse_checks;
23
use icann_rdap_common::check::CheckClass;
34
use icann_rdap_common::check::CheckParams;
@@ -55,11 +56,33 @@ pub(crate) enum ProcessType {
5556
Registry,
5657
}
5758

59+
/// Used for doing TLD Lookups.
60+
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
61+
pub(crate) enum TldLookup {
62+
/// Use IANA for TLD lookups.
63+
Iana,
64+
65+
/// No TLD specific lookups.
66+
None,
67+
}
68+
69+
/// Used for doing TLD Lookups.
70+
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
71+
pub(crate) enum InrBackupBootstrap {
72+
/// Use ARIN if no bootstraps can be found for INR queries.
73+
Arin,
74+
75+
/// No INR bootstrap backup.
76+
None,
77+
}
78+
5879
pub(crate) struct ProcessingParams {
5980
pub bootstrap_type: BootstrapType,
6081
pub output_type: OutputType,
6182
pub check_types: Vec<CheckClass>,
6283
pub process_type: ProcessType,
84+
pub tld_lookup: TldLookup,
85+
pub inr_backup_bootstrap: InrBackupBootstrap,
6386
pub error_on_checks: bool,
6487
pub no_cache: bool,
6588
pub max_cache_age: u32,
@@ -93,7 +116,26 @@ async fn do_domain_query<'a, W: std::io::Write>(
93116
write: &mut W,
94117
) -> Result<(), CliError> {
95118
let mut transactions = RequestResponses::new();
96-
let base_url = get_base_url(&processing_params.bootstrap_type, client, query_type).await?;
119+
120+
// special processing for TLD Lookups
121+
let temp_query_type;
122+
let (base_url, query_type) = if let QueryType::Domain(ref domain) = query_type {
123+
if domain.is_tld() && matches!(processing_params.tld_lookup, TldLookup::Iana) {
124+
temp_query_type = QueryType::Domain(domain.trim_start_matches('.').to_string());
125+
("https://rdap.iana.org".to_string(), &temp_query_type)
126+
} else {
127+
(
128+
get_base_url(&processing_params.bootstrap_type, client, query_type).await?,
129+
query_type,
130+
)
131+
}
132+
} else {
133+
(
134+
get_base_url(&processing_params.bootstrap_type, client, query_type).await?,
135+
query_type,
136+
)
137+
};
138+
97139
let response = do_request(&base_url, query_type, processing_params, client).await;
98140
let registrar_response;
99141
match response {
@@ -183,8 +225,16 @@ async fn do_inr_query<'a, W: std::io::Write>(
183225
write: &mut W,
184226
) -> Result<(), CliError> {
185227
let mut transactions = RequestResponses::new();
186-
let base_url = get_base_url(&processing_params.bootstrap_type, client, query_type).await?;
187-
let response = do_request(&base_url, query_type, processing_params, client).await;
228+
let mut base_url = get_base_url(&processing_params.bootstrap_type, client, query_type).await;
229+
if base_url.is_err()
230+
&& matches!(
231+
processing_params.inr_backup_bootstrap,
232+
InrBackupBootstrap::Arin
233+
)
234+
{
235+
base_url = Ok("https://rdap.arin.net/registry".to_string());
236+
};
237+
let response = do_request(&base_url?, query_type, processing_params, client).await;
188238
match response {
189239
Ok(response) => {
190240
let source_host = response.http_data.host.to_owned();

icann-rdap-cli/src/rdap.env

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
# Where to lookup TLDs
2222
#RDAP_TLD_LOOKUP=iana
2323

24+
# Which base URL to use if no IP address or autnum bootstrap can be found.
25+
#RDAP_INR_BACKUP_BOOTSTRAP=arin
26+
2427
# Do not use cache.
2528
#RDAP_NO_CACHE=true
2629

0 commit comments

Comments
 (0)