use kafka_client_core::{
DescribeAclsFilter as CoreFilter, DescribeAclsPlan as CorePlan,
DescribeAclsPlanError as CorePlanError,
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DescribeAclsFilter {
resource_type: i8,
resource_name: Option<String>,
pattern_type: i8,
principal: Option<String>,
host: Option<String>,
operation: i8,
permission_type: i8,
}
impl DescribeAclsFilter {
pub const fn new(
resource_type: i8,
resource_name: Option<String>,
pattern_type: i8,
principal: Option<String>,
host: Option<String>,
operation: i8,
permission_type: i8,
) -> Self {
Self {
resource_type,
resource_name,
pattern_type,
principal,
host,
operation,
permission_type,
}
}
pub const fn resource_type(&self) -> i8 {
self.resource_type
}
pub fn resource_name(&self) -> Option<&str> {
self.resource_name.as_deref()
}
pub const fn pattern_type(&self) -> i8 {
self.pattern_type
}
pub fn principal(&self) -> Option<&str> {
self.principal.as_deref()
}
pub fn host(&self) -> Option<&str> {
self.host.as_deref()
}
pub const fn operation(&self) -> i8 {
self.operation
}
pub const fn permission_type(&self) -> i8 {
self.permission_type
}
pub fn into_parts(
self,
) -> (
i8,
Option<String>,
i8,
Option<String>,
Option<String>,
i8,
i8,
) {
(
self.resource_type,
self.resource_name,
self.pattern_type,
self.principal,
self.host,
self.operation,
self.permission_type,
)
}
fn canonicalize(mut self) -> Self {
self.resource_name = self.resource_name.map(canonical_string);
self.principal = self.principal.map(canonical_string);
self.host = self.host.map(canonical_string);
self
}
fn into_core(self) -> CoreFilter {
let (
resource_type,
resource_name,
pattern_type,
principal,
host,
operation,
permission_type,
) = self.into_parts();
CoreFilter::new(
resource_type,
resource_name,
pattern_type,
principal,
host,
operation,
permission_type,
)
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DescribeAclsRequest {
filter: DescribeAclsFilter,
}
impl DescribeAclsRequest {
pub const fn new(filter: DescribeAclsFilter) -> Self {
Self { filter }
}
pub const fn filter(&self) -> &DescribeAclsFilter {
&self.filter
}
pub fn into_filter(self) -> DescribeAclsFilter {
self.filter
}
pub(crate) fn canonicalize(mut self) -> Self {
self.filter = self.filter.canonicalize();
self
}
pub(crate) fn into_plan(self) -> Result<CorePlan, CorePlanError> {
CorePlan::new(self.filter.into_core())
}
}
fn canonical_string(value: String) -> String {
value.into_boxed_str().into_string()
}