Skip to main content

confluent_kafka/admin/options/
renew_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::renew_delegation_token`.
16
17/// Options for `Admin::renew_delegation_token`.
18#[derive(Clone, Debug)]
19#[doc(alias = "org.apache.kafka.clients.admin.RenewDelegationTokenOptions")]
20pub struct RenewDelegationTokenOptions {
21    renew_time_period_ms: i64,
22    timeout_ms: Option<i32>,
23}
24
25impl Default for RenewDelegationTokenOptions {
26    fn default() -> Self {
27        Self { renew_time_period_ms: -1, timeout_ms: None }
28    }
29}
30
31impl RenewDelegationTokenOptions {
32    /// Creates default options (default API timeout, server-default renew
33    /// period).
34    #[doc(alias = "org.apache.kafka.clients.admin.RenewDelegationTokenOptions#RenewDelegationTokenOptions")]
35    pub fn new() -> Self {
36        Self::default()
37    }
38
39    /// Sets the renew time period in milliseconds.
40    ///
41    /// # Arguments
42    ///
43    /// - `renew_time_period_ms` - the renew time period in milliseconds, `-1` for the server
44    ///   default.
45    ///
46    /// # Returns
47    ///
48    /// This `RenewDelegationTokenOptions` instance.
49    #[must_use]
50    #[doc(alias = "org.apache.kafka.clients.admin.RenewDelegationTokenOptions#renewTimePeriodMs")]
51    pub fn set_renew_time_period_ms(mut self, renew_time_period_ms: i64) -> Self {
52        self.renew_time_period_ms = renew_time_period_ms;
53        self
54    }
55
56    /// Returns the renew time period in milliseconds, `-1` for the server default.
57    #[doc(alias = "org.apache.kafka.clients.admin.RenewDelegationTokenOptions#renewTimePeriodMs")]
58    pub fn renew_time_period_ms(&self) -> i64 {
59        self.renew_time_period_ms
60    }
61
62    /// Set the timeout in milliseconds for this operation, or `None` if the default
63    /// API timeout for the `AdminClient` should be used.
64    ///
65    /// # Arguments
66    ///
67    /// - `timeout_ms` - the timeout in milliseconds, or `None` for the default API timeout.
68    ///
69    /// # Returns
70    ///
71    /// This `RenewDelegationTokenOptions` instance.
72    #[must_use]
73    #[doc(alias = "org.apache.kafka.clients.admin.AbstractOptions#timeoutMs")]
74    pub fn set_timeout_ms(mut self, timeout_ms: Option<i32>) -> Self {
75        self.timeout_ms = timeout_ms;
76        self
77    }
78
79    /// Returns the timeout in milliseconds for this operation, or `None` if the
80    /// default API timeout for the `AdminClient` should be used.
81    #[doc(alias = "org.apache.kafka.clients.admin.AbstractOptions#timeoutMs")]
82    pub fn timeout_ms(&self) -> Option<i32> {
83        self.timeout_ms
84    }
85}
86
87#[cfg(test)]
88mod tests {
89    use super::*;
90
91    #[test]
92    fn defaults_and_setter() {
93        assert_eq!(RenewDelegationTokenOptions::new().renew_time_period_ms(), -1);
94        let options = RenewDelegationTokenOptions::new()
95            .set_renew_time_period_ms(1000)
96            .set_timeout_ms(Some(5000));
97        assert_eq!(options.renew_time_period_ms(), 1000);
98        assert_eq!(options.timeout_ms(), Some(5000));
99    }
100}