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

//! List Endpoints command
//!
//! Wraps invoking of the `v3/endpoints` with `GET` 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::identity::v3::endpoint::list;
use openstack_types::identity::v3::endpoint::response::list::EndpointResponse;

/// Lists all available endpoints.
///
/// Relationship:
/// `https://docs.openstack.org/api/openstack-identity/3/rel/endpoints`
#[derive(Args)]
#[command(about = "List endpoints")]
pub struct EndpointsCommand {
    /// Request Query parameters
    #[command(flatten)]
    query: QueryParameters,

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

/// Query parameters
#[derive(Args)]
struct QueryParameters {
    /// The interface type, which describes the visibility of the endpoint.
    /// Value is: -public. Visible by end users on a publicly available network
    /// interface. -internal. Visible by end users on an unmetered internal
    /// network interface.-admin. Visible by administrative users on a secure
    /// network interface.
    #[arg(help_heading = "Query parameters", long, value_parser = ["admin","internal","public"])]
    interface: Option<String>,

    /// (Since v3.2) The ID of the region that contains the service endpoint.
    #[arg(help_heading = "Query parameters", long)]
    region_id: Option<String>,

    /// The UUID of the service to which the endpoint belongs
    #[arg(help_heading = "Query parameters", long)]
    service_id: Option<String>,
}

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

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

        let op = OutputProcessor::from_args(parsed_args, Some("identity.endpoint"), Some("list"));
        op.validate_args(parsed_args)?;

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

        // Set query parameters
        if let Some(val) = &self.query.interface {
            ep_builder.interface(val);
        }
        if let Some(val) = &self.query.region_id {
            ep_builder.region_id(val);
        }
        if let Some(val) = &self.query.service_id {
            ep_builder.service_id(val);
        }

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

        let data: Vec<serde_json::Value> = ep.query_async(client).await?;
        op.output_list::<EndpointResponse>(data)?;
        // Show command specific hints
        op.show_command_hint()?;
        Ok(())
    }
}