Skip to main content

confluent_kafka/admin/options/
describe_delegation_token_options.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//! Options for `Admin::describe_delegation_token`.
16
17use crate::common::security::auth::KafkaPrincipal;
18
19/// Options for `Admin::describe_delegation_token`.
20#[derive(Clone, Debug, Default)]
21#[doc(alias = "org.apache.kafka.clients.admin.DescribeDelegationTokenOptions")]
22pub struct DescribeDelegationTokenOptions {
23    owners: Option<Vec<KafkaPrincipal>>,
24    timeout_ms: Option<i32>,
25}
26
27impl DescribeDelegationTokenOptions {
28    /// Creates default options (default API timeout, describe all authorized
29    /// tokens).
30    #[doc(alias = "org.apache.kafka.clients.admin.DescribeDelegationTokenOptions#DescribeDelegationTokenOptions")]
31    pub fn new() -> Self {
32        Self::default()
33    }
34
35    /// If owners is `None`, all the user owned tokens and tokens where user have Describe
36    /// permission will be returned.
37    ///
38    /// # Arguments
39    ///
40    /// - `owners` - The owners that we want to describe delegation tokens for
41    ///
42    /// # Returns
43    ///
44    /// This `DescribeDelegationTokenOptions` instance.
45    #[must_use]
46    #[doc(alias = "org.apache.kafka.clients.admin.DescribeDelegationTokenOptions#owners")]
47    pub fn set_owners(mut self, owners: Option<Vec<KafkaPrincipal>>) -> Self {
48        self.owners = owners;
49        self
50    }
51
52    /// Returns the owners to describe delegation tokens for, or `None` for all authorized tokens.
53    #[doc(alias = "org.apache.kafka.clients.admin.DescribeDelegationTokenOptions#owners")]
54    pub fn owners(&self) -> Option<&[KafkaPrincipal]> {
55        self.owners.as_deref()
56    }
57
58    /// Set the timeout in milliseconds for this operation, or `None` if the default
59    /// API timeout for the `AdminClient` should be used.
60    ///
61    /// # Arguments
62    ///
63    /// - `timeout_ms` - the timeout in milliseconds, or `None` for the default API timeout.
64    ///
65    /// # Returns
66    ///
67    /// This `DescribeDelegationTokenOptions` instance.
68    #[must_use]
69    #[doc(alias = "org.apache.kafka.clients.admin.AbstractOptions#timeoutMs")]
70    pub fn set_timeout_ms(mut self, timeout_ms: Option<i32>) -> Self {
71        self.timeout_ms = timeout_ms;
72        self
73    }
74
75    /// Returns the timeout in milliseconds for this operation, or `None` if the
76    /// default API timeout for the `AdminClient` should be used.
77    #[doc(alias = "org.apache.kafka.clients.admin.AbstractOptions#timeoutMs")]
78    pub fn timeout_ms(&self) -> Option<i32> {
79        self.timeout_ms
80    }
81}
82
83#[cfg(test)]
84mod tests {
85    use super::*;
86
87    #[test]
88    fn defaults() {
89        let options = DescribeDelegationTokenOptions::new();
90        assert!(options.owners().is_none());
91        assert_eq!(options.timeout_ms(), None);
92    }
93
94    #[test]
95    fn setters() {
96        let owner = KafkaPrincipal::new(KafkaPrincipal::USER_TYPE, "alice");
97        let options = DescribeDelegationTokenOptions::new()
98            .set_owners(Some(vec![owner.clone()]))
99            .set_timeout_ms(Some(5000));
100        assert_eq!(options.owners(), Some([owner].as_slice()));
101        assert_eq!(options.timeout_ms(), Some(5000));
102    }
103}