Added hosts endpoint group
This commit is contained in:
parent
3af55e3a87
commit
d9c2b0f698
|
@ -99,7 +99,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||
|
||||
[[package]]
|
||||
name = "construct"
|
||||
version = "1.6.0"
|
||||
version = "1.13.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"construct-models",
|
||||
|
@ -109,7 +109,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "construct-models"
|
||||
version = "1.6.0"
|
||||
version = "1.13.0"
|
||||
dependencies = [
|
||||
"reqwest",
|
||||
"serde",
|
||||
|
|
|
@ -10,8 +10,5 @@ Construct is a Censys API wrapper made in Rust
|
|||
cargo run --example basic
|
||||
```
|
||||
|
||||
## Todo
|
||||
- [ ] Add authentication
|
||||
|
||||
## Disclaimer
|
||||
###### Developers are not responsible for any misuse
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "construct-models"
|
||||
version = "1.6.0"
|
||||
version = "1.13.0"
|
||||
edition = "2021"
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "construct"
|
||||
version = "1.6.0"
|
||||
version = "1.13.0"
|
||||
edition = "2021"
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
use construct_models::hosts::Aggregate;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
impl Construct {
|
||||
/// Returns aggregation of hosts that match the given query string
|
||||
pub async fn fetch_hosts_aggregate(
|
||||
&self,
|
||||
query: &str,
|
||||
field: &str,
|
||||
num_buckets: i16,
|
||||
virtual_hosts: &str,
|
||||
) -> Result<Aggregate> {
|
||||
Ok(self
|
||||
.client
|
||||
.get(format!("{}/v2/hosts/aggregate", self.base_url))
|
||||
.basic_auth(&self.api_id, Some(&self.api_secret))
|
||||
.query(&[
|
||||
("q", query),
|
||||
("field", field),
|
||||
("num_buckets", &num_buckets.to_string()),
|
||||
("virtual_hosts", virtual_hosts),
|
||||
])
|
||||
.send()
|
||||
.await?
|
||||
.process_error()
|
||||
.await?
|
||||
.json()
|
||||
.await?)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
use construct_models::hosts::Certificates;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
impl Construct {
|
||||
/// Returns a list of observations containing certificates which were ever presented on this host.
|
||||
pub async fn fetch_hosts_certificates(
|
||||
&self,
|
||||
ip: &str,
|
||||
per_page: i16,
|
||||
start_time: &str,
|
||||
end_time: &str,
|
||||
cursor: &str,
|
||||
) -> Result<Certificates> {
|
||||
Ok(self
|
||||
.client
|
||||
.get(format!("{}/v2/hosts/{}/certificates", self.base_url, ip))
|
||||
.basic_auth(&self.api_id, Some(&self.api_secret))
|
||||
.query(&[
|
||||
("start_time", start_time),
|
||||
("end_time", end_time),
|
||||
("cursor", cursor),
|
||||
("per_page", &per_page.to_string()),
|
||||
])
|
||||
.send()
|
||||
.await?
|
||||
.process_error()
|
||||
.await?
|
||||
.json()
|
||||
.await?)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
use construct_models::hosts::Comments;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
impl Construct {
|
||||
/// Returns a list of comments on the given host.
|
||||
pub async fn fetch_hosts_comments(&self, ip: &str) -> Result<Comments> {
|
||||
Ok(self
|
||||
.client
|
||||
.get(format!("{}/v2/hosts/{}/comments", self.base_url, ip))
|
||||
.basic_auth(&self.api_id, Some(&self.api_secret))
|
||||
.send()
|
||||
.await?
|
||||
.process_error()
|
||||
.await?
|
||||
.json()
|
||||
.await?)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
use construct_models::hosts::Diff;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
impl Construct {
|
||||
/// Returns a diff of a host against different points in time or against a different host altogether.
|
||||
pub async fn fetch_hosts_diff(
|
||||
&self,
|
||||
ip: &str,
|
||||
ip_b: &str,
|
||||
at_time: &str,
|
||||
at_time_b: &str,
|
||||
) -> Result<Diff> {
|
||||
Ok(self
|
||||
.client
|
||||
.get(format!("{}/v2/hosts/{}/diff", self.base_url, ip))
|
||||
.basic_auth(&self.api_id, Some(&self.api_secret))
|
||||
.query(&[
|
||||
("ip_b", ip_b),
|
||||
("at_time", at_time),
|
||||
("at_time_b", at_time_b),
|
||||
])
|
||||
.send()
|
||||
.await?
|
||||
.process_error()
|
||||
.await?
|
||||
.json()
|
||||
.await?)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
use construct_models::hosts::Host;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
pub(crate) mod aggregate;
|
||||
pub(crate) mod certificates;
|
||||
pub(crate) mod comments;
|
||||
pub(crate) mod diff;
|
||||
pub(crate) mod names;
|
||||
pub(crate) mod search;
|
||||
|
||||
impl Construct {
|
||||
/// Returns host information for the specified IP address
|
||||
pub async fn fetch_hosts(&self, ip: &str, at_time: &str) -> Result<Host> {
|
||||
Ok(self
|
||||
.client
|
||||
.get(format!("{}/v2/hosts/{}", self.base_url, ip))
|
||||
.basic_auth(&self.api_id, Some(&self.api_secret))
|
||||
.query(&[("at_time", at_time)])
|
||||
.send()
|
||||
.await?
|
||||
.process_error()
|
||||
.await?
|
||||
.json()
|
||||
.await?)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
use construct_models::hosts::Names;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
impl Construct {
|
||||
/// Returns host names for the specified IP address
|
||||
pub async fn fetch_hosts_names(&self, ip: &str, per_page: i16, cursor: &str) -> Result<Names> {
|
||||
Ok(self
|
||||
.client
|
||||
.get(format!("{}/v2/hosts/{}/names", self.base_url, ip))
|
||||
.basic_auth(&self.api_id, Some(&self.api_secret))
|
||||
.query(&[("cursor", cursor), ("per_page", &per_page.to_string())])
|
||||
.send()
|
||||
.await?
|
||||
.process_error()
|
||||
.await?
|
||||
.json()
|
||||
.await?)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
use construct_models::hosts::Search;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
impl Construct {
|
||||
/// Returns previews of hosts matching a specified search query
|
||||
pub async fn search_hosts_(
|
||||
&self,
|
||||
query: &str,
|
||||
per_page: i16,
|
||||
virtual_hosts: &str,
|
||||
sort: &str,
|
||||
cursor: &str,
|
||||
fields: &str,
|
||||
) -> Result<Search> {
|
||||
Ok(self
|
||||
.client
|
||||
.get(format!("{}/v2/hosts/search", self.base_url))
|
||||
.basic_auth(&self.api_id, Some(&self.api_secret))
|
||||
.query(&[
|
||||
("q", query),
|
||||
("per_page", &per_page.to_string()),
|
||||
("virtual_hosts", virtual_hosts),
|
||||
("sort", sort),
|
||||
("cursor", cursor),
|
||||
("fields", fields),
|
||||
])
|
||||
.send()
|
||||
.await?
|
||||
.process_error()
|
||||
.await?
|
||||
.json()
|
||||
.await?)
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ use construct_models::Error;
|
|||
|
||||
mod account;
|
||||
mod data;
|
||||
mod hosts;
|
||||
mod metadata;
|
||||
|
||||
pub(crate) mod prelude {
|
||||
|
|
Loading…
Reference in New Issue