Skip to main content

openstack_cli_dns/v2/limit/
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//! Get Limit command
19//!
20//! Wraps invoking of the `v2/limits` 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::limit::get;
32use openstack_types::dns::v2::limit::response;
33
34/// List project limits
35#[derive(Args)]
36#[command(about = "Get Project Limits")]
37pub struct LimitCommand {
38    /// Request Query parameters
39    #[command(flatten)]
40    query: QueryParameters,
41
42    /// Request Headers parameters
43    #[command(flatten)]
44    headers: HeaderParameters,
45
46    /// Path parameters
47    #[command(flatten)]
48    path: PathParameters,
49}
50
51/// Query parameters
52#[derive(Args)]
53struct QueryParameters {}
54
55/// Header parameters
56#[derive(Args)]
57struct HeaderParameters {
58    /// If enabled this will show results from all projects in Designate
59    #[arg(long)]
60    x_auth_all_projects: Option<bool>,
61
62    /// This allows a user to impersonate another project
63    #[arg(long)]
64    x_auth_sudo_project_id: Option<String>,
65}
66
67/// Path parameters
68#[derive(Args)]
69struct PathParameters {}
70
71impl LimitCommand {
72    /// Perform command action
73    pub async fn take_action<C: CliArgs>(
74        &self,
75        parsed_args: &C,
76        client: &mut AsyncOpenStack,
77    ) -> Result<(), OpenStackCliError> {
78        info!("Get Limit");
79
80        let op = OutputProcessor::from_args(parsed_args, Some("dns.limit"), Some("get"));
81        op.validate_args(parsed_args)?;
82
83        let mut ep_builder = get::Request::builder();
84        // Set path parameters
85
86        // Set header parameters
87        if let Some(val) = &self.headers.x_auth_all_projects {
88            ep_builder.header(
89                http::header::HeaderName::from_static("x-auth-all-projects"),
90                http::header::HeaderValue::from_static(if *val { "true" } else { "false" }),
91            );
92        }
93        if let Some(val) = &self.headers.x_auth_sudo_project_id {
94            ep_builder.header(
95                http::header::HeaderName::from_static("x-auth-sudo-project-id"),
96                http::header::HeaderValue::from_str(val)?,
97            );
98        }
99
100        let ep = ep_builder
101            .build()
102            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
103
104        let data: serde_json::Value = ep.query_async(client).await?;
105
106        op.output_single::<response::get::LimitResponse>(data.clone())?;
107        // Show command specific hints
108        op.show_command_hint()?;
109        Ok(())
110    }
111}