Skip to main content

confluent_kafka/admin/
delete_acls_result.rs

1// Copyright 2025 Confluent Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! The result of `Admin::delete_acls`.
16
17use std::collections::HashMap;
18
19use crate::common::acl::{AclBinding, AclBindingFilter};
20use crate::common::{Error, KafkaFuture};
21
22/// A class containing either the deleted ACL binding or an exception if the
23/// delete failed.
24#[derive(Clone, Debug)]
25#[doc(alias = "org.apache.kafka.clients.admin.DeleteAclsResult$FilterResult")]
26pub struct FilterResult {
27    binding: Option<AclBinding>,
28    error: Option<Error>,
29}
30
31impl FilterResult {
32    /// Creates a filter result carrying the deleted binding and/or an error.
33    #[doc(alias = "org.apache.kafka.clients.admin.DeleteAclsResult$FilterResult#FilterResult")]
34    pub(crate) fn new(binding: Option<AclBinding>, error: Option<Error>) -> Self {
35        Self { binding, error }
36    }
37
38    /// Returns the deleted ACL binding, or `None` if there was an error.
39    #[doc(alias = "org.apache.kafka.clients.admin.DeleteAclsResult$FilterResult#binding")]
40    pub fn binding(&self) -> Option<&AclBinding> {
41        self.binding.as_ref()
42    }
43
44    /// Returns an exception if the ACL delete was not successful, or `None` if it
45    /// was.
46    #[doc(alias = "org.apache.kafka.clients.admin.DeleteAclsResult$FilterResult#exception")]
47    pub fn error(&self) -> Option<&Error> {
48        self.error.as_ref()
49    }
50}
51
52/// A class containing the results of the delete ACLs operation.
53#[derive(Clone, Debug)]
54#[doc(alias = "org.apache.kafka.clients.admin.DeleteAclsResult$FilterResults")]
55pub struct FilterResults {
56    values: Vec<FilterResult>,
57}
58
59impl FilterResults {
60    /// Creates a `FilterResults` from a list of per-ACL results.
61    #[doc(alias = "org.apache.kafka.clients.admin.DeleteAclsResult$FilterResults#FilterResults")]
62    pub(crate) fn new(values: Vec<FilterResult>) -> Self {
63        Self { values }
64    }
65
66    /// Returns a list of delete ACLs results for a given filter.
67    #[doc(alias = "org.apache.kafka.clients.admin.DeleteAclsResult$FilterResults#values")]
68    pub fn values(&self) -> &[FilterResult] {
69        &self.values
70    }
71}
72
73/// The result of the `Admin::delete_acls` call.
74#[derive(Clone, Debug)]
75#[doc(alias = "org.apache.kafka.clients.admin.DeleteAclsResult")]
76pub struct DeleteAclsResult {
77    futures: HashMap<AclBindingFilter, KafkaFuture<FilterResults>>,
78}
79
80impl DeleteAclsResult {
81    /// Creates a new result from the per-filter futures.
82    #[doc(alias = "org.apache.kafka.clients.admin.DeleteAclsResult#DeleteAclsResult")]
83    pub(crate) fn new(futures: HashMap<AclBindingFilter, KafkaFuture<FilterResults>>) -> Self {
84        Self { futures }
85    }
86
87    /// Returns a map from ACL filters to futures which can be used to check the
88    /// status of the deletions by each filter.
89    #[doc(alias = "org.apache.kafka.clients.admin.DeleteAclsResult#values")]
90    pub fn values(&self) -> &HashMap<AclBindingFilter, KafkaFuture<FilterResults>> {
91        &self.futures
92    }
93
94    /// Returns a future which succeeds only if all the ACL deletions succeed, and
95    /// which contains all the deleted ACLs. Note that if the filters don't match
96    /// any ACLs, this is not considered an error.
97    #[doc(alias = "org.apache.kafka.clients.admin.DeleteAclsResult#all")]
98    pub fn all(&self) -> KafkaFuture<Vec<AclBinding>> {
99        let futures: Vec<KafkaFuture<FilterResults>> = self.futures.values().cloned().collect();
100        KafkaFuture::all_of(futures.clone()).then_apply(move |()| get_acl_bindings(&futures))
101    }
102}
103
104/// The deleted ACL bindings of `futures`, all complete, or the first per-ACL
105/// deletion error.
106#[doc(alias = "org.apache.kafka.clients.admin.DeleteAclsResult#getAclBindings")]
107fn get_acl_bindings(futures: &[KafkaFuture<FilterResults>]) -> Result<Vec<AclBinding>, Error> {
108    let mut acls = Vec::new();
109    for value in futures {
110        // `all_of` has completed every future, successfully, so this is the
111        // unreachable branch Java reports as an internal error.
112        let results = match value.result_if_done() {
113            Some(Ok(results)) => results,
114            Some(Err(error)) => return Err(Error::kafka_message_source("DeleteAclsResult#all: internal error", error)),
115            None => return Err(Error::kafka_message("DeleteAclsResult#all: internal error")),
116        };
117        for result in results.values() {
118            if let Some(error) = result.error() {
119                return Err(error.clone());
120            }
121            if let Some(binding) = result.binding() {
122                acls.push(binding.clone());
123            }
124        }
125    }
126    Ok(acls)
127}