Skip to main content

openstack_cli_compute/v2/keypair/
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 Keypair command
19//!
20//! Wraps invoking of the `v2.1/os-keypairs/{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::compute::v2::keypair::find;
32use openstack_sdk::api::find;
33use openstack_types::compute::v2::keypair::response;
34
35/// Shows details for a keypair that is associated with the account.
36///
37/// Normal response codes: 200
38///
39/// Error response codes: unauthorized(401), forbidden(403), itemNotFound(404)
40#[derive(Args)]
41#[command(about = "Show Keypair Details")]
42pub struct KeypairCommand {
43    /// Request Query parameters
44    #[command(flatten)]
45    query: QueryParameters,
46
47    /// Path parameters
48    #[command(flatten)]
49    path: PathParameters,
50}
51
52/// Query parameters
53#[derive(Args)]
54struct QueryParameters {
55    /// User resource for which the operation should be performed.
56    #[command(flatten)]
57    user: UserInput,
58}
59
60/// User input select group
61#[derive(Args)]
62#[group(required = false, multiple = false)]
63struct UserInput {
64    /// User Name.
65    #[arg(long, help_heading = "Path parameters", value_name = "USER_NAME")]
66    user_name: Option<String>,
67    /// User ID.
68    #[arg(long, help_heading = "Path parameters", value_name = "USER_ID")]
69    user_id: Option<String>,
70    /// Current authenticated user.
71    #[arg(long, help_heading = "Path parameters", action = clap::ArgAction::SetTrue)]
72    current_user: bool,
73}
74
75/// Path parameters
76#[derive(Args)]
77struct PathParameters {
78    /// id parameter for /v2.1/os-keypairs/{id} API
79    #[arg(
80        help_heading = "Path parameters",
81        id = "path_param_id",
82        value_name = "ID"
83    )]
84    id: String,
85}
86
87impl KeypairCommand {
88    /// Perform command action
89    pub async fn take_action<C: CliArgs>(
90        &self,
91        parsed_args: &C,
92        client: &mut AsyncOpenStack,
93    ) -> Result<(), OpenStackCliError> {
94        info!("Show Keypair");
95
96        let op = OutputProcessor::from_args(parsed_args, Some("compute.keypair"), Some("show"));
97        op.validate_args(parsed_args)?;
98
99        let mut find_builder = find::Request::builder();
100
101        find_builder.id(&self.path.id);
102
103        let find_ep = find_builder
104            .build()
105            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
106        let find_data: serde_json::Value = find(find_ep).query_async(client).await?;
107
108        op.output_single::<response::get_20::KeypairResponse>(find_data.clone())
109            .or_else(|_| {
110                op.output_single::<response::get_22::KeypairResponse>(find_data.clone())
111            })?;
112        // Show command specific hints
113        op.show_command_hint()?;
114        Ok(())
115    }
116}