openstack_sdk/api/object_store/v1/account/
head.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//! Shows metadata for an account. Because the storage system can store large
19//! amounts of data, take care when you represent the total bytes response as
20//! an integer; when possible, convert it to a 64-bit unsigned integer if your
21//! platform supports that primitive type. Do not include metadata headers in
22//! this request.
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    /// The unique name for the account. An account is also known as the
35    /// project or tenant.
36    #[builder(default, setter(into))]
37    account: 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 Account.
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::HEAD
80    }
81
82    fn endpoint(&self) -> Cow<'static, str> {
83        self.account.as_ref().to_string().into()
84    }
85
86    fn parameters(&self) -> QueryParams<'_> {
87        QueryParams::default()
88    }
89
90    fn service_type(&self) -> ServiceType {
91        ServiceType::ObjectStore
92    }
93
94    fn response_key(&self) -> Option<Cow<'static, str>> {
95        None
96    }
97
98    /// Returns headers to be set into the request
99    fn request_headers(&self) -> Option<&HeaderMap> {
100        self._headers.as_ref()
101    }
102
103    /// Returns required API version
104    fn api_version(&self) -> Option<ApiVersion> {
105        Some(ApiVersion::new(1, 0))
106    }
107}
108
109#[cfg(test)]
110mod tests {
111    use super::*;
112    #[cfg(feature = "sync")]
113    use crate::api::RawQuery;
114    use crate::test::client::FakeOpenStackClient;
115    use crate::types::ServiceType;
116    use http::{HeaderName, HeaderValue};
117    use httpmock::MockServer;
118
119    #[test]
120    fn test_service_type() {
121        assert_eq!(
122            Request::builder().build().unwrap().service_type(),
123            ServiceType::ObjectStore
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::HEAD)
139                .path(format!("/{account}", account = "account",));
140
141            then.status(200).header("content-type", "application/json");
142        });
143
144        let endpoint = Request::builder().account("account").build().unwrap();
145        let _ = endpoint.raw_query(&client).unwrap();
146        mock.assert();
147    }
148
149    #[cfg(feature = "sync")]
150    #[test]
151    fn endpoint_headers() {
152        let server = MockServer::start();
153        let client = FakeOpenStackClient::new(server.base_url());
154        let mock = server.mock(|when, then| {
155            when.method(httpmock::Method::HEAD)
156                .path(format!("/{account}", account = "account",))
157                .header("foo", "bar")
158                .header("not_foo", "not_bar");
159            then.status(200).header("content-type", "application/json");
160        });
161
162        let endpoint = Request::builder()
163            .account("account")
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 _ = endpoint.raw_query(&client).unwrap();
178        mock.assert();
179    }
180}