Skip to main content

openstack_cli_dns/v2/recordset/
list.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//! List Recordsets command
19//!
20//! Wraps invoking of the `v2/recordsets` with `GET` method
21
22use clap::Args;
23use tracing::info;
24
25use openstack_cli_core::cli::CliArgs;
26use openstack_cli_core::error::OpenStackCliError;
27use openstack_cli_core::output::OutputProcessor;
28use openstack_sdk::AsyncOpenStack;
29
30use openstack_sdk::api::QueryAsync;
31use openstack_sdk::api::dns::v2::recordset::list;
32use openstack_sdk::api::{Pagination, paged};
33use openstack_types::dns::v2::recordset::response;
34
35/// This lists all recordsets owned by a project in Designate
36#[derive(Args)]
37#[command(about = "List all Recordsets owned by project")]
38pub struct RecordsetsCommand {
39    /// Request Query parameters
40    #[command(flatten)]
41    query: QueryParameters,
42
43    /// Request Headers parameters
44    #[command(flatten)]
45    headers: HeaderParameters,
46
47    /// Path parameters
48    #[command(flatten)]
49    path: PathParameters,
50
51    /// Total limit of entities count to return. Use this when there are too many entries.
52    #[arg(long, default_value_t = 10000)]
53    max_items: usize,
54}
55
56/// Query parameters
57#[derive(Args)]
58struct QueryParameters {
59    /// Filter results to only show zones that have a type matching the filter
60    #[arg(help_heading = "Query parameters", long, value_parser = ["CATALOG","PRIMARY","SECONDARY"])]
61    _type: Option<String>,
62
63    /// Filter results to only show recordsets that have a record with data
64    /// matching the filter
65    #[arg(help_heading = "Query parameters", long)]
66    data: Option<String>,
67
68    /// Filter results to only show zones that have a description matching the
69    /// filter
70    #[arg(help_heading = "Query parameters", long)]
71    description: Option<String>,
72
73    /// Requests a page size of items. Returns a number of items up to a limit
74    /// value. Use the limit parameter to make an initial limited request and
75    /// use the ID of the last-seen item from the response as the marker
76    /// parameter value in a subsequent limited request.
77    #[arg(
78        help_heading = "Query parameters",
79        long("page-size"),
80        visible_alias("limit")
81    )]
82    limit: Option<i32>,
83
84    /// The ID of the last-seen item. Use the limit parameter to make an
85    /// initial limited request and use the ID of the last-seen item from the
86    /// response as the marker parameter value in a subsequent limited request.
87    #[arg(help_heading = "Query parameters", long)]
88    marker: Option<String>,
89
90    /// Filter results to only show zones that have a name matching the filter
91    #[arg(help_heading = "Query parameters", long)]
92    name: Option<String>,
93
94    /// Sorts the response by the requested sort direction. A valid value is
95    /// asc (ascending) or desc (descending). Default is asc. You can specify
96    /// multiple pairs of sort key and sort direction query parameters. If you
97    /// omit the sort direction in a pair, the API uses the natural sorting
98    /// direction of the server attribute that is provided as the sort_key.
99    #[arg(help_heading = "Query parameters", long, value_parser = ["asc","desc"])]
100    sort_dir: Option<String>,
101
102    /// Sorts the response by the this attribute value. Default is id. You can
103    /// specify multiple pairs of sort key and sort direction query parameters.
104    /// If you omit the sort direction in a pair, the API uses the natural
105    /// sorting direction of the server attribute that is provided as the
106    /// sort_key.
107    #[arg(help_heading = "Query parameters", long, value_parser = ["created_at","id","name","serial","status","tenant_id","ttl","updated_at"])]
108    sort_key: Option<String>,
109
110    /// Filter results to only show zones that have a status matching the
111    /// filter
112    #[arg(help_heading = "Query parameters", long, value_parser = ["ACTIVE","DELETED","ERROR","PENDING","SUCCESS","ZONE"])]
113    status: Option<String>,
114
115    /// Filter results to only show zones that have a ttl matching the filter
116    #[arg(help_heading = "Query parameters", long)]
117    ttl: Option<i32>,
118
119    /// ID for the zone
120    #[arg(help_heading = "Query parameters", long)]
121    zone_id: Option<String>,
122}
123
124/// Header parameters
125#[derive(Args)]
126struct HeaderParameters {
127    /// If enabled this will show results from all projects in Designate
128    #[arg(long)]
129    x_auth_all_projects: Option<bool>,
130
131    /// This allows a user to impersonate another project
132    #[arg(long)]
133    x_auth_sudo_project_id: Option<String>,
134}
135
136/// Path parameters
137#[derive(Args)]
138struct PathParameters {}
139
140impl RecordsetsCommand {
141    /// Perform command action
142    pub async fn take_action<C: CliArgs>(
143        &self,
144        parsed_args: &C,
145        client: &mut AsyncOpenStack,
146    ) -> Result<(), OpenStackCliError> {
147        info!("List Recordsets");
148
149        let op = OutputProcessor::from_args(parsed_args, Some("dns.recordset"), Some("list"));
150        op.validate_args(parsed_args)?;
151
152        let mut ep_builder = list::Request::builder();
153        // Set path parameters
154        // Set query parameters
155        if let Some(val) = &self.query.data {
156            ep_builder.data(val);
157        }
158        if let Some(val) = &self.query.description {
159            ep_builder.description(val);
160        }
161        if let Some(val) = &self.query.limit {
162            ep_builder.limit(*val);
163        }
164        if let Some(val) = &self.query.marker {
165            ep_builder.marker(val);
166        }
167        if let Some(val) = &self.query.name {
168            ep_builder.name(val);
169        }
170        if let Some(val) = &self.query.sort_dir {
171            ep_builder.sort_dir(val);
172        }
173        if let Some(val) = &self.query.sort_key {
174            ep_builder.sort_key(val);
175        }
176        if let Some(val) = &self.query.status {
177            ep_builder.status(val);
178        }
179        if let Some(val) = &self.query.ttl {
180            ep_builder.ttl(*val);
181        }
182        if let Some(val) = &self.query._type {
183            ep_builder._type(val);
184        }
185        if let Some(val) = &self.query.zone_id {
186            ep_builder.zone_id(val);
187        }
188        // Set header parameters
189        if let Some(val) = &self.headers.x_auth_all_projects {
190            ep_builder.header(
191                http::header::HeaderName::from_static("x-auth-all-projects"),
192                http::header::HeaderValue::from_static(if *val { "true" } else { "false" }),
193            );
194        }
195        if let Some(val) = &self.headers.x_auth_sudo_project_id {
196            ep_builder.header(
197                http::header::HeaderName::from_static("x-auth-sudo-project-id"),
198                http::header::HeaderValue::from_str(val)?,
199            );
200        }
201
202        let ep = ep_builder
203            .build()
204            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
205
206        let data: Vec<serde_json::Value> = paged(ep, Pagination::Limit(self.max_items))
207            .query_async(client)
208            .await?;
209
210        op.output_list::<response::list::RecordsetResponse>(data.clone())?;
211        // Show command specific hints
212        op.show_command_hint()?;
213        Ok(())
214    }
215}