Skip to main content

openstack_cli_dns/v2/zone/
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 Zone command
19//!
20//! Wraps invoking of the `v2/zones/{zone_id}` with `PATCH` 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::zone::find;
32use openstack_sdk::api::dns::v2::zone::set;
33use openstack_sdk::api::find;
34use openstack_types::dns::v2::zone::response;
35
36/// Update the attribute(s) for an existing zone.
37#[derive(Args)]
38#[command(about = "Update a Zone")]
39pub struct ZoneCommand {
40    /// Request Query parameters
41    #[command(flatten)]
42    query: QueryParameters,
43
44    /// Path parameters
45    #[command(flatten)]
46    path: PathParameters,
47
48    /// Description for this zone
49    #[arg(help_heading = "Body parameters", long)]
50    description: Option<String>,
51
52    /// e-mail for the zone. Used in SOA records for the zone. Forbidden for
53    /// SECONDARY zones.
54    #[arg(help_heading = "Body parameters", long)]
55    email: Option<String>,
56
57    /// TTL (Time to Live) for the zone.
58    #[arg(help_heading = "Body parameters", long)]
59    ttl: Option<i32>,
60}
61
62/// Query parameters
63#[derive(Args)]
64struct QueryParameters {}
65
66/// Path parameters
67#[derive(Args)]
68struct PathParameters {
69    /// zone_id parameter for /v2/zones/{zone_id} API
70    #[arg(
71        help_heading = "Path parameters",
72        id = "path_param_id",
73        value_name = "ID"
74    )]
75    id: String,
76}
77
78impl ZoneCommand {
79    /// Perform command action
80    pub async fn take_action<C: CliArgs>(
81        &self,
82        parsed_args: &C,
83        client: &mut AsyncOpenStack,
84    ) -> Result<(), OpenStackCliError> {
85        info!("Set Zone");
86
87        let op = OutputProcessor::from_args(parsed_args, Some("dns.zone"), Some("set"));
88        op.validate_args(parsed_args)?;
89
90        let mut find_builder = find::Request::builder();
91
92        find_builder.id(&self.path.id);
93
94        let find_ep = find_builder
95            .build()
96            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
97        let find_data: serde_json::Value = find(find_ep).query_async(client).await?;
98
99        let mut ep_builder = set::Request::builder();
100
101        let resource_id = find_data["id"]
102            .as_str()
103            .ok_or_else(|| eyre::eyre!("resource ID must be a string"))?
104            .to_string();
105        ep_builder.id(resource_id.clone());
106
107        // Set body parameters
108        // Set Request.description data
109        if let Some(arg) = &self.description {
110            ep_builder.description(arg);
111        }
112
113        // Set Request.email data
114        if let Some(arg) = &self.email {
115            ep_builder.email(arg);
116        }
117
118        // Set Request.ttl data
119        if let Some(arg) = &self.ttl {
120            ep_builder.ttl(*arg);
121        }
122
123        let ep = ep_builder
124            .build()
125            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
126
127        let data: serde_json::Value = ep.query_async(client).await?;
128
129        op.output_single::<response::set::ZoneResponse>(data.clone())?;
130        // Show command specific hints
131        op.show_command_hint()?;
132        Ok(())
133    }
134}