Skip to main content

openstack_sdk_load_balancer/v2/amphorae/
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 amphora and its associated configuration.
19//!
20//! The API immediately purges any and all configuration data, depending on the
21//! configuration settings. You cannot recover it.
22//!
23//! **New in version 2.20**
24//!
25use derive_builder::Builder;
26use http::{HeaderMap, HeaderName, HeaderValue};
27
28use openstack_sdk_core::api::rest_endpoint_prelude::*;
29
30use std::borrow::Cow;
31
32#[derive(Builder, Debug, Clone)]
33#[builder(setter(strip_option))]
34pub struct Request<'a> {
35    /// amphora_id parameter for /v2/octavia/amphorae/{amphora_id} API
36    #[builder(default, setter(into))]
37    amphora_id: Cow<'a, str>,
38
39    #[builder(setter(name = "_headers"), default, private)]
40    _headers: Option<HeaderMap>,
41}
42impl<'a> Request<'a> {
43    /// Create a builder for the endpoint.
44    pub fn builder() -> RequestBuilder<'a> {
45        RequestBuilder::default()
46    }
47}
48
49impl<'a> RequestBuilder<'a> {
50    /// Add a single header to the Amphorae.
51    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
52    where
53        K: Into<HeaderName>,
54        V: Into<HeaderValue>,
55    {
56        self._headers
57            .get_or_insert(None)
58            .get_or_insert_with(HeaderMap::new)
59            .insert(header_name.into(), header_value.into());
60        self
61    }
62
63    /// Add multiple headers.
64    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
65    where
66        I: Iterator<Item = T>,
67        T: Into<(Option<HeaderName>, HeaderValue)>,
68    {
69        self._headers
70            .get_or_insert(None)
71            .get_or_insert_with(HeaderMap::new)
72            .extend(iter.map(Into::into));
73        self
74    }
75}
76
77impl RestEndpoint for Request<'_> {
78    fn method(&self) -> http::Method {
79        http::Method::DELETE
80    }
81
82    fn endpoint(&self) -> Cow<'static, str> {
83        format!(
84            "octavia/amphorae/{amphora_id}",
85            amphora_id = self.amphora_id.as_ref(),
86        )
87        .into()
88    }
89
90    fn parameters(&self) -> QueryParams<'_> {
91        QueryParams::default()
92    }
93
94    fn service_type(&self) -> ServiceType {
95        ServiceType::LoadBalancer
96    }
97
98    fn response_key(&self) -> Option<Cow<'static, str>> {
99        None
100    }
101
102    /// Returns headers to be set into the request
103    fn request_headers(&self) -> Option<&HeaderMap> {
104        self._headers.as_ref()
105    }
106
107    /// Returns required API version
108    fn api_version(&self) -> Option<ApiVersion> {
109        Some(ApiVersion::new(2, 0))
110    }
111}
112
113#[cfg(test)]
114mod tests {
115    use super::*;
116    use http::{HeaderName, HeaderValue};
117    use httpmock::MockServer;
118    #[cfg(feature = "sync")]
119    use openstack_sdk_core::api::Query;
120    use openstack_sdk_core::test::client::FakeOpenStackClient;
121    use openstack_sdk_core::types::ServiceType;
122    use serde_json::json;
123
124    #[test]
125    fn test_service_type() {
126        assert_eq!(
127            Request::builder().build().unwrap().service_type(),
128            ServiceType::LoadBalancer
129        );
130    }
131
132    #[test]
133    fn test_response_key() {
134        assert!(Request::builder().build().unwrap().response_key().is_none())
135    }
136
137    #[cfg(feature = "sync")]
138    #[test]
139    fn endpoint() {
140        let server = MockServer::start();
141        let client = FakeOpenStackClient::new(server.base_url());
142        let mock = server.mock(|when, then| {
143            when.method(httpmock::Method::DELETE).path(format!(
144                "/octavia/amphorae/{amphora_id}",
145                amphora_id = "amphora_id",
146            ));
147
148            then.status(200)
149                .header("content-type", "application/json")
150                .json_body(json!({ "dummy": {} }));
151        });
152
153        let endpoint = Request::builder().amphora_id("amphora_id").build().unwrap();
154        let _: serde_json::Value = endpoint.query(&client).unwrap();
155        mock.assert();
156    }
157
158    #[cfg(feature = "sync")]
159    #[test]
160    fn endpoint_headers() {
161        let server = MockServer::start();
162        let client = FakeOpenStackClient::new(server.base_url());
163        let mock = server.mock(|when, then| {
164            when.method(httpmock::Method::DELETE)
165                .path(format!(
166                    "/octavia/amphorae/{amphora_id}",
167                    amphora_id = "amphora_id",
168                ))
169                .header("foo", "bar")
170                .header("not_foo", "not_bar");
171            then.status(200)
172                .header("content-type", "application/json")
173                .json_body(json!({ "dummy": {} }));
174        });
175
176        let endpoint = Request::builder()
177            .amphora_id("amphora_id")
178            .headers(
179                [(
180                    Some(HeaderName::from_static("foo")),
181                    HeaderValue::from_static("bar"),
182                )]
183                .into_iter(),
184            )
185            .header(
186                HeaderName::from_static("not_foo"),
187                HeaderValue::from_static("not_bar"),
188            )
189            .build()
190            .unwrap();
191        let _: serde_json::Value = endpoint.query(&client).unwrap();
192        mock.assert();
193    }
194}