| 1 |
//! Nameserver search results filter implementation. |
| 2 |
//! |
| 3 |
//! Extracts fields from [`crate::response::NameserverSearchResults`] RDAP objects. |
| 4 |
//! Values are aggregated across all search results into arrays. |
| 5 |
//! |
| 6 |
//! # Supported Filters |
| 7 |
//! |
| 8 |
//! | Filter | Value Type | Description | |
| 9 |
//! |---|---|---| |
| 10 |
//! | `Handle` | `StringArray` | Handles from all results | |
| 11 |
//! | `Status` | `StringArray` | Statuses from all results | |
| 12 |
//! | `ObjectClassName` | `StringArray` | Object class names from all results | |
| 13 |
//! | `Event` | `HashMapVal` | Events aggregated from all results | |
| 14 |
//! | `RdapConformance` | `StringArray` | Conformance URIs from all results | |
| 15 |
//! | `IpAddress` | `StringArray` | IP addresses from all results | |
| 16 |
//! | Entity roles | `StringArray` | Role-based fields aggregated from all results | |
| 17 |
|
| 18 |
use super::*; |
| 19 |
use crate::response::{CommonFields, NameserverSearchResults, ObjectCommonFields}; |
| 20 |
|
| 21 |
impl Filterable for NameserverSearchResults { |
| 22 |
fn filter(&self, filters: &[Filter]) -> FilterResult { |
| 23 |
filters |
| 24 |
.iter() |
| 25 |
.map(|f| match f { |
| 26 |
Filter::Handle => FilterOutput { |
| 27 |
filter: *f, |
| 28 |
value: FilterValue::StringArray( |
| 29 |
self.results() |
| 30 |
.iter() |
| 31 |
.filter_map(|n| n.handle()) |
| 32 |
.map(|h| h.to_string()) |
| 33 |
.collect(), |
| 34 |
), |
| 35 |
}, |
| 36 |
Filter::Status => FilterOutput { |
| 37 |
filter: *f, |
| 38 |
value: FilterValue::StringArray( |
| 39 |
self.results() |
| 40 |
.iter() |
| 41 |
.flat_map(|n| n.status()) |
| 42 |
.map(|s| s.to_string()) |
| 43 |
.collect(), |
| 44 |
), |
| 45 |
}, |
| 46 |
Filter::ObjectClassName => FilterOutput { |
| 47 |
filter: *f, |
| 48 |
value: FilterValue::StringArray( |
| 49 |
self.results() |
| 50 |
.iter() |
| 51 |
.map(|n| n.object_class_name().to_string()) |
| 52 |
.collect(), |
| 53 |
), |
| 54 |
}, |
| 55 |
Filter::Event => FilterOutput { |
| 56 |
filter: *f, |
| 57 |
value: FilterValue::HashMapVal( |
| 58 |
self.results() |
| 59 |
.iter() |
| 60 |
.flat_map(|n| n.events()) |
| 61 |
.filter_map(|e| { |
| 62 |
let action = e.event_action()?; |
| 63 |
let date = e.event_date()?; |
| 64 |
Some((action.to_string(), FilterValue::StringVal(date.to_string()))) |
| 65 |
}) |
| 66 |
.collect(), |
| 67 |
), |
| 68 |
}, |
| 69 |
Filter::RdapConformance => FilterOutput { |
| 70 |
filter: *f, |
| 71 |
value: FilterValue::StringArray( |
| 72 |
self.results() |
| 73 |
.iter() |
| 74 |
.filter_map(|n| n.common().rdap_conformance.as_ref()) |
| 75 |
.flatten() |
| 76 |
.map(|ext| ext.0.clone()) |
| 77 |
.collect(), |
| 78 |
), |
| 79 |
}, |
| 80 |
Filter::IpAddress => FilterOutput { |
| 81 |
filter: *f, |
| 82 |
value: FilterValue::StringArray( |
| 83 |
self.results() |
| 84 |
.iter() |
| 85 |
.flat_map(|n| n.ip_addresses()) |
| 86 |
.flat_map(|ip| ip.v4s()) |
| 87 |
.chain( |
| 88 |
self.results() |
| 89 |
.iter() |
| 90 |
.flat_map(|n| n.ip_addresses()) |
| 91 |
.flat_map(|ip| ip.v6s()), |
| 92 |
) |
| 93 |
.map(|ip| ip.to_string()) |
| 94 |
.collect(), |
| 95 |
), |
| 96 |
}, |
| 97 |
_ => entity_role_filter_output_search(self.results().iter(), *f), |
| 98 |
}) |
| 99 |
.collect() |
| 100 |
} |
| 101 |
} |