openstack_cli 0.13.5

OpenStack client rewritten in Rust
Documentation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
//
// WARNING: This file is automatically generated from OpenAPI schema using
// `openstack-codegenerator`.

//! Create Certificate command
//!
//! Wraps invoking of the `v1/certificates` with `POST` method

use clap::Args;
use tracing::info;

use openstack_sdk::AsyncOpenStack;

use crate::Cli;
use crate::OpenStackCliError;
use crate::output::OutputProcessor;

use openstack_sdk::api::QueryAsync;
use openstack_sdk::api::container_infrastructure_management::v1::certificate::create;
use openstack_types::container_infrastructure_management::v1::certificate::response::create::CertificateResponse;
use serde_json::Value;

/// Sign a new certificate by the CA.
///
/// | param certificate: | | | --- | --- | | | a certificate within the request
/// body. |
#[derive(Args)]
pub struct CertificateCommand {
    /// Request Query parameters
    #[command(flatten)]
    query: QueryParameters,

    /// Path parameters
    #[command(flatten)]
    path: PathParameters,

    #[arg(help_heading = "Body parameters", long)]
    ca_cert_type: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    cluster_uuid: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    created_at: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    csr: Option<String>,

    /// Parameter is an array, may be provided multiple times.
    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long, value_name="JSON", value_parser=crate::common::parse_json)]
    links: Option<Vec<Value>>,

    #[arg(help_heading = "Body parameters", long)]
    pem: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    updated_at: Option<String>,
}

/// Query parameters
#[derive(Args)]
struct QueryParameters {}

/// Path parameters
#[derive(Args)]
struct PathParameters {}

impl CertificateCommand {
    /// Perform command action
    pub async fn take_action(
        &self,
        parsed_args: &Cli,
        client: &mut AsyncOpenStack,
    ) -> Result<(), OpenStackCliError> {
        info!("Create Certificate");

        let op = OutputProcessor::from_args(
            parsed_args,
            Some("container-infrastructure-management.certificate"),
            Some("create"),
        );
        op.validate_args(parsed_args)?;

        let mut ep_builder = create::Request::builder();

        // Set body parameters
        // Set Request.ca_cert_type data
        if let Some(arg) = &self.ca_cert_type {
            ep_builder.ca_cert_type(arg);
        }

        // Set Request.cluster_uuid data
        if let Some(arg) = &self.cluster_uuid {
            ep_builder.cluster_uuid(arg);
        }

        // Set Request.created_at data
        if let Some(arg) = &self.created_at {
            ep_builder.created_at(arg);
        }

        // Set Request.csr data
        if let Some(arg) = &self.csr {
            ep_builder.csr(arg);
        }

        // Set Request.links data
        if let Some(arg) = &self.links {
            let links_builder: Vec<create::Links> = arg
                .iter()
                .flat_map(|v| serde_json::from_value::<create::Links>(v.to_owned()))
                .collect::<Vec<create::Links>>();
            ep_builder.links(links_builder);
        }

        // Set Request.pem data
        if let Some(arg) = &self.pem {
            ep_builder.pem(arg);
        }

        // Set Request.updated_at data
        if let Some(arg) = &self.updated_at {
            ep_builder.updated_at(arg);
        }

        let ep = ep_builder
            .build()
            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;

        let data = ep.query_async(client).await?;
        op.output_single::<CertificateResponse>(data)?;
        // Show command specific hints
        op.show_command_hint()?;
        Ok(())
    }
}