-
Notifications
You must be signed in to change notification settings - Fork 472
Expand file tree
/
Copy pathmod.rs
More file actions
220 lines (166 loc) · 6.2 KB
/
mod.rs
File metadata and controls
220 lines (166 loc) · 6.2 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// Copyright (c) Microsoft. All rights reserved.
pub mod aziot;
pub mod image_gc_settings;
pub mod module;
pub mod uri;
pub mod watchdog;
pub trait RuntimeSettings {
type ModuleConfig: Clone;
fn hostname(&self) -> &str;
fn edge_ca_cert(&self) -> Option<&str>;
fn edge_ca_key(&self) -> Option<&str>;
fn edge_ca_auto_renew(&self) -> &Option<cert_renewal::AutoRenewConfig>;
fn edge_ca_subject(&self) -> &Option<aziot_certd_config::CertSubject>;
fn trust_bundle_cert(&self) -> Option<&str>;
fn manifest_trust_bundle_cert(&self) -> Option<&str>;
fn auto_reprovisioning_mode(&self) -> aziot::AutoReprovisioningMode;
fn homedir(&self) -> &std::path::Path;
fn allow_elevated_docker_permissions(&self) -> bool;
fn iotedge_max_requests(&self) -> &IotedgeMaxRequests;
fn agent(&self) -> &module::Settings<Self::ModuleConfig>;
fn agent_mut(&mut self) -> &mut module::Settings<Self::ModuleConfig>;
fn connect(&self) -> &uri::Connect;
fn listen(&self) -> &uri::Listen;
fn watchdog(&self) -> &watchdog::Settings;
fn endpoints(&self) -> &aziot::Endpoints;
fn additional_info(&self) -> &std::collections::BTreeMap<String, String>;
fn image_garbage_collection(&self) -> &image_gc_settings::Settings;
}
#[derive(Clone, Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct EdgeCa {
#[serde(skip_serializing_if = "Option::is_none")]
pub cert: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub key: Option<String>,
// This enum has one value variant and one table variant. It must be placed
// after all values and before all tables.
#[serde(flatten, skip_serializing_if = "Option::is_none")]
pub subject: Option<aziot_certd_config::CertSubject>,
#[serde(skip_serializing_if = "Option::is_none")]
pub auto_renew: Option<cert_renewal::AutoRenewConfig>,
}
impl EdgeCa {
pub fn is_default(&self) -> bool {
self == &EdgeCa::default()
}
}
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct IotedgeMaxRequests {
pub management: usize,
pub workload: usize,
}
impl Default for IotedgeMaxRequests {
fn default() -> IotedgeMaxRequests {
IotedgeMaxRequests {
// Allow 50 concurrent requests on the management socket, as that is the
// maximum number of modules allowed by IoT Hub.
management: 50,
workload: http_common::Incoming::default_max_requests(),
}
}
}
impl IotedgeMaxRequests {
pub fn is_default(&self) -> bool {
self == &IotedgeMaxRequests::default()
}
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct Settings<ModuleConfig> {
pub hostname: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub trust_bundle_cert: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub manifest_trust_bundle_cert: Option<String>,
#[serde(default)]
pub auto_reprovisioning_mode: aziot::AutoReprovisioningMode,
pub homedir: std::path::PathBuf,
#[serde(default = "default_allow_elevated_docker_permissions")]
pub allow_elevated_docker_permissions: bool,
#[serde(default, skip_serializing_if = "IotedgeMaxRequests::is_default")]
pub iotedge_max_requests: IotedgeMaxRequests,
#[serde(default, skip_serializing_if = "EdgeCa::is_default")]
pub edge_ca: EdgeCa,
pub agent: module::Settings<ModuleConfig>,
pub connect: uri::Connect,
pub listen: uri::Listen,
#[serde(default)]
pub watchdog: watchdog::Settings,
/// Map of service names to endpoint URIs.
///
/// Only configurable in debug builds for the sake of tests.
#[serde(default, skip_serializing)]
#[cfg_attr(not(debug_assertions), serde(skip_deserializing))]
pub endpoints: aziot::Endpoints,
/// Additional system information
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
pub additional_info: std::collections::BTreeMap<String, String>,
#[serde(
default,
skip_serializing_if = "image_gc_settings::Settings::is_default"
)]
pub image_garbage_collection: image_gc_settings::Settings,
}
pub(crate) fn default_allow_elevated_docker_permissions() -> bool {
// For now, we will allow elevated docker permissions by default. This will change in a future version.
true
}
impl<T: Clone> RuntimeSettings for Settings<T> {
type ModuleConfig = T;
fn hostname(&self) -> &str {
&self.hostname
}
fn edge_ca_cert(&self) -> Option<&str> {
self.edge_ca.cert.as_deref()
}
fn edge_ca_key(&self) -> Option<&str> {
self.edge_ca.key.as_deref()
}
fn edge_ca_auto_renew(&self) -> &Option<cert_renewal::AutoRenewConfig> {
&self.edge_ca.auto_renew
}
fn edge_ca_subject(&self) -> &Option<aziot_certd_config::CertSubject> {
&self.edge_ca.subject
}
fn trust_bundle_cert(&self) -> Option<&str> {
self.trust_bundle_cert.as_deref()
}
fn manifest_trust_bundle_cert(&self) -> Option<&str> {
self.manifest_trust_bundle_cert.as_deref()
}
fn auto_reprovisioning_mode(&self) -> aziot::AutoReprovisioningMode {
self.auto_reprovisioning_mode
}
fn iotedge_max_requests(&self) -> &IotedgeMaxRequests {
&self.iotedge_max_requests
}
fn homedir(&self) -> &std::path::Path {
&self.homedir
}
fn allow_elevated_docker_permissions(&self) -> bool {
self.allow_elevated_docker_permissions
}
fn agent(&self) -> &module::Settings<Self::ModuleConfig> {
&self.agent
}
fn agent_mut(&mut self) -> &mut module::Settings<Self::ModuleConfig> {
&mut self.agent
}
fn connect(&self) -> &uri::Connect {
&self.connect
}
fn listen(&self) -> &uri::Listen {
&self.listen
}
fn watchdog(&self) -> &watchdog::Settings {
&self.watchdog
}
fn endpoints(&self) -> &aziot::Endpoints {
&self.endpoints
}
fn additional_info(&self) -> &std::collections::BTreeMap<String, String> {
&self.additional_info
}
fn image_garbage_collection(&self) -> &image_gc_settings::Settings {
&self.image_garbage_collection
}
}