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`.

//! Show ServiceStatus command
//!
//! Wraps invoking of the `v2/service_statuses/{service_id}` with `GET` method

use clap::Args;
use eyre::{OptionExt, WrapErr};
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::dns::v2::service_status::get;
use openstack_types::dns::v2::service_status::response::get::ServiceStatusResponse;

/// Show the status of a service.
#[derive(Args)]
#[command(about = "Show a Service Status")]
pub struct ServiceStatusCommand {
    /// Request Query parameters
    #[command(flatten)]
    query: QueryParameters,

    /// Request Headers parameters
    #[command(flatten)]
    headers: HeaderParameters,

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

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

/// Header parameters
#[derive(Args)]
struct HeaderParameters {
    /// If enabled this will show results from all projects in Designate
    #[arg(long)]
    x_auth_all_projects: Option<bool>,

    /// This allows a user to impersonate another project
    #[arg(long)]
    x_auth_sudo_project_id: Option<String>,
}

/// Path parameters
#[derive(Args)]
struct PathParameters {
    /// service_id parameter for /v2/service_statuses/{service_id} API
    #[arg(
        help_heading = "Path parameters",
        id = "path_param_service_id",
        value_name = "SERVICE_ID"
    )]
    service_id: String,
}

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

        let op = OutputProcessor::from_args(parsed_args, Some("dns.service_status"), Some("show"));
        op.validate_args(parsed_args)?;

        let mut ep_builder = get::Request::builder();
        // Set path parameters
        ep_builder.service_id(&self.path.service_id);

        // Set header parameters
        if let Some(val) = &self.headers.x_auth_all_projects {
            ep_builder.header(
                http::header::HeaderName::from_static("x-auth-all-projects"),
                http::header::HeaderValue::from_static(if *val { "true" } else { "false" }),
            );
        }
        if let Some(val) = &self.headers.x_auth_sudo_project_id {
            ep_builder.header(
                http::header::HeaderName::from_static("x-auth-sudo-project-id"),
                http::header::HeaderValue::from_str(val)?,
            );
        }

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

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