openstack_sdk/api/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 crate::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 RequestBuilder<'_> {
50    /// Add a single header to the Amphorae.
51    pub fn header(&mut self, header_name: &'static str, header_value: &'static str) -> &mut Self
52where {
53        self._headers
54            .get_or_insert(None)
55            .get_or_insert_with(HeaderMap::new)
56            .insert(header_name, HeaderValue::from_static(header_value));
57        self
58    }
59
60    /// Add multiple headers.
61    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
62    where
63        I: Iterator<Item = T>,
64        T: Into<(Option<HeaderName>, HeaderValue)>,
65    {
66        self._headers
67            .get_or_insert(None)
68            .get_or_insert_with(HeaderMap::new)
69            .extend(iter.map(Into::into));
70        self
71    }
72}
73
74impl RestEndpoint for Request<'_> {
75    fn method(&self) -> http::Method {
76        http::Method::DELETE
77    }
78
79    fn endpoint(&self) -> Cow<'static, str> {
80        format!(
81            "octavia/amphorae/{amphora_id}",
82            amphora_id = self.amphora_id.as_ref(),
83        )
84        .into()
85    }
86
87    fn parameters(&self) -> QueryParams {
88        QueryParams::default()
89    }
90
91    fn service_type(&self) -> ServiceType {
92        ServiceType::LoadBalancer
93    }
94
95    fn response_key(&self) -> Option<Cow<'static, str>> {
96        None
97    }
98
99    /// Returns headers to be set into the request
100    fn request_headers(&self) -> Option<&HeaderMap> {
101        self._headers.as_ref()
102    }
103
104    /// Returns required API version
105    fn api_version(&self) -> Option<ApiVersion> {
106        Some(ApiVersion::new(2, 0))
107    }
108}
109
110#[cfg(test)]
111mod tests {
112    use super::*;
113    #[cfg(feature = "sync")]
114    use crate::api::Query;
115    use crate::test::client::FakeOpenStackClient;
116    use crate::types::ServiceType;
117    use http::{HeaderName, HeaderValue};
118    use httpmock::MockServer;
119    use serde_json::json;
120
121    #[test]
122    fn test_service_type() {
123        assert_eq!(
124            Request::builder().build().unwrap().service_type(),
125            ServiceType::LoadBalancer
126        );
127    }
128
129    #[test]
130    fn test_response_key() {
131        assert!(Request::builder().build().unwrap().response_key().is_none())
132    }
133
134    #[cfg(feature = "sync")]
135    #[test]
136    fn endpoint() {
137        let server = MockServer::start();
138        let client = FakeOpenStackClient::new(server.base_url());
139        let mock = server.mock(|when, then| {
140            when.method(httpmock::Method::DELETE).path(format!(
141                "/octavia/amphorae/{amphora_id}",
142                amphora_id = "amphora_id",
143            ));
144
145            then.status(200)
146                .header("content-type", "application/json")
147                .json_body(json!({ "dummy": {} }));
148        });
149
150        let endpoint = Request::builder().amphora_id("amphora_id").build().unwrap();
151        let _: serde_json::Value = endpoint.query(&client).unwrap();
152        mock.assert();
153    }
154
155    #[cfg(feature = "sync")]
156    #[test]
157    fn endpoint_headers() {
158        let server = MockServer::start();
159        let client = FakeOpenStackClient::new(server.base_url());
160        let mock = server.mock(|when, then| {
161            when.method(httpmock::Method::DELETE)
162                .path(format!(
163                    "/octavia/amphorae/{amphora_id}",
164                    amphora_id = "amphora_id",
165                ))
166                .header("foo", "bar")
167                .header("not_foo", "not_bar");
168            then.status(200)
169                .header("content-type", "application/json")
170                .json_body(json!({ "dummy": {} }));
171        });
172
173        let endpoint = Request::builder()
174            .amphora_id("amphora_id")
175            .headers(
176                [(
177                    Some(HeaderName::from_static("foo")),
178                    HeaderValue::from_static("bar"),
179                )]
180                .into_iter(),
181            )
182            .header("not_foo", "not_bar")
183            .build()
184            .unwrap();
185        let _: serde_json::Value = endpoint.query(&client).unwrap();
186        mock.assert();
187    }
188}