|
1 | 1 | use bootstrap::BootstrapType;
|
2 | 2 | use clap::builder::styling::AnsiColor;
|
3 | 3 | use clap::builder::Styles;
|
4 |
| -use icann_rdap_common::check::string::StringCheck; |
5 | 4 | use icann_rdap_common::check::CheckClass;
|
6 | 5 | use icann_rdap_common::client::create_client;
|
7 | 6 | use icann_rdap_common::client::ClientConfig;
|
| 7 | +use query::InrBackupBootstrap; |
8 | 8 | use query::ProcessType;
|
9 | 9 | use query::ProcessingParams;
|
| 10 | +use query::TldLookup; |
10 | 11 | use std::io::IsTerminal;
|
11 | 12 | use std::str::FromStr;
|
12 | 13 | use tracing::error;
|
@@ -110,17 +111,30 @@ struct Cli {
|
110 | 111 | #[arg(short = 'B', long, required = false, env = "RDAP_BASE_URL")]
|
111 | 112 | base_url: Option<String>,
|
112 | 113 |
|
113 |
| - /// Default to IANA for TLD lookups. |
| 114 | + /// Specify where to send TLD queries. |
114 | 115 | ///
|
115 |
| - /// When querying for TLDs, use IANA as the authoritative server. |
| 116 | + /// Defaults to IANA. |
116 | 117 | #[arg(
|
117 | 118 | long,
|
118 | 119 | required = false,
|
119 | 120 | env = "RDAP_TLD_LOOKUP",
|
120 | 121 | value_enum,
|
121 |
| - default_value_t = TldLookup::Iana, |
| 122 | + default_value_t = TldLookupArg::Iana, |
122 | 123 | )]
|
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, |
124 | 138 |
|
125 | 139 | /// Output format.
|
126 | 140 | ///
|
@@ -388,14 +402,23 @@ enum PagerType {
|
388 | 402 | }
|
389 | 403 |
|
390 | 404 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
|
391 |
| -enum TldLookup { |
| 405 | +enum TldLookupArg { |
392 | 406 | /// Use IANA for TLD lookups.
|
393 | 407 | Iana,
|
394 | 408 |
|
395 | 409 | /// No TLD specific lookups.
|
396 | 410 | None,
|
397 | 411 | }
|
398 | 412 |
|
| 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 | + |
399 | 422 | impl From<&LogLevel> for LevelFilter {
|
400 | 423 | fn from(log_level: &LogLevel) -> Self {
|
401 | 424 | match log_level {
|
@@ -431,24 +454,7 @@ pub async fn wrapped_main() -> Result<(), CliError> {
|
431 | 454 |
|
432 | 455 | let level = LevelFilter::from(&cli.log_level);
|
433 | 456 |
|
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); |
452 | 458 |
|
453 | 459 | let use_pager = match cli.page_output {
|
454 | 460 | PagerType::Embedded => true,
|
@@ -499,11 +505,31 @@ pub async fn wrapped_main() -> Result<(), CliError> {
|
499 | 505 | .collect::<Vec<CheckClass>>()
|
500 | 506 | };
|
501 | 507 |
|
| 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 | + |
502 | 526 | let processing_params = ProcessingParams {
|
503 | 527 | bootstrap_type,
|
504 | 528 | output_type,
|
505 | 529 | check_types,
|
506 | 530 | process_type,
|
| 531 | + tld_lookup, |
| 532 | + inr_backup_bootstrap, |
507 | 533 | error_on_checks: cli.error_on_checks,
|
508 | 534 | no_cache: cli.no_cache,
|
509 | 535 | max_cache_age: cli.max_cache_age,
|
|
0 commit comments