Skip to content

Commit

Permalink
Merge pull request #38 from icann/dev
Browse files Browse the repository at this point in the history
Upgrade to 0.0.14
  • Loading branch information
anewton1998 authored Nov 26, 2023
2 parents 1960f63 + 643cf59 commit 8b8478c
Show file tree
Hide file tree
Showing 40 changed files with 1,591 additions and 221 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/build-test-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: BuildTest

on:
push:
tags:
- 'bt_*'

jobs:
test-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check format
run: cargo fmt --check
- name: Build
run: cargo build --release --verbose
- name: Run tests
run: cargo test --verbose
- name: Install WASM32
run: rustup target add wasm32-unknown-unknown
- name: Check wasm32
run: cargo check --target wasm32-unknown-unknown -p icann-rdap-client

build:
name: Release build
needs: [test-build]
if: startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
OS: ubuntu-latest
- target: aarch64-unknown-linux-gnu
OS: ubuntu-latest
- target: x86_64-apple-darwin
OS: macos-latest
- target: aarch64-apple-darwin
OS: macos-latest
- target: x86_64-pc-windows-msvc
OS: windows-latest
runs-on: ${{ matrix.OS }}
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
target: ${{ matrix.target }}

- name: Build target
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --release --target ${{ matrix.target }}

2 changes: 1 addition & 1 deletion .github/workflows/release-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
shell: bash
run: |
cd target/${{ matrix.target }}/release
tar czvf ../../../icann-rdap-${{ matrix.target }}.tar.gz rdap
tar czvf ../../../icann-rdap-${{ matrix.target }}.tar.gz rdap rdap-srv rdap-srv-data rdap-srv-store rdap-srv-test-data
cd -
- name: Publish
uses: softprops/action-gh-release@v1
Expand Down
31 changes: 10 additions & 21 deletions Cargo.lock

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

7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ members = [
]

[workspace.package]
version = "0.0.13"
version = "0.0.14"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/icann/icann-rdap"
Expand Down Expand Up @@ -38,7 +38,7 @@ buildstructor = "0.5"
cidr-utils = "0.5"

# command line options parser
clap = { version = "4.0", features = [ "std", "derive", "env" ] }
clap = { version = "4.3.19", features = [ "std", "derive", "env", "unstable-styles" ] }

# chrono (time and date library)
chrono = { version = "0.4", features = ["alloc", "std", "clock", "serde"], default-features = false }
Expand Down Expand Up @@ -88,9 +88,6 @@ minus = {version = "5.4", features = ["dynamic_output", "search"] }
# percent encoding
pct-str = "1.2"

# eventually consistent shared data
pinboard = "2.2.0"

# ip address trie
prefix-trie = "0.2.4"

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.13", path = "../icann-rdap-client" }
icann-rdap-common = { version = "0.0.13", path = "../icann-rdap-common" }
icann-rdap-client = { version = "0.0.14", path = "../icann-rdap-client" }
icann-rdap-common = { version = "0.0.14", path = "../icann-rdap-common" }

