Skip to main content

openstack_sdk_load_balancer/v2/availability_zone_profile/
find.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`.
17use derive_builder::Builder;
18use http::{HeaderMap, HeaderName, HeaderValue};
19
20use openstack_sdk_core::api::Findable;
21use openstack_sdk_core::api::rest_endpoint_prelude::*;
22use openstack_sdk_core::api::{ApiError, RestClient};
23
24use crate::v2::availability_zone_profile::{get as Get, list as List};
25
26/// Find for availability_zone_profile by nameOrId.
27#[derive(Debug, Builder, Clone)]
28#[builder(setter(strip_option))]
29pub struct Request<'a> {
30    #[builder(setter(into), default)]
31    id: Cow<'a, str>,
32
33    #[builder(setter(name = "_headers"), default, private)]
34    _headers: Option<HeaderMap>,
35}
36
37impl<'a> Request<'a> {
38    /// Create a builder for the endpoint.
39    pub fn builder() -> RequestBuilder<'a> {
40        RequestBuilder::default()
41    }
42}
43
44impl<'a> RequestBuilder<'a> {
45    /// Add a single header to the Volume.
46    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
47    where
48        K: Into<HeaderName>,
49        V: Into<HeaderValue>,
50    {
51        self._headers
52            .get_or_insert(None)
53            .get_or_insert_with(HeaderMap::new)
54            .insert(header_name.into(), header_value.into());
55        self
56    }
57
58    /// Add multiple headers.
59    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
60    where
61        I: Iterator<Item = T>,
62        T: Into<(Option<HeaderName>, HeaderValue)>,
63    {
64        self._headers
65            .get_or_insert(None)
66            .get_or_insert_with(HeaderMap::new)
67            .extend(iter.map(Into::into));
68        self
69    }
70}
71
72impl<'a> Findable for Request<'a> {
73    type G = Get::Request<'a>;
74    type L = List::Request<'a>;
75    fn get_ep<C: RestClient>(&self) -> Result<Get::Request<'a>, ApiError<C::Error>> {
76        let mut ep = Get::Request::builder();
77        ep.id(self.id.clone());
78        if let Some(headers) = &self._headers {
79            ep.headers(headers.iter().map(|(k, v)| (Some(k.clone()), v.clone())));
80        }
81        ep.build().map_err(ApiError::endpoint_builder)
82    }
83
84    fn list_ep<C: RestClient>(&self) -> Result<List::Request<'a>, ApiError<C::Error>> {
85        let mut ep = List::Request::builder();
86        if let Some(headers) = &self._headers {
87            ep.headers(headers.iter().map(|(k, v)| (Some(k.clone()), v.clone())));
88        }
89        ep.name(self.id.clone());
90        ep.build().map_err(ApiError::endpoint_builder)
91    }
92}