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