Skip to main content

openstack_sdk_object_store/v1/account/
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//! Deletes the specified account when a reseller admin issues this request.
19//! Accounts are only deleted by (1) having a reseller admin level auth token
20//! (2) sending a DELETE to a proxy server for the account to be deleted and
21//! (3) that proxy server having the allow_account_management” config option
22//! set to true. Note that an issuing a DELETE request simply marks the account
23//! for deletion later as outlined in the link:
24//! https://docs.openstack.org/swift/latest/overview_reaper.html. Take care
25//! when performing this operation because deleting an account is a one-way
26//! operation that is not trivially recoverable. It''s crucial to note that in
27//! an OpenStack context, you should delete an account after the project/tenant
28//! has been deleted from Keystone.
29//!
30use derive_builder::Builder;
31use http::{HeaderMap, HeaderName, HeaderValue};
32
33use openstack_sdk_core::api::rest_endpoint_prelude::*;
34
35use std::borrow::Cow;
36
37#[derive(Builder, Debug, Clone)]
38#[builder(setter(strip_option))]
39pub struct Request<'a> {
40    /// The unique name for the account. An account is also known as the
41    /// project or tenant.
42    #[builder(default, setter(into))]
43    account: Cow<'a, str>,
44
45    #[builder(setter(name = "_headers"), default, private)]
46    _headers: Option<HeaderMap>,
47}
48impl<'a> Request<'a> {
49    /// Create a builder for the endpoint.
50    pub fn builder() -> RequestBuilder<'a> {
51        RequestBuilder::default()
52    }
53}
54
55impl<'a> RequestBuilder<'a> {
56    /// Add a single header to the Account.
57    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
58    where
59        K: Into<HeaderName>,
60        V: Into<HeaderValue>,
61    {
62        self._headers
63            .get_or_insert(None)
64            .get_or_insert_with(HeaderMap::new)
65            .insert(header_name.into(), header_value.into());
66        self
67    }
68
69    /// Add multiple headers.
70    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
71    where
72        I: Iterator<Item = T>,
73        T: Into<(Option<HeaderName>, HeaderValue)>,
74    {
75        self._headers
76            .get_or_insert(None)
77            .get_or_insert_with(HeaderMap::new)
78            .extend(iter.map(Into::into));
79        self
80    }
81}
82
83impl RestEndpoint for Request<'_> {
84    fn method(&self) -> http::Method {
85        http::Method::DELETE
86    }
87
88    fn endpoint(&self) -> Cow<'static, str> {
89        self.account.as_ref().to_string().into()
90    }
91
92    fn parameters(&self) -> QueryParams<'_> {
93        QueryParams::default()
94    }
95
96    fn service_type(&self) -> ServiceType {
97        ServiceType::ObjectStore
98    }
99
100    fn response_key(&self) -> Option<Cow<'static, str>> {
101        None
102    }
103
104    /// Returns headers to be set into the request
105    fn request_headers(&self) -> Option<&HeaderMap> {
106        self._headers.as_ref()
107    }
108
109    /// Returns required API version
110    fn api_version(&self) -> Option<ApiVersion> {
111        Some(ApiVersion::new(1, 0))
112    }
113}
114
115#[cfg(test)]
116mod tests {
117    use super::*;
118    use http::{HeaderName, HeaderValue};
119    use httpmock::MockServer;
120    #[cfg(feature = "sync")]
121    use openstack_sdk_core::api::Query;
122    use openstack_sdk_core::test::client::FakeOpenStackClient;
123    use openstack_sdk_core::types::ServiceType;
124    use serde_json::json;
125
126    #[test]
127    fn test_service_type() {
128        assert_eq!(
129            Request::builder().build().unwrap().service_type(),
130            ServiceType::ObjectStore
131        );
132    }
133
134    #[test]
135    fn test_response_key() {
136        assert!(Request::builder().build().unwrap().response_key().is_none())
137    }
138
139    #[cfg(feature = "sync")]
140    #[test]
141    fn endpoint() {
142        let server = MockServer::start();
143        let client = FakeOpenStackClient::new(server.base_url());
144        let mock = server.mock(|when, then| {
145            when.method(httpmock::Method::DELETE)
146                .path(format!("/{account}", account = "account",));
147
148            then.status(200)
149                .header("content-type", "application/json")
150                .json_body(json!({ "dummy": {} }));
151        });
152
153        let endpoint = Request::builder().account("account").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!("/{account}", account = "account",))
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            .account("account")
175            .headers(
176                [(
177                    Some(HeaderName::from_static("foo")),
178                    HeaderValue::from_static("bar"),
179                )]
180                .into_iter(),
181            )
182            .header(
183                HeaderName::from_static("not_foo"),
184                HeaderValue::from_static("not_bar"),
185            )
186            .build()
187            .unwrap();
188        let _: serde_json::Value = endpoint.query(&client).unwrap();
189        mock.assert();
190    }
191}