Skip to main content

openstack_cli_network/v2/security_group_rule/
set.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//! Set SecurityGroupRule command
19//!
20//! Wraps invoking of the `v2.0/security-group-rules/{id}` with `PUT` method
21
22use clap::Args;
23use eyre::WrapErr;
24use tracing::info;
25
26use openstack_cli_core::cli::CliArgs;
27use openstack_cli_core::error::OpenStackCliError;
28use openstack_cli_core::output::OutputProcessor;
29use openstack_sdk::AsyncOpenStack;
30
31use openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::network::v2::security_group_rule::set;
33use openstack_types::network::v2::security_group_rule::response;
34
35/// Command without description in OpenAPI
36#[derive(Args)]
37pub struct SecurityGroupRuleCommand {
38    /// Request Query parameters
39    #[command(flatten)]
40    query: QueryParameters,
41
42    /// Path parameters
43    #[command(flatten)]
44    path: PathParameters,
45
46    #[command(flatten)]
47    security_group_rule: SecurityGroupRule,
48}
49
50/// Query parameters
51#[derive(Args)]
52struct QueryParameters {}
53
54/// Path parameters
55#[derive(Args)]
56struct PathParameters {
57    /// id parameter for /v2.0/security-group-rules/{id} API
58    #[arg(
59        help_heading = "Path parameters",
60        id = "path_param_id",
61        value_name = "ID"
62    )]
63    id: String,
64}
65/// SecurityGroupRule Body data
66#[derive(Args, Clone)]
67struct SecurityGroupRule {
68    #[arg(help_heading = "Body parameters", long)]
69    description: Option<String>,
70}
71
72impl SecurityGroupRuleCommand {
73    /// Perform command action
74    pub async fn take_action<C: CliArgs>(
75        &self,
76        parsed_args: &C,
77        client: &mut AsyncOpenStack,
78    ) -> Result<(), OpenStackCliError> {
79        info!("Set SecurityGroupRule");
80
81        let op = OutputProcessor::from_args(
82            parsed_args,
83            Some("network.security_group_rule"),
84            Some("set"),
85        );
86        op.validate_args(parsed_args)?;
87
88        let mut ep_builder = set::Request::builder();
89
90        ep_builder.id(&self.path.id);
91
92        // Set body parameters
93        // Set Request.security_group_rule data
94        let args = &self.security_group_rule;
95        let mut security_group_rule_builder = set::SecurityGroupRuleBuilder::default();
96        if let Some(val) = &args.description {
97            security_group_rule_builder.description(val);
98        }
99
100        ep_builder.security_group_rule(
101            security_group_rule_builder
102                .build()
103                .wrap_err("error preparing the request data")?,
104        );
105
106        let ep = ep_builder
107            .build()
108            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
109
110        let data: serde_json::Value = ep.query_async(client).await?;
111
112        op.output_single::<response::set::SecurityGroupRuleResponse>(data.clone())?;
113        // Show command specific hints
114        op.show_command_hint()?;
115        Ok(())
116    }
117}