Skip to main content

openstack_sdk_object_store/v1/account/
get.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 details for an account and lists containers, sorted by name, in the
19//! account.
20//!
21use derive_builder::Builder;
22use http::{HeaderMap, HeaderName, HeaderValue};
23
24use openstack_sdk_core::api::rest_endpoint_prelude::*;
25
26use std::borrow::Cow;
27
28use openstack_sdk_core::api::Pageable;
29#[derive(Builder, Debug, Clone)]
30#[builder(setter(strip_option))]
31pub struct Request<'a> {
32    /// The unique name for the account. An account is also known as the
33    /// project or tenant.
34    #[builder(default, setter(into))]
35    account: Cow<'a, str>,
36
37    /// The delimiter is a single character used to split object names to
38    /// present a pseudo-directory hierarchy of objects. When combined with a
39    /// prefix query, this enables API users to simulate and traverse the
40    /// objects in a container as if they were in a directory tree.
41    #[builder(default, setter(into))]
42    delimiter: Option<Cow<'a, str>>,
43
44    /// For a string value, x, constrains the list to items whose names are
45    /// less than x.
46    #[builder(default, setter(into))]
47    end_marker: Option<Cow<'a, str>>,
48
49    /// The response format. Valid values are json, xml, or plain. The default
50    /// is plain. If you append the format=xml or format=json query parameter
51    /// to the storage account URL, the response shows extended container
52    /// information serialized in that format. If you append the format=plain
53    /// query parameter, the response lists the container names separated by
54    /// newlines.
55    #[builder(default, setter(into))]
56    format: Option<Cow<'a, str>>,
57
58    /// For an integer value n, limits the number of results to n.
59    #[builder(default)]
60    limit: Option<u32>,
61
62    /// For a string value, x, constrains the list to items whose names are
63    /// greater than x.
64    #[builder(default, setter(into))]
65    marker: Option<Cow<'a, str>>,
66
67    /// Only objects with this prefix will be returned. When combined with a
68    /// delimiter query, this enables API users to simulate and traverse the
69    /// objects in a container as if they were in a directory tree.
70    #[builder(default, setter(into))]
71    prefix: Option<Cow<'a, str>>,
72
73    /// By default, listings are returned sorted by name, ascending. If you
74    /// include the reverse=true query parameter, the listing will be returned
75    /// sorted by name, descending.
76    #[builder(default)]
77    reverse: Option<bool>,
78
79    #[builder(setter(name = "_headers"), default, private)]
80    _headers: Option<HeaderMap>,
81}
82impl<'a> Request<'a> {
83    /// Create a builder for the endpoint.
84    pub fn builder() -> RequestBuilder<'a> {
85        RequestBuilder::default()
86    }
87}
88
89impl<'a> RequestBuilder<'a> {
90    /// Add a single header to the Account.
91    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
92    where
93        K: Into<HeaderName>,
94        V: Into<HeaderValue>,
95    {
96        self._headers
97            .get_or_insert(None)
98            .get_or_insert_with(HeaderMap::new)
99            .insert(header_name.into(), header_value.into());
100        self
101    }
102
103    /// Add multiple headers.
104    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
105    where
106        I: Iterator<Item = T>,
107        T: Into<(Option<HeaderName>, HeaderValue)>,
108    {
109        self._headers
110            .get_or_insert(None)
111            .get_or_insert_with(HeaderMap::new)
112            .extend(iter.map(Into::into));
113        self
114    }
115}
116
117impl RestEndpoint for Request<'_> {
118    fn method(&self) -> http::Method {
119        http::Method::GET
120    }
121
122    fn endpoint(&self) -> Cow<'static, str> {
123        self.account.as_ref().to_string().into()
124    }
125
126    fn parameters(&self) -> QueryParams<'_> {
127        let mut params = QueryParams::default();
128        params.push_opt("limit", self.limit);
129        params.push_opt("marker", self.marker.as_ref());
130        params.push_opt("end_marker", self.end_marker.as_ref());
131        params.push_opt("format", self.format.as_ref());
132        params.push_opt("prefix", self.prefix.as_ref());
133        params.push_opt("delimiter", self.delimiter.as_ref());
134        params.push_opt("reverse", self.reverse);
135
136        params
137    }
138
139    fn service_type(&self) -> ServiceType {
140        ServiceType::ObjectStore
141    }
142
143    fn response_key(&self) -> Option<Cow<'static, str>> {
144        None
145    }
146
147    /// Returns headers to be set into the request
148    fn request_headers(&self) -> Option<&HeaderMap> {
149        self._headers.as_ref()
150    }
151
152    /// Returns required API version
153    fn api_version(&self) -> Option<ApiVersion> {
154        Some(ApiVersion::new(1, 0))
155    }
156}
157impl Pageable for Request<'_> {
158    fn use_keyset_pagination(&self) -> bool {
159        false
160    }
161}
162
163#[cfg(test)]
164mod tests {
165    use super::*;
166    use http::{HeaderName, HeaderValue};
167    use httpmock::MockServer;
168    #[cfg(feature = "sync")]
169    use openstack_sdk_core::api::Query;
170    use openstack_sdk_core::test::client::FakeOpenStackClient;
171    use openstack_sdk_core::types::ServiceType;
172    use serde_json::json;
173
174    #[test]
175    fn test_service_type() {
176        assert_eq!(
177            Request::builder().build().unwrap().service_type(),
178            ServiceType::ObjectStore
179        );
180    }
181
182    #[test]
183    fn test_response_key() {
184        assert!(Request::builder().build().unwrap().response_key().is_none())
185    }
186
187    #[cfg(feature = "sync")]
188    #[test]
189    fn endpoint() {
190        let server = MockServer::start();
191        let client = FakeOpenStackClient::new(server.base_url());
192        let mock = server.mock(|when, then| {
193            when.method(httpmock::Method::GET)
194                .path(format!("/{account}", account = "account",));
195
196            then.status(200)
197                .header("content-type", "application/json")
198                .json_body(json!({ "dummy": {} }));
199        });
200
201        let endpoint = Request::builder().account("account").build().unwrap();
202        let _: serde_json::Value = endpoint.query(&client).unwrap();
203        mock.assert();
204    }
205
206    #[cfg(feature = "sync")]
207    #[test]
208    fn endpoint_headers() {
209        let server = MockServer::start();
210        let client = FakeOpenStackClient::new(server.base_url());
211        let mock = server.mock(|when, then| {
212            when.method(httpmock::Method::GET)
213                .path(format!("/{account}", account = "account",))
214                .header("foo", "bar")
215                .header("not_foo", "not_bar");
216            then.status(200)
217                .header("content-type", "application/json")
218                .json_body(json!({ "dummy": {} }));
219        });
220
221        let endpoint = Request::builder()
222            .account("account")
223            .headers(
224                [(
225                    Some(HeaderName::from_static("foo")),
226                    HeaderValue::from_static("bar"),
227                )]
228                .into_iter(),
229            )
230            .header(
231                HeaderName::from_static("not_foo"),
232                HeaderValue::from_static("not_bar"),
233            )
234            .build()
235            .unwrap();
236        let _: serde_json::Value = endpoint.query(&client).unwrap();
237        mock.assert();
238    }
239}