Skip to main content

openstack_cli_network/v2/vpn/ikepolicy/
create.rs

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 Ikepolicy command
19//!
20//! Wraps invoking of the `v2.0/vpn/ikepolicies` with `POST` method
21
22use clap::Args;
23use eyre::WrapErr;
24use tracing::info;
25
26use openstack_cli_core::cli::CliArgs;
27use openstack_cli_core::error::OpenStackCliError;
28use openstack_cli_core::output::OutputProcessor;
29use openstack_sdk::AsyncOpenStack;
30
31use clap::ValueEnum;
32use openstack_sdk::api::QueryAsync;
33use openstack_sdk::api::network::v2::vpn::ikepolicy::create;
34use openstack_types::network::v2::vpn::ikepolicy::response;
35
36/// Creates an IKE policy.
37///
38/// The IKE policy is used for phases one and two negotiation of the VPN
39/// connection. You can specify both the authentication and encryption
40/// algorithms for connections.
41///
42/// Normal response codes: 201
43///
44/// Error response codes: 400, 401
45#[derive(Args)]
46#[command(about = "Create IKE policy")]
47pub struct IkepolicyCommand {
48    /// Request Query parameters
49    #[command(flatten)]
50    query: QueryParameters,
51
52    /// Path parameters
53    #[command(flatten)]
54    path: PathParameters,
55
56    /// An `ikepolicy` object.
57    #[command(flatten)]
58    ikepolicy: Ikepolicy,
59}
60
61/// Query parameters
62#[derive(Args)]
63struct QueryParameters {}
64
65/// Path parameters
66#[derive(Args)]
67struct PathParameters {}
68
69#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
70enum AuthAlgorithm {
71    AesCmac,
72    AesXcbc,
73    Sha1,
74    Sha256,
75    Sha384,
76    Sha512,
77}
78
79#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
80enum EncryptionAlgorithm {
81    _3des,
82    Aes128,
83    Aes128Ccm12,
84    Aes128Ccm16,
85    Aes128Ccm8,
86    Aes128Ctr,
87    Aes128Gcm12,
88    Aes128Gcm16,
89    Aes128Gcm8,
90    Aes192,
91    Aes192Ccm12,
92    Aes192Ccm16,
93    Aes192Ccm8,
94    Aes192Ctr,
95    Aes192Gcm12,
96    Aes192Gcm16,
97    Aes192Gcm8,
98    Aes256,
99    Aes256Ccm12,
100    Aes256Ccm16,
101    Aes256Ccm8,
102    Aes256Ctr,
103    Aes256Gcm12,
104    Aes256Gcm16,
105    Aes256Gcm8,
106}
107
108#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
109enum IkeVersion {
110    V1,
111    V2,
112}
113
114#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
115enum Pfs {
116    Group14,
117    Group15,
118    Group16,
119    Group17,
120    Group18,
121    Group19,
122    Group2,
123    Group20,
124    Group21,
125    Group22,
126    Group23,
127    Group24,
128    Group25,
129    Group26,
130    Group27,
131    Group28,
132    Group29,
133    Group30,
134    Group31,
135    Group5,
136}
137
138#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
139enum Phase1NegotiationMode {
140    Aggressive,
141    Main,
142}
143
144/// Ikepolicy Body data
145#[derive(Args, Clone)]
146struct Ikepolicy {
147    /// The authentication hash algorithm. Valid values are `sha1`, `sha256`,
148    /// `sha384`, `sha512`, `aes-xcbc`, `aes-cmac`. The default is `sha1`.
149    #[arg(help_heading = "Body parameters", long)]
150    auth_algorithm: Option<AuthAlgorithm>,
151
152    /// A human-readable description for the resource. Default is an empty
153    /// string.
154    #[arg(help_heading = "Body parameters", long)]
155    description: Option<String>,
156
157    /// The encryption algorithm. A valid value is `3des`, `aes-128`,
158    /// `aes-192`, `aes-256`, `aes-128-ctr`, `aes-192-ctr`, `aes-256-ctr`.
159    /// Additional values for AES CCM and GCM modes are defined (e.g.
160    /// `aes-256-ccm-16`, `aes-256-gcm-16`) for all combinations of key length
161    /// 128, 192, 256 bits and ICV length 8, 12, 16 octets. Default is
162    /// `aes-128`.
163    #[arg(help_heading = "Body parameters", long)]
164    encryption_algorithm: Option<EncryptionAlgorithm>,
165
166    /// The IKE version. A valid value is `v1` or `v2`. Default is `v1`.
167    #[arg(help_heading = "Body parameters", long)]
168    ike_version: Option<IkeVersion>,
169
170    /// The lifetime of the security association. The lifetime consists of a
171    /// unit and integer value. You can omit either the unit or value portion
172    /// of the lifetime. Default unit is seconds and default value is 3600.
173    #[arg(help_heading = "Body parameters", long)]
174    lifetime: Option<String>,
175
176    /// Human-readable name of the resource. Default is an empty string.
177    #[arg(help_heading = "Body parameters", long)]
178    name: Option<String>,
179
180    /// Perfect forward secrecy (PFS). A valid value is `Group2`, `Group5`,
181    /// `Group14` to `Group31`. Default is `Group5`.
182    #[arg(help_heading = "Body parameters", long)]
183    pfs: Option<Pfs>,
184
185    /// The IKE mode. A valid value is `main`, which is the default.
186    #[arg(help_heading = "Body parameters", long)]
187    phase1_negotiation_mode: Option<Phase1NegotiationMode>,
188
189    /// The ID of the project.
190    #[arg(help_heading = "Body parameters", long)]
191    tenant_id: Option<String>,
192}
193
194impl IkepolicyCommand {
195    /// Perform command action
196    pub async fn take_action<C: CliArgs>(
197        &self,
198        parsed_args: &C,
199        client: &mut AsyncOpenStack,
200    ) -> Result<(), OpenStackCliError> {
201        info!("Create Ikepolicy");
202
203        let op =
204            OutputProcessor::from_args(parsed_args, Some("network.vpn/ikepolicy"), Some("create"));
205        op.validate_args(parsed_args)?;
206
207        let mut ep_builder = create::Request::builder();
208
209        // Set body parameters
210        // Set Request.ikepolicy data
211        let args = &self.ikepolicy;
212        let mut ikepolicy_builder = create::IkepolicyBuilder::default();
213        if let Some(val) = &args.auth_algorithm {
214            let tmp = match val {
215                AuthAlgorithm::AesCmac => create::AuthAlgorithm::AesCmac,
216                AuthAlgorithm::AesXcbc => create::AuthAlgorithm::AesXcbc,
217                AuthAlgorithm::Sha1 => create::AuthAlgorithm::Sha1,
218                AuthAlgorithm::Sha256 => create::AuthAlgorithm::Sha256,
219                AuthAlgorithm::Sha384 => create::AuthAlgorithm::Sha384,
220                AuthAlgorithm::Sha512 => create::AuthAlgorithm::Sha512,
221            };
222            ikepolicy_builder.auth_algorithm(tmp);
223        }
224
225        if let Some(val) = &args.description {
226            ikepolicy_builder.description(val);
227        }
228
229        if let Some(val) = &args.encryption_algorithm {
230            let tmp = match val {
231                EncryptionAlgorithm::_3des => create::EncryptionAlgorithm::_3des,
232                EncryptionAlgorithm::Aes128 => create::EncryptionAlgorithm::Aes128,
233                EncryptionAlgorithm::Aes128Ccm12 => create::EncryptionAlgorithm::Aes128Ccm12,
234                EncryptionAlgorithm::Aes128Ccm16 => create::EncryptionAlgorithm::Aes128Ccm16,
235                EncryptionAlgorithm::Aes128Ccm8 => create::EncryptionAlgorithm::Aes128Ccm8,
236                EncryptionAlgorithm::Aes128Ctr => create::EncryptionAlgorithm::Aes128Ctr,
237                EncryptionAlgorithm::Aes128Gcm12 => create::EncryptionAlgorithm::Aes128Gcm12,
238                EncryptionAlgorithm::Aes128Gcm16 => create::EncryptionAlgorithm::Aes128Gcm16,
239                EncryptionAlgorithm::Aes128Gcm8 => create::EncryptionAlgorithm::Aes128Gcm8,
240                EncryptionAlgorithm::Aes192 => create::EncryptionAlgorithm::Aes192,
241                EncryptionAlgorithm::Aes192Ccm12 => create::EncryptionAlgorithm::Aes192Ccm12,
242                EncryptionAlgorithm::Aes192Ccm16 => create::EncryptionAlgorithm::Aes192Ccm16,
243                EncryptionAlgorithm::Aes192Ccm8 => create::EncryptionAlgorithm::Aes192Ccm8,
244                EncryptionAlgorithm::Aes192Ctr => create::EncryptionAlgorithm::Aes192Ctr,
245                EncryptionAlgorithm::Aes192Gcm12 => create::EncryptionAlgorithm::Aes192Gcm12,
246                EncryptionAlgorithm::Aes192Gcm16 => create::EncryptionAlgorithm::Aes192Gcm16,
247                EncryptionAlgorithm::Aes192Gcm8 => create::EncryptionAlgorithm::Aes192Gcm8,
248                EncryptionAlgorithm::Aes256 => create::EncryptionAlgorithm::Aes256,
249                EncryptionAlgorithm::Aes256Ccm12 => create::EncryptionAlgorithm::Aes256Ccm12,
250                EncryptionAlgorithm::Aes256Ccm16 => create::EncryptionAlgorithm::Aes256Ccm16,
251                EncryptionAlgorithm::Aes256Ccm8 => create::EncryptionAlgorithm::Aes256Ccm8,
252                EncryptionAlgorithm::Aes256Ctr => create::EncryptionAlgorithm::Aes256Ctr,
253                EncryptionAlgorithm::Aes256Gcm12 => create::EncryptionAlgorithm::Aes256Gcm12,
254                EncryptionAlgorithm::Aes256Gcm16 => create::EncryptionAlgorithm::Aes256Gcm16,
255                EncryptionAlgorithm::Aes256Gcm8 => create::EncryptionAlgorithm::Aes256Gcm8,
256            };
257            ikepolicy_builder.encryption_algorithm(tmp);
258        }
259
260        if let Some(val) = &args.ike_version {
261            let tmp = match val {
262                IkeVersion::V1 => create::IkeVersion::V1,
263                IkeVersion::V2 => create::IkeVersion::V2,
264            };
265            ikepolicy_builder.ike_version(tmp);
266        }
267
268        if let Some(val) = &args.lifetime {
269            ikepolicy_builder.lifetime(val);
270        }
271
272        if let Some(val) = &args.name {
273            ikepolicy_builder.name(val);
274        }
275
276        if let Some(val) = &args.pfs {
277            let tmp = match val {
278                Pfs::Group14 => create::Pfs::Group14,
279                Pfs::Group15 => create::Pfs::Group15,
280                Pfs::Group16 => create::Pfs::Group16,
281                Pfs::Group17 => create::Pfs::Group17,
282                Pfs::Group18 => create::Pfs::Group18,
283                Pfs::Group19 => create::Pfs::Group19,
284                Pfs::Group2 => create::Pfs::Group2,
285                Pfs::Group20 => create::Pfs::Group20,
286                Pfs::Group21 => create::Pfs::Group21,
287                Pfs::Group22 => create::Pfs::Group22,
288                Pfs::Group23 => create::Pfs::Group23,
289                Pfs::Group24 => create::Pfs::Group24,
290                Pfs::Group25 => create::Pfs::Group25,
291                Pfs::Group26 => create::Pfs::Group26,
292                Pfs::Group27 => create::Pfs::Group27,
293                Pfs::Group28 => create::Pfs::Group28,
294                Pfs::Group29 => create::Pfs::Group29,
295                Pfs::Group30 => create::Pfs::Group30,
296                Pfs::Group31 => create::Pfs::Group31,
297                Pfs::Group5 => create::Pfs::Group5,
298            };
299            ikepolicy_builder.pfs(tmp);
300        }
301
302        if let Some(val) = &args.phase1_negotiation_mode {
303            let tmp = match val {
304                Phase1NegotiationMode::Aggressive => create::Phase1NegotiationMode::Aggressive,
305                Phase1NegotiationMode::Main => create::Phase1NegotiationMode::Main,
306            };
307            ikepolicy_builder.phase1_negotiation_mode(tmp);
308        }
309
310        if let Some(val) = &args.tenant_id {
311            ikepolicy_builder.tenant_id(val);
312        }
313
314        ep_builder.ikepolicy(
315            ikepolicy_builder
316                .build()
317                .wrap_err("error preparing the request data")?,
318        );
319
320        let ep = ep_builder
321            .build()
322            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
323
324        let data: serde_json::Value = ep.query_async(client).await?;
325
326        op.output_single::<response::create::IkepolicyResponse>(data.clone())?;
327        // Show command specific hints
328        op.show_command_hint()?;
329        Ok(())
330    }
331}