Skip to main content

openstack_cli_network/v2/vpn/endpoint_group/
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 EndpointGroup command
19//!
20//! Wraps invoking of the `v2.0/vpn/endpoint-groups/{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::find;
33use openstack_sdk::api::network::v2::vpn::endpoint_group::find;
34use openstack_sdk::api::network::v2::vpn::endpoint_group::set;
35use openstack_types::network::v2::vpn::endpoint_group::response;
36
37/// Updates settings for a VPN endpoint group.
38///
39/// Normal response codes: 200
40///
41/// Error response codes: 400, 401, 404
42#[derive(Args)]
43#[command(about = "Update VPN endpoint group")]
44pub struct EndpointGroupCommand {
45    /// Request Query parameters
46    #[command(flatten)]
47    query: QueryParameters,
48
49    /// Path parameters
50    #[command(flatten)]
51    path: PathParameters,
52
53    #[command(flatten)]
54    endpoint_group: EndpointGroup,
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/vpn/endpoint-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/// EndpointGroup Body data
73#[derive(Args, Clone)]
74struct EndpointGroup {
75    /// A human-readable description for the resource. Default is an empty
76    /// string.
77    #[arg(help_heading = "Body parameters", long)]
78    description: Option<String>,
79
80    /// Human-readable name of the resource. Default is an empty string.
81    #[arg(help_heading = "Body parameters", long)]
82    name: Option<String>,
83}
84
85impl EndpointGroupCommand {
86    /// Perform command action
87    pub async fn take_action<C: CliArgs>(
88        &self,
89        parsed_args: &C,
90        client: &mut AsyncOpenStack,
91    ) -> Result<(), OpenStackCliError> {
92        info!("Set EndpointGroup");
93
94        let op = OutputProcessor::from_args(
95            parsed_args,
96            Some("network.vpn/endpoint_group"),
97            Some("set"),
98        );
99        op.validate_args(parsed_args)?;
100
101        let mut find_builder = find::Request::builder();
102
103        find_builder.id(&self.path.id);
104
105        let find_ep = find_builder
106            .build()
107            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
108        let find_data: serde_json::Value = find(find_ep).query_async(client).await?;
109
110        let mut ep_builder = set::Request::builder();
111
112        let resource_id = find_data["id"]
113            .as_str()
114            .ok_or_else(|| eyre::eyre!("resource ID must be a string"))?
115            .to_string();
116        ep_builder.id(resource_id.clone());
117
118        // Set body parameters
119        // Set Request.endpoint_group data
120        let args = &self.endpoint_group;
121        let mut endpoint_group_builder = set::EndpointGroupBuilder::default();
122        if let Some(val) = &args.description {
123            endpoint_group_builder.description(val);
124        }
125
126        if let Some(val) = &args.name {
127            endpoint_group_builder.name(val);
128        }
129
130        ep_builder.endpoint_group(
131            endpoint_group_builder
132                .build()
133                .wrap_err("error preparing the request data")?,
134        );
135
136        let ep = ep_builder
137            .build()
138            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
139
140        let data: serde_json::Value = ep.query_async(client).await?;
141
142        op.output_single::<response::set::EndpointGroupResponse>(data.clone())?;
143        // Show command specific hints
144        op.show_command_hint()?;
145        Ok(())
146    }
147}