1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// SPDX-License-Identifier: Apache-2.0
use serde::{Deserialize, Serialize};
use crate::NetworkState;
#[derive(Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
#[non_exhaustive]
/// The IEEE 802.1X authentication configuration. The example yaml output of
/// [crate::NetworkState] with IEEE 802.1X authentication interface:
/// ```yml
/// ---
/// interfaces:
/// - name: eth1
/// type: ethernet
/// state: up
/// 802.1x:
/// ca-cert: /etc/pki/802-1x-test/ca.crt
/// client-cert: /etc/pki/802-1x-test/client.example.org.crt
/// eap-methods:
/// - tls
/// identity: client.example.org
/// private-key: /etc/pki/802-1x-test/client.example.org.key
/// private-key-password: password
/// ```
pub struct Ieee8021XConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub identity: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", rename = "eap-methods")]
/// Deserialize and serialize from/to `eap-methods`.
pub eap: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
/// Deserialize and serialize from/to `private-key`.
pub private_key: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
/// Deserialize and serialize from/to `client-cert`.
pub client_cert: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
/// Deserialize and serialize from/to `ca-cert`.
pub ca_cert: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
/// Deserialize and serialize from/to `private-key-password`.
/// Replaced to `<_password_hid_by_nmstate>` when querying.
pub private_key_password: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
/// Deserialize and serialize from/to `phase2-auth`.
pub phase2_auth: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
/// Deserialize and serialize from/to `password`.
/// Replaced to `<_password_hid_by_nmstate>` when querying.
pub password: Option<String>,
}
impl Ieee8021XConfig {
pub(crate) fn hide_secrets(&mut self) {
if self.private_key_password.is_some() {
self.private_key_password =
Some(NetworkState::PASSWORD_HID_BY_NMSTATE.to_string());
}
if self.password.is_some() {
self.password =
Some(NetworkState::PASSWORD_HID_BY_NMSTATE.to_string());
}
}
}
impl std::fmt::Debug for Ieee8021XConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Ieee8021XConfig")
.field("identity", &self.identity)
.field("eap", &self.eap)
.field("private_key", &self.private_key)
.field("client_cert", &self.client_cert)
.field("ca_cert", &self.ca_cert)
.field(
"private_key_password",
&Some(NetworkState::PASSWORD_HID_BY_NMSTATE.to_string()),
)
.field("phase2_auth", &self.phase2_auth)
.field(
"password",
&Some(NetworkState::PASSWORD_HID_BY_NMSTATE.to_string()),
)
.finish()
}
}