Skip to main content

openstack_sdk_load_balancer/v2/pool/member/
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::pool::member::{get as Get, list as List};
25
26/// Find for pool/member 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    #[builder(default, setter(into))]
33    pool_id: Cow<'a, str>,
34
35    #[builder(setter(name = "_headers"), default, private)]
36    _headers: Option<HeaderMap>,
37}
38
39impl<'a> Request<'a> {
40    /// Create a builder for the endpoint.
41    pub fn builder() -> RequestBuilder<'a> {
42        RequestBuilder::default()
43    }
44}
45
46impl<'a> RequestBuilder<'a> {
47    /// Add a single header to the Volume.
48    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
49    where
50        K: Into<HeaderName>,
51        V: Into<HeaderValue>,
52    {
53        self._headers
54            .get_or_insert(None)
55            .get_or_insert_with(HeaderMap::new)
56            .insert(header_name.into(), header_value.into());
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<'a> Findable for Request<'a> {
75    type G = Get::Request<'a>;
76    type L = List::Request<'a>;
77    fn get_ep<C: RestClient>(&self) -> Result<Get::Request<'a>, ApiError<C::Error>> {
78        let mut ep = Get::Request::builder();
79        ep.id(self.id.clone());
80        ep.pool_id(self.pool_id.clone());
81        if let Some(headers) = &self._headers {
82            ep.headers(headers.iter().map(|(k, v)| (Some(k.clone()), v.clone())));
83        }
84        ep.build().map_err(ApiError::endpoint_builder)
85    }
86
87    fn list_ep<C: RestClient>(&self) -> Result<List::Request<'a>, ApiError<C::Error>> {
88        let mut ep = List::Request::builder();
89        ep.pool_id(self.pool_id.clone());
90        if let Some(headers) = &self._headers {
91            ep.headers(headers.iter().map(|(k, v)| (Some(k.clone()), v.clone())));
92        }
93        ep.name(self.id.clone());
94        ep.build().map_err(ApiError::endpoint_builder)
95    }
96}