Skip to content

Commit

Permalink
Merge pull request #76 from icann/andy_dev
Browse files Browse the repository at this point in the history
Andy dev
  • Loading branch information
anewton1998 authored Aug 31, 2024
2 parents 047e63c + d947136 commit 32f3084
Show file tree
Hide file tree
Showing 23 changed files with 788 additions and 23 deletions.
62 changes: 62 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ keywords = ["whois", "rdap"]

[workspace.dependencies]

# for suffix string searchs
ab-radix-trie = "0.2.1"

# easy error handling
anyhow = "1.0"

Expand Down
18 changes: 18 additions & 0 deletions icann-rdap-cli/tests/integration/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,21 @@ async fn GIVEN_idn_WHEN_query_a_label_THEN_success() {
let assert = test_jig.cmd.assert();
assert.success();
}

#[tokio::test(flavor = "multi_thread")]
async fn GIVEN_domain_WHEN_search_domain_names_THEN_success() {
// GIVEN
let mut test_jig = TestJig::new_with_enable_domain_name_search().await;
let mut tx = test_jig.mem.new_tx().await.expect("new transaction");
tx.add_domain(&Domain::basic().ldh_name("foo.example").build())
.await
.expect("add domain in tx");
tx.commit().await.expect("tx commit");

// WHEN
test_jig.cmd.arg("-t").arg("domain-name").arg("foo.*");

// THEN
let assert = test_jig.cmd.assert();
assert.success();
}
16 changes: 15 additions & 1 deletion icann-rdap-cli/tests/integration/test_jig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use assert_cmd::Command;
use icann_rdap_srv::config::ListenConfig;
use icann_rdap_srv::server::AppState;
use icann_rdap_srv::server::Listener;
use icann_rdap_srv::storage::mem::config::MemConfig;
use icann_rdap_srv::storage::mem::ops::Mem;
use icann_rdap_srv::storage::CommonConfig;
use std::time::Duration;
use test_dir::DirBuilder;
use test_dir::FileType;
Expand All @@ -18,7 +20,19 @@ pub struct TestJig {

impl TestJig {
pub async fn new() -> TestJig {
let mem = Mem::default();
let common_config = CommonConfig::default();
TestJig::new_common_config(common_config).await
}

pub async fn new_with_enable_domain_name_search() -> TestJig {
let common_config = CommonConfig::builder()
.domain_search_by_name_enable(true)
.build();
TestJig::new_common_config(common_config).await
}

pub async fn new_common_config(common_config: CommonConfig) -> TestJig {
let mem = Mem::new(MemConfig::builder().common_config(common_config).build());
let app_state = AppState {
storage: mem.clone(),
bootstrap: false,
Expand Down
1 change: 1 addition & 0 deletions icann-rdap-srv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ An RDAP Server.
icann-rdap-client = { version = "0.0.17", path = "../icann-rdap-client" }
icann-rdap-common = { version = "0.0.17", path = "../icann-rdap-common" }

ab-radix-trie.workspace = true
async-trait.workspace = true
axum.workspace = true
axum-extra.workspace = true
Expand Down
7 changes: 6 additions & 1 deletion icann-rdap-srv/src/bin/rdap-srv-data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use icann_rdap_srv::storage::data::NetworkOrError;
use icann_rdap_srv::storage::data::Template;
use icann_rdap_srv::storage::mem::config::MemConfig;
use icann_rdap_srv::storage::mem::ops::Mem;
use icann_rdap_srv::storage::CommonConfig;
use icann_rdap_srv::storage::StoreOps;
use icann_rdap_srv::util::bin::check::check_rdap;
use icann_rdap_srv::util::bin::check::to_check_classes;
Expand Down Expand Up @@ -524,7 +525,11 @@ async fn main() -> Result<(), RdapServerError> {

let data_dir = cli.data_dir.clone();
let config = ServiceConfig::non_server().data_dir(&data_dir).build()?;
let storage = Mem::new(MemConfig::builder().build());
let storage = Mem::new(
MemConfig::builder()
.common_config(CommonConfig::default())
.build(),
);
storage.init().await?;
load_data(&config, &storage, false).await?;

Expand Down
6 changes: 4 additions & 2 deletions icann-rdap-srv/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ mod tests {
storage::{
data::load_data,
mem::{config::MemConfig, ops::Mem},
StoreOps,
CommonConfig, StoreOps,
},
};

Expand Down Expand Up @@ -618,7 +618,9 @@ mod tests {
}

async fn new_and_init_mem(data_dir: String) -> Mem {
let mem_config = MemConfig::builder().build();
let mem_config = MemConfig::builder()
.common_config(CommonConfig::default())
.build();
let mem = Mem::new(mem_config.clone());
mem.init().await.expect("initialzing memeory");
load_data(
Expand Down
19 changes: 15 additions & 4 deletions icann-rdap-srv/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use buildstructor::Builder;
use envmnt::get_or;
use envmnt::{get_or, get_parse_or};
use strum_macros::Display;
use tracing::debug;

use crate::{
error::RdapServerError,
storage::{mem::config::MemConfig, pg::config::PgConfig},
storage::{mem::config::MemConfig, pg::config::PgConfig, CommonConfig},
};

pub const LOG: &str = "RDAP_SRV_LOG";
Expand All @@ -17,6 +17,7 @@ pub const DATA_DIR: &str = "RDAP_SRV_DATA_DIR";
pub const AUTO_RELOAD: &str = "RDAP_SRV_AUTO_RELOAD";
pub const BOOTSTRAP: &str = "RDAP_SRV_BOOTSTRAP";
pub const UPDATE_ON_BOOTSTRAP: &str = "RDAP_SRV_UPDATE_ON_BOOTSTRAP";
pub const DOMAIN_SEARCH_BY_NAME_ENABLE: &str = "RDAP_SRV_DOMAIN_SEARCH_BY_NAME";

pub fn debug_config_vars() {
let var_list = [
Expand All @@ -29,6 +30,7 @@ pub fn debug_config_vars() {
AUTO_RELOAD,
BOOTSTRAP,
UPDATE_ON_BOOTSTRAP,
DOMAIN_SEARCH_BY_NAME_ENABLE,
];
envmnt::vars()
.iter()
Expand Down Expand Up @@ -65,12 +67,21 @@ pub enum StorageType {

impl StorageType {
pub fn new_from_env() -> Result<Self, RdapServerError> {
let domain_search_by_name = get_parse_or(DOMAIN_SEARCH_BY_NAME_ENABLE, false)?;
let common_config = CommonConfig::builder()
.domain_search_by_name_enable(domain_search_by_name)
.build();
let storage = get_or(STORAGE, "memory");
let storage_type = if storage == "memory" {
StorageType::Memory(MemConfig::builder().build())
StorageType::Memory(MemConfig::builder().common_config(common_config).build())
} else if storage == "postgres" {
let db_url = get_or(DB_URL, "postgresql://127.0.0.1/rdap");
StorageType::Postgres(PgConfig::builder().db_url(db_url).build())
StorageType::Postgres(
PgConfig::builder()
.db_url(db_url)
.common_config(common_config)
.build(),
)
} else {
return Err(RdapServerError::Config(format!(
"storage type of '{storage}' is invalid"
Expand Down
36 changes: 36 additions & 0 deletions icann-rdap-srv/src/rdap/domains.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use axum::{
extract::{Query, State},
response::Response,
};

use serde::Deserialize;

use crate::{error::RdapServerError, rdap::response::ResponseUtil, server::DynServiceState};

use super::response::NOT_IMPLEMENTED;

#[derive(Debug, Deserialize)]
pub(crate) struct DomainsParams {
name: Option<String>,

#[serde(rename = "nsLdhName")]
_ns_ldh_name: Option<String>,

#[serde(rename = "nsIp")]
_ns_ip: Option<String>,
}

#[axum_macros::debug_handler]
#[tracing::instrument(level = "debug")]
pub(crate) async fn domains(
Query(params): Query<DomainsParams>,
state: State<DynServiceState>,
) -> Result<Response, RdapServerError> {
if let Some(name) = params.name {
let storage = state.get_storage().await?;
let results = storage.search_domains_by_name(&name).await?;
Ok(results.response())
} else {
Ok(NOT_IMPLEMENTED.response())
}
}
1 change: 1 addition & 0 deletions icann-rdap-srv/src/rdap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use icann_rdap_common::response::{error::Error, RdapResponse};

pub mod autnum;
pub mod domain;
pub mod domains;
pub mod entity;
pub mod ip;
pub mod nameserver;
Expand Down
3 changes: 2 additions & 1 deletion icann-rdap-srv/src/rdap/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use axum::{response::IntoResponse, routing::get, Router};
use super::{
autnum::autnum_by_num,
domain::domain_by_name,
domains::domains,
entity::entity_by_handle,
ip::network_by_netid,
nameserver::nameserver_by_name,
Expand All @@ -17,7 +18,7 @@ pub(crate) fn rdap_router() -> Router<crate::server::DynServiceState> {
.route("/autnum/:asnumber", get(autnum_by_num))
.route("/nameserver/:name", get(nameserver_by_name))
.route("/entity/:handle", get(entity_by_handle))
.route("/domains", get(not_implemented))
.route("/domains", get(domains))
.route("/nameservers", get(not_implemented))
.route("/entities", get(not_implemented))
.route("/help", get(srvhelp))
Expand Down
6 changes: 5 additions & 1 deletion icann-rdap-srv/src/storage/mem/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use buildstructor::Builder;

use crate::storage::CommonConfig;

#[derive(Debug, Builder, Clone)]
pub struct MemConfig {}
pub struct MemConfig {
pub common_config: CommonConfig,
}
Loading

0 comments on commit 32f3084

Please sign in to comment.