Skip to main content

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