Skip to main content

openstack_cli_dns/v2/zone/
show.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//! Show Zone command
19//!
20//! Wraps invoking of the `v2/zones/{zone_id}` 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::zone::find;
32use openstack_sdk::api::find;
33use openstack_types::dns::v2::zone::response;
34
35/// Show a zone
36#[derive(Args)]
37#[command(about = "Show a Zone")]
38pub struct ZoneCommand {
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
52/// Query parameters
53#[derive(Args)]
54struct QueryParameters {}
55
56/// Header parameters
57#[derive(Args)]
58struct HeaderParameters {
59    /// If enabled this will show results from all projects in Designate
60    #[arg(long)]
61    x_auth_all_projects: Option<bool>,
62
63    /// This allows a user to impersonate another project
64    #[arg(long)]
65    x_auth_sudo_project_id: Option<String>,
66}
67
68/// Path parameters
69#[derive(Args)]
70struct PathParameters {
71    /// zone_id parameter for /v2/zones/{zone_id} API
72    #[arg(
73        help_heading = "Path parameters",
74        id = "path_param_id",
75        value_name = "ID"
76    )]
77    id: String,
78}
79
80impl ZoneCommand {
81    /// Perform command action
82    pub async fn take_action<C: CliArgs>(
83        &self,
84        parsed_args: &C,
85        client: &mut AsyncOpenStack,
86    ) -> Result<(), OpenStackCliError> {
87        info!("Show Zone");
88
89        let op = OutputProcessor::from_args(parsed_args, Some("dns.zone"), Some("show"));
90        op.validate_args(parsed_args)?;
91
92        let mut find_builder = find::Request::builder();
93
94        find_builder.id(&self.path.id);
95
96        if let Some(val) = &self.headers.x_auth_all_projects {
97            find_builder.header(
98                http::header::HeaderName::from_static("x-auth-all-projects"),
99                http::header::HeaderValue::from_static(if *val { "true" } else { "false" }),
100            );
101        }
102        if let Some(val) = &self.headers.x_auth_sudo_project_id {
103            find_builder.header(
104                http::header::HeaderName::from_static("x-auth-sudo-project-id"),
105                http::header::HeaderValue::from_str(val)?,
106            );
107        }
108        let find_ep = find_builder
109            .build()
110            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
111        let find_data: serde_json::Value = find(find_ep).query_async(client).await?;
112
113        op.output_single::<response::get::ZoneResponse>(find_data.clone())?;
114        // Show command specific hints
115        op.show_command_hint()?;
116        Ok(())
117    }
118}