Skip to main content

openstack_cli_network/v2/rbac_policy/
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 RbacPolicy command
19//!
20//! Wraps invoking of the `v2.0/rbac-policies/{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::rbac_policy::set;
33use openstack_types::network::v2::rbac_policy::response;
34
35/// Update RBAC policy for given tenant.
36///
37/// Normal response codes: 200
38///
39/// Error response codes: 400, 401, 403, 404
40#[derive(Args)]
41#[command(about = "Update RBAC policy")]
42pub struct RbacPolicyCommand {
43    /// Request Query parameters
44    #[command(flatten)]
45    query: QueryParameters,
46
47    /// Path parameters
48    #[command(flatten)]
49    path: PathParameters,
50
51    #[command(flatten)]
52    rbac_policy: RbacPolicy,
53}
54
55/// Query parameters
56#[derive(Args)]
57struct QueryParameters {}
58
59/// Path parameters
60#[derive(Args)]
61struct PathParameters {
62    /// id parameter for /v2.0/rbac-policies/{id} API
63    #[arg(
64        help_heading = "Path parameters",
65        id = "path_param_id",
66        value_name = "ID"
67    )]
68    id: String,
69}
70/// RbacPolicy Body data
71#[derive(Args, Clone)]
72struct RbacPolicy {
73    /// The ID of the tenant to which the RBAC policy will be enforced. Please
74    /// note that Neutron does not perform any type of validation that the
75    /// value provided is actually the ID of the existing project. If, for
76    /// example, the name of the project is provided here, it will be accepted
77    /// by the Neutron API, but the RBAC rule created will not work as
78    /// expected.
79    #[arg(help_heading = "Body parameters", long)]
80    target_tenant: Option<String>,
81}
82
83impl RbacPolicyCommand {
84    /// Perform command action
85    pub async fn take_action<C: CliArgs>(
86        &self,
87        parsed_args: &C,
88        client: &mut AsyncOpenStack,
89    ) -> Result<(), OpenStackCliError> {
90        info!("Set RbacPolicy");
91
92        let op = OutputProcessor::from_args(parsed_args, Some("network.rbac_policy"), Some("set"));
93        op.validate_args(parsed_args)?;
94
95        let mut ep_builder = set::Request::builder();
96
97        ep_builder.id(&self.path.id);
98
99        // Set body parameters
100        // Set Request.rbac_policy data
101        let args = &self.rbac_policy;
102        let mut rbac_policy_builder = set::RbacPolicyBuilder::default();
103        if let Some(val) = &args.target_tenant {
104            rbac_policy_builder.target_tenant(val);
105        }
106
107        ep_builder.rbac_policy(
108            rbac_policy_builder
109                .build()
110                .wrap_err("error preparing the request data")?,
111        );
112
113        let ep = ep_builder
114            .build()
115            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
116
117        let data: serde_json::Value = ep.query_async(client).await?;
118
119        op.output_single::<response::set::RbacPolicyResponse>(data.clone())?;
120        // Show command specific hints
121        op.show_command_hint()?;
122        Ok(())
123    }
124}