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 RequestBuilder<'_> {
50    /// Add a single header to the Account.
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::HEAD
77    }
78
79    fn endpoint(&self) -> Cow<'static, str> {
80        self.account.as_ref().to_string().into()
81    }
82
83    fn parameters(&self) -> QueryParams {
84        QueryParams::default()
85    }
86
87    fn service_type(&self) -> ServiceType {
88        ServiceType::ObjectStore
89    }
90
91    fn response_key(&self) -> Option<Cow<'static, str>> {
92        None
93    }
94
95    /// Returns headers to be set into the request
96    fn request_headers(&self) -> Option<&HeaderMap> {
97        self._headers.as_ref()
98    }
99
100    /// Returns required API version
101    fn api_version(&self) -> Option<ApiVersion> {
102        Some(ApiVersion::new(1, 0))
103    }
104}
105
106#[cfg(test)]
107mod tests {
108    use super::*;
109    #[cfg(feature = "sync")]
110    use crate::api::RawQuery;
111    use crate::test::client::FakeOpenStackClient;
112    use crate::types::ServiceType;
113    use http::{HeaderName, HeaderValue};
114    use httpmock::MockServer;
115
116    #[test]
117    fn test_service_type() {
118        assert_eq!(
119            Request::builder().build().unwrap().service_type(),
120            ServiceType::ObjectStore
121        );
122    }
123
124    #[test]
125    fn test_response_key() {
126        assert!(Request::builder().build().unwrap().response_key().is_none())
127    }
128
129    #[cfg(feature = "sync")]
130    #[test]
131    fn endpoint() {
132        let server = MockServer::start();
133        let client = FakeOpenStackClient::new(server.base_url());
134        let mock = server.mock(|when, then| {
135            when.method(httpmock::Method::HEAD)
136                .path(format!("/{account}", account = "account",));
137
138            then.status(200).header("content-type", "application/json");
139        });
140
141        let endpoint = Request::builder().account("account").build().unwrap();
142        let _ = endpoint.raw_query(&client).unwrap();
143        mock.assert();
144    }
145
146    #[cfg(feature = "sync")]
147    #[test]
148    fn endpoint_headers() {
149        let server = MockServer::start();
150        let client = FakeOpenStackClient::new(server.base_url());
151        let mock = server.mock(|when, then| {
152            when.method(httpmock::Method::HEAD)
153                .path(format!("/{account}", account = "account",))
154                .header("foo", "bar")
155                .header("not_foo", "not_bar");
156            then.status(200).header("content-type", "application/json");
157        });
158
159        let endpoint = Request::builder()
160            .account("account")
161            .headers(
162                [(
163                    Some(HeaderName::from_static("foo")),
164                    HeaderValue::from_static("bar"),
165                )]
166                .into_iter(),
167            )
168            .header("not_foo", "not_bar")
169            .build()
170            .unwrap();
171        let _ = endpoint.raw_query(&client).unwrap();
172        mock.assert();
173    }
174}