openstack_sdk_identity/v3/auth/token/
delete.rs1use derive_builder::Builder;
28use http::{HeaderMap, HeaderName, HeaderValue};
29
30use openstack_sdk_core::api::rest_endpoint_prelude::*;
31
32#[derive(Builder, Debug, Clone)]
33#[builder(setter(strip_option))]
34pub struct Request {
35 #[builder(setter(name = "_headers"), default, private)]
36 _headers: Option<HeaderMap>,
37}
38impl Request {
39 pub fn builder() -> RequestBuilder {
41 RequestBuilder::default()
42 }
43}
44
45impl RequestBuilder {
46 pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
48 where
49 K: Into<HeaderName>,
50 V: Into<HeaderValue>,
51 {
52 self._headers
53 .get_or_insert(None)
54 .get_or_insert_with(HeaderMap::new)
55 .insert(header_name.into(), header_value.into());
56 self
57 }
58
59 pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
61 where
62 I: Iterator<Item = T>,
63 T: Into<(Option<HeaderName>, HeaderValue)>,
64 {
65 self._headers
66 .get_or_insert(None)
67 .get_or_insert_with(HeaderMap::new)
68 .extend(iter.map(Into::into));
69 self
70 }
71}
72
73impl RestEndpoint for Request {
74 fn method(&self) -> http::Method {
75 http::Method::DELETE
76 }
77
78 fn endpoint(&self) -> Cow<'static, str> {
79 "auth/tokens".to_string().into()
80 }
81
82 fn parameters(&self) -> QueryParams<'_> {
83 QueryParams::default()
84 }
85
86 fn service_type(&self) -> ServiceType {
87 ServiceType::Identity
88 }
89
90 fn response_key(&self) -> Option<Cow<'static, str>> {
91 None
92 }
93
94 fn request_headers(&self) -> Option<&HeaderMap> {
96 self._headers.as_ref()
97 }
98
99 fn api_version(&self) -> Option<ApiVersion> {
101 Some(ApiVersion::new(3, 0))
102 }
103}
104
105#[cfg(test)]
106mod tests {
107 use super::*;
108 use http::{HeaderName, HeaderValue};
109 use httpmock::MockServer;
110 #[cfg(feature = "sync")]
111 use openstack_sdk_core::api::Query;
112 use openstack_sdk_core::test::client::FakeOpenStackClient;
113 use openstack_sdk_core::types::ServiceType;
114 use serde_json::json;
115
116 #[test]
117 fn test_service_type() {
118 assert_eq!(
119 Request::builder().build().unwrap().service_type(),
120 ServiceType::Identity
121 );
122 }
123
124 #[test]
125 fn test_response_key() {
126 assert!(Request::builder().build().unwrap().response_key().is_none())
127 }
128
129 #[cfg(feature = "sync")]
130 #[test]
131 fn endpoint() {
132 let server = MockServer::start();
133 let client = FakeOpenStackClient::new(server.base_url());
134 let mock = server.mock(|when, then| {
135 when.method(httpmock::Method::DELETE)
136 .path("/auth/tokens".to_string());
137
138 then.status(200)
139 .header("content-type", "application/json")
140 .json_body(json!({ "dummy": {} }));
141 });
142
143 let endpoint = Request::builder().build().unwrap();
144 let _: serde_json::Value = endpoint.query(&client).unwrap();
145 mock.assert();
146 }
147
148 #[cfg(feature = "sync")]
149 #[test]
150 fn endpoint_headers() {
151 let server = MockServer::start();
152 let client = FakeOpenStackClient::new(server.base_url());
153 let mock = server.mock(|when, then| {
154 when.method(httpmock::Method::DELETE)
155 .path("/auth/tokens".to_string())
156 .header("foo", "bar")
157 .header("not_foo", "not_bar");
158 then.status(200)
159 .header("content-type", "application/json")
160 .json_body(json!({ "dummy": {} }));
161 });
162
163 let endpoint = Request::builder()
164 .headers(
165 [(
166 Some(HeaderName::from_static("foo")),
167 HeaderValue::from_static("bar"),
168 )]
169 .into_iter(),
170 )
171 .header(
172 HeaderName::from_static("not_foo"),
173 HeaderValue::from_static("not_bar"),
174 )
175 .build()
176 .unwrap();
177 let _: serde_json::Value = endpoint.query(&client).unwrap();
178 mock.assert();
179 }
180}