openstack_sdk/api/network/v2/vpn/ipsecpolicy/
delete.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5//     http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// SPDX-License-Identifier: Apache-2.0
14//
15// WARNING: This file is automatically generated from OpenAPI schema using
16// `openstack-codegenerator`.
17
18//! Removes an IPsec policy.
19//!
20//! Normal response codes: 204
21//!
22//! Error response codes: 401, 404, 409
23//!
24use derive_builder::Builder;
25use http::{HeaderMap, HeaderName, HeaderValue};
26
27use crate::api::rest_endpoint_prelude::*;
28
29use std::borrow::Cow;
30
31#[derive(Builder, Debug, Clone)]
32#[builder(setter(strip_option))]
33pub struct Request<'a> {
34    /// id parameter for /v2.0/vpn/ipsecpolicies/{id} API
35    #[builder(default, setter(into))]
36    id: Cow<'a, str>,
37
38    #[builder(setter(name = "_headers"), default, private)]
39    _headers: Option<HeaderMap>,
40}
41impl<'a> Request<'a> {
42    /// Create a builder for the endpoint.
43    pub fn builder() -> RequestBuilder<'a> {
44        RequestBuilder::default()
45    }
46}
47
48impl<'a> RequestBuilder<'a> {
49    /// Add a single header to the Ipsecpolicy.
50    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
51    where
52        K: Into<HeaderName>,
53        V: Into<HeaderValue>,
54    {
55        self._headers
56            .get_or_insert(None)
57            .get_or_insert_with(HeaderMap::new)
58            .insert(header_name.into(), header_value.into());
59        self
60    }
61
62    /// Add multiple headers.
63    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
64    where
65        I: Iterator<Item = T>,
66        T: Into<(Option<HeaderName>, HeaderValue)>,
67    {
68        self._headers
69            .get_or_insert(None)
70            .get_or_insert_with(HeaderMap::new)
71            .extend(iter.map(Into::into));
72        self
73    }
74}
75
76impl RestEndpoint for Request<'_> {
77    fn method(&self) -> http::Method {
78        http::Method::DELETE
79    }
80
81    fn endpoint(&self) -> Cow<'static, str> {
82        format!("vpn/ipsecpolicies/{id}", id = self.id.as_ref(),).into()
83    }
84
85    fn parameters(&self) -> QueryParams<'_> {
86        QueryParams::default()
87    }
88
89    fn service_type(&self) -> ServiceType {
90        ServiceType::Network
91    }
92
93    fn response_key(&self) -> Option<Cow<'static, str>> {
94        None
95    }
96
97    /// Returns headers to be set into the request
98    fn request_headers(&self) -> Option<&HeaderMap> {
99        self._headers.as_ref()
100    }
101
102    /// Returns required API version
103    fn api_version(&self) -> Option<ApiVersion> {
104        Some(ApiVersion::new(2, 0))
105    }
106}
107
108#[cfg(test)]
109mod tests {
110    use super::*;
111    #[cfg(feature = "sync")]
112    use crate::api::Query;
113    use crate::test::client::FakeOpenStackClient;
114    use crate::types::ServiceType;
115    use http::{HeaderName, HeaderValue};
116    use httpmock::MockServer;
117    use serde_json::json;
118
119    #[test]
120    fn test_service_type() {
121        assert_eq!(
122            Request::builder().build().unwrap().service_type(),
123            ServiceType::Network
124        );
125    }
126
127    #[test]
128    fn test_response_key() {
129        assert!(Request::builder().build().unwrap().response_key().is_none())
130    }
131
132    #[cfg(feature = "sync")]
133    #[test]
134    fn endpoint() {
135        let server = MockServer::start();
136        let client = FakeOpenStackClient::new(server.base_url());
137        let mock = server.mock(|when, then| {
138            when.method(httpmock::Method::DELETE)
139                .path(format!("/vpn/ipsecpolicies/{id}", id = "id",));
140
141            then.status(200)
142                .header("content-type", "application/json")
143                .json_body(json!({ "dummy": {} }));
144        });
145
146        let endpoint = Request::builder().id("id").build().unwrap();
147        let _: serde_json::Value = endpoint.query(&client).unwrap();
148        mock.assert();
149    }
150
151    #[cfg(feature = "sync")]
152    #[test]
153    fn endpoint_headers() {
154        let server = MockServer::start();
155        let client = FakeOpenStackClient::new(server.base_url());
156        let mock = server.mock(|when, then| {
157            when.method(httpmock::Method::DELETE)
158                .path(format!("/vpn/ipsecpolicies/{id}", id = "id",))
159                .header("foo", "bar")
160                .header("not_foo", "not_bar");
161            then.status(200)
162                .header("content-type", "application/json")
163                .json_body(json!({ "dummy": {} }));
164        });
165
166        let endpoint = Request::builder()
167            .id("id")
168            .headers(
169                [(
170                    Some(HeaderName::from_static("foo")),
171                    HeaderValue::from_static("bar"),
172                )]
173                .into_iter(),
174            )
175            .header(
176                HeaderName::from_static("not_foo"),
177                HeaderValue::from_static("not_bar"),
178            )
179            .build()
180            .unwrap();
181        let _: serde_json::Value = endpoint.query(&client).unwrap();
182        mock.assert();
183    }
184}