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

//! Set IdentityProvider command
//!
//! Wraps invoking of the `v4/federation/identity_providers/{idp_id}` with `PUT` method

use clap::Args;
use eyre::WrapErr;
use tracing::info;

use openstack_sdk::AsyncOpenStack;

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

use crate::common::parse_key_val;
use openstack_sdk::api::QueryAsync;
use openstack_sdk::api::identity::v4::federation::identity_provider::set;
use openstack_types::identity::v4::federation::identity_provider::response::set::IdentityProviderResponse;
use serde_json::Value;

/// Updates the existing identity provider.
#[derive(Args)]
#[command(about = "Update single identity provider.")]
pub struct IdentityProviderCommand {
    /// Request Query parameters
    #[command(flatten)]
    query: QueryParameters,

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

    /// New identity provider data.
    #[command(flatten)]
    identity_provider: IdentityProvider,
}

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

/// Path parameters
#[derive(Args)]
struct PathParameters {
    /// The ID of the identity provider
    #[arg(
        help_heading = "Path parameters",
        id = "path_param_idp_id",
        value_name = "IDP_ID"
    )]
    idp_id: String,
}
/// IdentityProvider Body data
#[derive(Args, Clone)]
struct IdentityProvider {
    /// The new bound issuer that is verified when using the identity provider.
    #[arg(help_heading = "Body parameters", long)]
    bound_issuer: Option<String>,

    /// Set explicit NULL for the bound_issuer
    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "bound_issuer")]
    no_bound_issuer: bool,

    /// New default attribute mapping name which is automatically used when no
    /// mapping is explicitly requested. The referred attribute mapping must
    /// exist.
    #[arg(help_heading = "Body parameters", long)]
    default_mapping_name: Option<String>,

    /// Set explicit NULL for the default_mapping_name
    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "default_mapping_name")]
    no_default_mapping_name: bool,

    /// Identity provider `enabled` property. Inactive Identity Providers can
    /// not be used for login.
    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
    enabled: Option<Option<bool>>,

    /// New URL to fetch JsonWebKeySet. This must be set for "jwt" mapping when
    /// the provider does not provide discovery endpoint or when it is not
    /// standard compliant.
    #[arg(help_heading = "Body parameters", long)]
    jwks_url: Option<String>,

    /// Set explicit NULL for the jwks_url
    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "jwks_url")]
    no_jwks_url: bool,

    /// The list of the jwt validation public keys.
    ///
    /// Parameter is an array, may be provided multiple times.
    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)]
    jwt_validation_pubkeys: Option<Vec<String>>,

    /// The new name of the federated identity provider.
    #[arg(help_heading = "Body parameters", long)]
    name: Option<String>,

    /// Set explicit NULL for the name
    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "name")]
    no_name: bool,

    /// The new oidc `client_id` to use for the private client.
    #[arg(help_heading = "Body parameters", long)]
    oidc_client_id: Option<String>,

    /// Set explicit NULL for the oidc_client_id
    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "oidc_client_id")]
    no_oidc_client_id: bool,

    /// The new oidc `client_secret` to use for the private client.
    #[arg(help_heading = "Body parameters", long)]
    oidc_client_secret: Option<String>,

    /// Set explicit NULL for the oidc_client_secret
    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "oidc_client_secret")]
    no_oidc_client_secret: bool,

    /// The new OIDC discovery endpoint for the identity provider.
    #[arg(help_heading = "Body parameters", long)]
    oidc_discovery_url: Option<String>,

    /// Set explicit NULL for the oidc_discovery_url
    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "oidc_discovery_url")]
    no_oidc_discovery_url: bool,

    /// The new oidc response mode.
    #[arg(help_heading = "Body parameters", long)]
    oidc_response_mode: Option<String>,

    /// Set explicit NULL for the oidc_response_mode
    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "oidc_response_mode")]
    no_oidc_response_mode: bool,

    /// The new oidc response mode.
    ///
    /// Parameter is an array, may be provided multiple times.
    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)]
    oidc_response_types: Option<Vec<String>>,

    /// New additional provider configuration.
    #[arg(help_heading = "Body parameters", long, value_name="key=value", value_parser=parse_key_val::<String, Value>)]
    provider_config: Vec<(String, Value)>,
}

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

        let op = OutputProcessor::from_args(
            parsed_args,
            Some("identity.federation/identity_provider"),
            Some("set"),
        );
        op.validate_args(parsed_args)?;

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

        ep_builder.idp_id(&self.path.idp_id);

        // Set body parameters
        // Set Request.identity_provider data
        let args = &self.identity_provider;
        let mut identity_provider_builder = set::IdentityProviderBuilder::default();
        if let Some(val) = &args.bound_issuer {
            identity_provider_builder.bound_issuer(Some(val.into()));
        } else if args.no_bound_issuer {
            identity_provider_builder.bound_issuer(None);
        }

        if let Some(val) = &args.default_mapping_name {
            identity_provider_builder.default_mapping_name(Some(val.into()));
        } else if args.no_default_mapping_name {
            identity_provider_builder.default_mapping_name(None);
        }

        if let Some(val) = &args.enabled {
            identity_provider_builder.enabled(*val);
        }

        if let Some(val) = &args.jwks_url {
            identity_provider_builder.jwks_url(Some(val.into()));
        } else if args.no_jwks_url {
            identity_provider_builder.jwks_url(None);
        }

        if let Some(val) = &args.jwt_validation_pubkeys {
            identity_provider_builder
                .jwt_validation_pubkeys(val.iter().map(Into::into).collect::<Vec<_>>());
        }

        if let Some(val) = &args.name {
            identity_provider_builder.name(Some(val.into()));
        } else if args.no_name {
            identity_provider_builder.name(None);
        }

        if let Some(val) = &args.oidc_client_id {
            identity_provider_builder.oidc_client_id(Some(val.into()));
        } else if args.no_oidc_client_id {
            identity_provider_builder.oidc_client_id(None);
        }

        if let Some(val) = &args.oidc_client_secret {
            identity_provider_builder.oidc_client_secret(Some(val.into()));
        } else if args.no_oidc_client_secret {
            identity_provider_builder.oidc_client_secret(None);
        }

        if let Some(val) = &args.oidc_discovery_url {
            identity_provider_builder.oidc_discovery_url(Some(val.into()));
        } else if args.no_oidc_discovery_url {
            identity_provider_builder.oidc_discovery_url(None);
        }

        if let Some(val) = &args.oidc_response_mode {
            identity_provider_builder.oidc_response_mode(Some(val.into()));
        } else if args.no_oidc_response_mode {
            identity_provider_builder.oidc_response_mode(None);
        }

        if let Some(val) = &args.oidc_response_types {
            identity_provider_builder
                .oidc_response_types(val.iter().map(Into::into).collect::<Vec<_>>());
        }

        identity_provider_builder.provider_config(args.provider_config.iter().cloned());

        ep_builder.identity_provider(
            identity_provider_builder
                .build()
                .wrap_err("error preparing the request data")?,
        );

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

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