1use std::io::{Read, Result, Write};
4
5use serde::{Deserialize, Serialize};
6#[cfg(test)] use proptest_derive::Arbitrary;
7
8use crate::arrays::{read_array, write_array};
9use crate::bytes::{read_bytes, write_bytes};
10use crate::markers::{ApiMessage, Response};
11use crate::readable_writable::{Readable, Writable};
12use crate::tagged_fields::{RawTaggedField, read_tagged_fields, write_tagged_fields};
13#[cfg(test)] use crate::test_utils::{proptest_strategies, serde_bytes};
14
15#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
17#[cfg_attr(test, derive(Arbitrary))]
18pub struct DescribeDelegationTokenResponse {
19 pub error_code: i16,
21 #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
23 pub tokens: Vec<DescribedDelegationToken>,
24 pub throttle_time_ms: i32,
26 #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
28 pub _unknown_tagged_fields: Vec<RawTaggedField>,
29}
30
31impl ApiMessage for DescribeDelegationTokenResponse {
32 fn api_key(&self) -> i16 {
33 41
34 }
35
36 fn version(&self) -> i16 {
37 2
38 }
39}
40
41impl Response for DescribeDelegationTokenResponse { }
42
43impl Default for DescribeDelegationTokenResponse {
44 fn default() -> Self {
45 DescribeDelegationTokenResponse {
46 error_code: 0_i16,
47 tokens: Vec::<DescribedDelegationToken>::new(),
48 throttle_time_ms: 0_i32,
49 _unknown_tagged_fields: Vec::new(),
50 }
51 }
52}
53
54impl DescribeDelegationTokenResponse {
55 pub fn new(error_code: i16, tokens: Vec<DescribedDelegationToken>, throttle_time_ms: i32) -> Self {
56 Self {
57 error_code,
58 tokens,
59 throttle_time_ms,
60 _unknown_tagged_fields: vec![],
61 }
62 }
63}
64
65#[cfg(test)]
66mod tests_describe_delegation_token_response_new_and_default {
67 use super::*;
68
69 #[test]
70 fn test() {
71 let d = DescribeDelegationTokenResponse::new(
72 0_i16,
73 Vec::<DescribedDelegationToken>::new(),
74 0_i32,
75 );
76 assert_eq!(d, DescribeDelegationTokenResponse::default());
77 }
78}
79
80impl Readable for DescribeDelegationTokenResponse {
81 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
82 let error_code = i16::read(input)?;
83 let tokens = read_array::<DescribedDelegationToken>(input, "tokens", true)?;
84 let throttle_time_ms = i32::read(input)?;
85 let tagged_fields_callback = |tag: i32, _: &[u8]| {
86 match tag {
87 _ => Ok(false)
88 }
89 };
90 let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
91 Ok(DescribeDelegationTokenResponse {
92 error_code, tokens, throttle_time_ms, _unknown_tagged_fields
93 })
94 }
95}
96
97impl Writable for DescribeDelegationTokenResponse {
98 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
99 self.error_code.write(output)?;
100 write_array(output, "self.tokens", &self.tokens, true)?;
101 self.throttle_time_ms.write(output)?;
102 write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
103 Ok(())
104 }
105}
106
107#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
109#[cfg_attr(test, derive(Arbitrary))]
110pub struct DescribedDelegationToken {
111 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
113 pub principal_type: String,
114 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
116 pub principal_name: String,
117 pub issue_timestamp: i64,
119 pub expiry_timestamp: i64,
121 pub max_timestamp: i64,
123 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
125 pub token_id: String,
126 #[cfg_attr(test, proptest(strategy = "proptest_strategies::bytes()"))]
128 #[cfg_attr(test, serde(with="serde_bytes"))]
129 pub hmac: Vec<u8>,
130 #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
132 pub renewers: Vec<DescribedDelegationTokenRenewer>,
133 #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
135 pub _unknown_tagged_fields: Vec<RawTaggedField>,
136}
137
138impl Default for DescribedDelegationToken {
139 fn default() -> Self {
140 DescribedDelegationToken {
141 principal_type: String::from(""),
142 principal_name: String::from(""),
143 issue_timestamp: 0_i64,
144 expiry_timestamp: 0_i64,
145 max_timestamp: 0_i64,
146 token_id: String::from(""),
147 hmac: Vec::new(),
148 renewers: Vec::<DescribedDelegationTokenRenewer>::new(),
149 _unknown_tagged_fields: Vec::new(),
150 }
151 }
152}
153
154impl DescribedDelegationToken {
155 pub fn new<S1: AsRef<str>, S2: AsRef<str>, S3: AsRef<str>>(principal_type: S1, principal_name: S2, issue_timestamp: i64, expiry_timestamp: i64, max_timestamp: i64, token_id: S3, hmac: Vec<u8>, renewers: Vec<DescribedDelegationTokenRenewer>) -> Self {
156 Self {
157 principal_type: principal_type.as_ref().to_string(),
158 principal_name: principal_name.as_ref().to_string(),
159 issue_timestamp,
160 expiry_timestamp,
161 max_timestamp,
162 token_id: token_id.as_ref().to_string(),
163 hmac,
164 renewers,
165 _unknown_tagged_fields: vec![],
166 }
167 }
168}
169
170#[cfg(test)]
171mod tests_described_delegation_token_new_and_default {
172 use super::*;
173
174 #[test]
175 fn test() {
176 let d = DescribedDelegationToken::new(
177 String::from(""),
178 String::from(""),
179 0_i64,
180 0_i64,
181 0_i64,
182 String::from(""),
183 Vec::new(),
184 Vec::<DescribedDelegationTokenRenewer>::new(),
185 );
186 assert_eq!(d, DescribedDelegationToken::default());
187 }
188}
189
190impl Readable for DescribedDelegationToken {
191 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
192 let principal_type = String::read_ext(input, "principal_type", true)?;
193 let principal_name = String::read_ext(input, "principal_name", true)?;
194 let issue_timestamp = i64::read(input)?;
195 let expiry_timestamp = i64::read(input)?;
196 let max_timestamp = i64::read(input)?;
197 let token_id = String::read_ext(input, "token_id", true)?;
198 let hmac = read_bytes(input, "hmac", true)?;
199 let renewers = read_array::<DescribedDelegationTokenRenewer>(input, "renewers", true)?;
200 let tagged_fields_callback = |tag: i32, _: &[u8]| {
201 match tag {
202 _ => Ok(false)
203 }
204 };
205 let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
206 Ok(DescribedDelegationToken {
207 principal_type, principal_name, issue_timestamp, expiry_timestamp, max_timestamp, token_id, hmac, renewers, _unknown_tagged_fields
208 })
209 }
210}
211
212impl Writable for DescribedDelegationToken {
213 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
214 self.principal_type.write_ext(output, "self.principal_type", true)?;
215 self.principal_name.write_ext(output, "self.principal_name", true)?;
216 self.issue_timestamp.write(output)?;
217 self.expiry_timestamp.write(output)?;
218 self.max_timestamp.write(output)?;
219 self.token_id.write_ext(output, "self.token_id", true)?;
220 write_bytes(output, "self.hmac", &self.hmac, true)?;
221 write_array(output, "self.renewers", &self.renewers, true)?;
222 write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
223 Ok(())
224 }
225}
226
227#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
229#[cfg_attr(test, derive(Arbitrary))]
230pub struct DescribedDelegationTokenRenewer {
231 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
233 pub principal_type: String,
234 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
236 pub principal_name: String,
237 #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
239 pub _unknown_tagged_fields: Vec<RawTaggedField>,
240}
241
242impl Default for DescribedDelegationTokenRenewer {
243 fn default() -> Self {
244 DescribedDelegationTokenRenewer {
245 principal_type: String::from(""),
246 principal_name: String::from(""),
247 _unknown_tagged_fields: Vec::new(),
248 }
249 }
250}
251
252impl DescribedDelegationTokenRenewer {
253 pub fn new<S1: AsRef<str>, S2: AsRef<str>>(principal_type: S1, principal_name: S2) -> Self {
254 Self {
255 principal_type: principal_type.as_ref().to_string(),
256 principal_name: principal_name.as_ref().to_string(),
257 _unknown_tagged_fields: vec![],
258 }
259 }
260}
261
262#[cfg(test)]
263mod tests_described_delegation_token_renewer_new_and_default {
264 use super::*;
265
266 #[test]
267 fn test() {
268 let d = DescribedDelegationTokenRenewer::new(
269 String::from(""),
270 String::from(""),
271 );
272 assert_eq!(d, DescribedDelegationTokenRenewer::default());
273 }
274}
275
276impl Readable for DescribedDelegationTokenRenewer {
277 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
278 let principal_type = String::read_ext(input, "principal_type", true)?;
279 let principal_name = String::read_ext(input, "principal_name", true)?;
280 let tagged_fields_callback = |tag: i32, _: &[u8]| {
281 match tag {
282 _ => Ok(false)
283 }
284 };
285 let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
286 Ok(DescribedDelegationTokenRenewer {
287 principal_type, principal_name, _unknown_tagged_fields
288 })
289 }
290}
291
292impl Writable for DescribedDelegationTokenRenewer {
293 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
294 self.principal_type.write_ext(output, "self.principal_type", true)?;
295 self.principal_name.write_ext(output, "self.principal_name", true)?;
296 write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
297 Ok(())
298 }
299}
300
301#[cfg(test)]
302mod tests {
303 use super::*;
304 use proptest::prelude::*;
305
306 #[test]
307 fn test_java_default() {
308 crate::test_utils::test_java_default::<DescribeDelegationTokenResponse>("DescribeDelegationTokenResponse", 2);
309 }
310
311 proptest! {
312 #[test]
313 fn test_serde(data: DescribeDelegationTokenResponse) {
314 crate::test_utils::test_serde(&data)?;
315 }
316 }
317
318 proptest! {
319 #[test]
320 fn test_java_arbitrary(data: DescribeDelegationTokenResponse) {
321 crate::test_utils::test_java_arbitrary(&data, "DescribeDelegationTokenResponse", 2);
322 }
323 }
324}