anyhow.workspace = true
clap.workspace = true
Expand Down
8 changes: 6 additions & 2 deletions icann-rdap-cli/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ fn get_asn_bootstrap_urls(
iana: IanaRegistry,
query_type: &QueryType,
) -> Result<Vec<String>, CliError> {
let QueryType::AsNumber(asn) = query_type else {panic!("invalid query type")};
let QueryType::AsNumber(asn) = query_type else {
panic!("invalid query type")
};
let autnum = asn
.trim_start_matches(|c| -> bool { matches!(c, 'a' | 'A' | 's' | 'S') })
.parse::<u32>()
Expand Down Expand Up @@ -213,7 +215,9 @@ fn get_entity_handle_bootstrap_urls(
iana: IanaRegistry,
query_type: &QueryType,
) -> Result<Vec<String>, CliError> {
let QueryType::Entity(handle) = query_type else {panic!("non entity handle for bootstrap")};
let QueryType::Entity(handle) = query_type else {
panic!("non entity handle for bootstrap")
};
let handle_split = handle.rsplit_once('-').ok_or(CliError::BootstrapNotFound)?;
get_tag_bootstrap_urls(iana, handle_split.1)
}
Expand Down
16 changes: 15 additions & 1 deletion icann-rdap-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use bootstrap::BootstrapType;
use clap::builder::styling::AnsiColor;
use clap::builder::Styles;
use icann_rdap_common::check::CheckClass;
use icann_rdap_common::client::create_client;
use icann_rdap_common::client::ClientConfig;
Expand Down Expand Up @@ -33,8 +35,20 @@ pub mod write;
const BEFORE_LONG_HELP: &str = include_str!("before_long_help.txt");
const AFTER_LONG_HELP: &str = include_str!("after_long_help.txt");

struct CliStyles;

impl CliStyles {
fn cli_styles() -> Styles {
Styles::styled()
.header(AnsiColor::Yellow.on_default())
.usage(AnsiColor::Green.on_default())
.literal(AnsiColor::Green.on_default())
.placeholder(AnsiColor::Green.on_default())
}
}

#[derive(Parser, Debug)]
#[command(author, version = VERSION, about, long_about)]
#[command(author, version = VERSION, about, long_about, styles = CliStyles::cli_styles())]
#[command(group(
ArgGroup::new("input")
.required(true)
Expand Down
2 changes: 1 addition & 1 deletion icann-rdap-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ An RDAP client library.

[dependencies]

icann-rdap-common = { version = "0.0.13", path = "../icann-rdap-common" }
icann-rdap-common = { version = "0.0.14", path = "../icann-rdap-common" }

buildstructor.workspace = true
cidr-utils.workspace = true
Expand Down
8 changes: 6 additions & 2 deletions icann-rdap-common/src/check/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ impl GetChecks for Network {
if start_addr.is_err() {
items.push(CheckItem::malformed_ip_address())
} else if self.end_address.is_some() {
let Ok(start_addr) = start_addr else {panic!("ip result did not work")};
let Some(end_ip) = &self.end_address else {panic!("end address unwrap failed")};
let Ok(start_addr) = start_addr else {
panic!("ip result did not work")
};
let Some(end_ip) = &self.end_address else {
panic!("end address unwrap failed")
};
if let Ok(end_addr) = IpAddr::from_str(end_ip) {
if start_addr > end_addr {
items.push(CheckItem::end_ip_before_start_ip())
Expand Down
9 changes: 9 additions & 0 deletions icann-rdap-common/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub struct ClientConfig {

/// If true, HTTP redirects will be followed.
pub follow_redirects: bool,

/// Specify Host
pub host: Option<HeaderValue>,
}

impl Default for ClientConfig {
Expand All @@ -39,6 +42,7 @@ impl Default for ClientConfig {
accept_invalid_host_names: false,
accept_invalid_certificates: false,
follow_redirects: true,
host: None,
}
}
}
Expand All @@ -52,6 +56,7 @@ impl ClientConfig {
accept_invalid_host_names: Option<bool>,
accept_invalid_certificates: Option<bool>,
follow_redirects: Option<bool>,
host: Option<HeaderValue>,
) -> Self {
let default = ClientConfig::default();
Self {
Expand All @@ -62,6 +67,7 @@ impl ClientConfig {
accept_invalid_certificates: accept_invalid_certificates
.unwrap_or(default.accept_invalid_certificates),
follow_redirects: follow_redirects.unwrap_or(default.follow_redirects),
host,
}
}
}
Expand All @@ -78,6 +84,9 @@ pub fn create_client(config: &ClientConfig) -> Result<Client, reqwest::Error> {
header::ACCEPT,
HeaderValue::from_static(&ACCEPT_HEADER_VALUES),
);
if let Some(host) = &config.host {
default_headers.insert(header::HOST, host.into());
};

#[allow(unused_mut)]
let mut client = reqwest::Client::builder();
Expand Down
Loading

0 comments on commit 8b8478c

Please sign in to comment.