Skip to main content

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