|
| 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 | +//! Create IdentityProvider command |
| 19 | +//! |
| 20 | +//! Wraps invoking of the `v4/federation/identity_providers` with `POST` method |
| 21 | +
|
| 22 | +use clap::Args; |
| 23 | +use tracing::info; |
| 24 | + |
| 25 | +use openstack_sdk::AsyncOpenStack; |
| 26 | + |
| 27 | +use crate::Cli; |
| 28 | +use crate::OpenStackCliError; |
| 29 | +use crate::output::OutputProcessor; |
| 30 | + |
| 31 | +use crate::common::parse_key_val; |
| 32 | +use openstack_sdk::api::QueryAsync; |
| 33 | +use openstack_sdk::api::identity::v4::federation::identity_provider::create; |
| 34 | +use openstack_types::identity::v4::federation::identity_provider::response::create::IdentityProviderResponse; |
| 35 | +use serde_json::Value; |
| 36 | + |
| 37 | +/// Create the identity provider with the specified properties. |
| 38 | +/// |
| 39 | +/// It is expected that only admin user is able to create global identity |
| 40 | +/// providers. |
| 41 | +#[derive(Args)] |
| 42 | +#[command(about = "Create the identity provider.")] |
| 43 | +pub struct IdentityProviderCommand { |
| 44 | + /// Request Query parameters |
| 45 | + #[command(flatten)] |
| 46 | + query: QueryParameters, |
| 47 | + |
| 48 | + /// Path parameters |
| 49 | + #[command(flatten)] |
| 50 | + path: PathParameters, |
| 51 | + |
| 52 | + /// Identity provider data. |
| 53 | + #[command(flatten)] |
| 54 | + identity_provider: IdentityProvider, |
| 55 | +} |
| 56 | + |
| 57 | +/// Query parameters |
| 58 | +#[derive(Args)] |
| 59 | +struct QueryParameters {} |
| 60 | + |
| 61 | +/// Path parameters |
| 62 | +#[derive(Args)] |
| 63 | +struct PathParameters {} |
| 64 | +/// IdentityProvider Body data |
| 65 | +#[derive(Args, Clone)] |
| 66 | +struct IdentityProvider { |
| 67 | + /// The bound issuer that is verified when using the identity provider. |
| 68 | + #[arg(help_heading = "Body parameters", long)] |
| 69 | + bound_issuer: Option<String>, |
| 70 | + |
| 71 | + /// Default attribute mapping name which is automatically used when no |
| 72 | + /// mapping is explicitly requested. The referred attribute mapping must |
| 73 | + /// exist. |
| 74 | + #[arg(help_heading = "Body parameters", long)] |
| 75 | + default_mapping_name: Option<String>, |
| 76 | + |
| 77 | + /// The ID of the domain this identity provider belongs to. Empty value |
| 78 | + /// identifies that the identity provider can be used by other domains as |
| 79 | + /// well. |
| 80 | + #[arg(help_heading = "Body parameters", long)] |
| 81 | + domain_id: Option<String>, |
| 82 | + |
| 83 | + /// Optional URL to fetch JsonWebKeySet. Must be specified for JWT |
| 84 | + /// authentication when discovery for the provider is not available or not |
| 85 | + /// standard compliant. |
| 86 | + #[arg(help_heading = "Body parameters", long)] |
| 87 | + jwks_url: Option<String>, |
| 88 | + |
| 89 | + /// List of the jwt validation public keys. |
| 90 | + /// |
| 91 | + /// Parameter is an array, may be provided multiple times. |
| 92 | + #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)] |
| 93 | + jwt_validation_pubkeys: Option<Vec<String>>, |
| 94 | + |
| 95 | + /// Identity provider name. |
| 96 | + #[arg(help_heading = "Body parameters", long)] |
| 97 | + name: String, |
| 98 | + |
| 99 | + /// The oidc `client_id` to use for the private client. |
| 100 | + #[arg(help_heading = "Body parameters", long)] |
| 101 | + oidc_client_id: Option<String>, |
| 102 | + |
| 103 | + /// The oidc `client_secret` to use for the private client. It is never |
| 104 | + /// returned back. |
| 105 | + #[arg(help_heading = "Body parameters", long)] |
| 106 | + oidc_client_secret: Option<String>, |
| 107 | + |
| 108 | + /// OIDC discovery endpoint for the identity provider. |
| 109 | + #[arg(help_heading = "Body parameters", long)] |
| 110 | + oidc_discovery_url: Option<String>, |
| 111 | + |
| 112 | + /// The oidc response mode. |
| 113 | + #[arg(help_heading = "Body parameters", long)] |
| 114 | + oidc_response_mode: Option<String>, |
| 115 | + |
| 116 | + /// List of supported response types. |
| 117 | + /// |
| 118 | + /// Parameter is an array, may be provided multiple times. |
| 119 | + #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)] |
| 120 | + oidc_response_types: Option<Vec<String>>, |
| 121 | + |
| 122 | + /// Additional special provider specific configuration |
| 123 | + #[arg(help_heading = "Body parameters", long, value_name="key=value", value_parser=parse_key_val::<String, Value>)] |
| 124 | + provider_config: Option<Vec<(String, Value)>>, |
| 125 | +} |
| 126 | + |
| 127 | +impl IdentityProviderCommand { |
| 128 | + /// Perform command action |
| 129 | + pub async fn take_action( |
| 130 | + &self, |
| 131 | + parsed_args: &Cli, |
| 132 | + client: &mut AsyncOpenStack, |
| 133 | + ) -> Result<(), OpenStackCliError> { |
| 134 | + info!("Create IdentityProvider"); |
| 135 | + |
| 136 | + let op = OutputProcessor::from_args( |
| 137 | + parsed_args, |
| 138 | + Some("identity.federation/identity_provider"), |
| 139 | + Some("create"), |
| 140 | + ); |
| 141 | + op.validate_args(parsed_args)?; |
| 142 | + |
| 143 | + let mut ep_builder = create::Request::builder(); |
| 144 | + |
| 145 | + // Set body parameters |
| 146 | + // Set Request.identity_provider data |
| 147 | + let args = &self.identity_provider; |
| 148 | + let mut identity_provider_builder = create::IdentityProviderBuilder::default(); |
| 149 | + if let Some(val) = &args.bound_issuer { |
| 150 | + identity_provider_builder.bound_issuer(val); |
| 151 | + } |
| 152 | + |
| 153 | + if let Some(val) = &args.default_mapping_name { |
| 154 | + identity_provider_builder.default_mapping_name(val); |
| 155 | + } |
| 156 | + |
| 157 | + if let Some(val) = &args.domain_id { |
| 158 | + identity_provider_builder.domain_id(val); |
| 159 | + } |
| 160 | + |
| 161 | + if let Some(val) = &args.jwks_url { |
| 162 | + identity_provider_builder.jwks_url(val); |
| 163 | + } |
| 164 | + |
| 165 | + if let Some(val) = &args.jwt_validation_pubkeys { |
| 166 | + identity_provider_builder |
| 167 | + .jwt_validation_pubkeys(val.iter().map(Into::into).collect::<Vec<_>>()); |
| 168 | + } |
| 169 | + |
| 170 | + identity_provider_builder.name(&args.name); |
| 171 | + |
| 172 | + if let Some(val) = &args.oidc_client_id { |
| 173 | + identity_provider_builder.oidc_client_id(val); |
| 174 | + } |
| 175 | + |
| 176 | + if let Some(val) = &args.oidc_client_secret { |
| 177 | + identity_provider_builder.oidc_client_secret(val); |
| 178 | + } |
| 179 | + |
| 180 | + if let Some(val) = &args.oidc_discovery_url { |
| 181 | + identity_provider_builder.oidc_discovery_url(val); |
| 182 | + } |
| 183 | + |
| 184 | + if let Some(val) = &args.oidc_response_mode { |
| 185 | + identity_provider_builder.oidc_response_mode(val); |
| 186 | + } |
| 187 | + |
| 188 | + if let Some(val) = &args.oidc_response_types { |
| 189 | + identity_provider_builder |
| 190 | + .oidc_response_types(val.iter().map(Into::into).collect::<Vec<_>>()); |
| 191 | + } |
| 192 | + |
| 193 | + if let Some(val) = &args.provider_config { |
| 194 | + identity_provider_builder.provider_config(val.iter().cloned()); |
| 195 | + } |
| 196 | + |
| 197 | + ep_builder.identity_provider(identity_provider_builder.build().unwrap()); |
| 198 | + |
| 199 | + let ep = ep_builder |
| 200 | + .build() |
| 201 | + .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?; |
| 202 | + |
| 203 | + let data = ep.query_async(client).await?; |
| 204 | + op.output_single::<IdentityProviderResponse>(data)?; |
| 205 | + // Show command specific hints |
| 206 | + op.show_command_hint()?; |
| 207 | + Ok(()) |
| 208 | + } |
| 209 | +} |
0 commit comments