Skip to main content

openstack_cli_network/v2/security_group/
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 SecurityGroup command
19//!
20//! Wraps invoking of the `v2.0/security-groups/{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::find;
32use openstack_sdk::api::network::v2::security_group::find;
33use openstack_types::network::v2::security_group::response;
34
35/// Shows details for a security group.
36///
37/// The associated security group rules are contained in the response.
38///
39/// Use the `fields` query parameter to control which fields are returned in
40/// the response body. For more information, see [Fields](#fields).
41///
42/// Normal response codes: 200
43///
44/// Error response codes: 401, 404
45#[derive(Args)]
46#[command(about = "Show security group")]
47pub struct SecurityGroupCommand {
48    /// Request Query parameters
49    #[command(flatten)]
50    query: QueryParameters,
51
52    /// Path parameters
53    #[command(flatten)]
54    path: PathParameters,
55}
56
57/// Query parameters
58#[derive(Args)]
59struct QueryParameters {}
60
61/// Path parameters
62#[derive(Args)]
63struct PathParameters {
64    /// id parameter for /v2.0/security-groups/{id} API
65    #[arg(
66        help_heading = "Path parameters",
67        id = "path_param_id",
68        value_name = "ID"
69    )]
70    id: String,
71}
72
73impl SecurityGroupCommand {
74    /// Perform command action
75    pub async fn take_action<C: CliArgs>(
76        &self,
77        parsed_args: &C,
78        client: &mut AsyncOpenStack,
79    ) -> Result<(), OpenStackCliError> {
80        info!("Show SecurityGroup");
81
82        let op =
83            OutputProcessor::from_args(parsed_args, Some("network.security_group"), Some("show"));
84        op.validate_args(parsed_args)?;
85
86        let mut find_builder = find::Request::builder();
87
88        find_builder.id(&self.path.id);
89
90        let find_ep = find_builder
91            .build()
92            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
93        let find_data: serde_json::Value = find(find_ep).query_async(client).await?;
94
95        op.output_single::<response::get::SecurityGroupResponse>(find_data.clone())?;
96        // Show command specific hints
97        op.show_command_hint()?;
98        Ok(())
99    }
100}