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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
//! Installer specification parsing
//!
//! This module handles parsing of installer.toml files into strongly-typed structures.
use crate::models::{Error, Result};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// Complete installer specification parsed from installer.toml
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InstallerSpec {
/// Core installer metadata
pub installer: InstallerMetadata,
/// Artifacts to download and verify
#[serde(default)]
pub artifact: Vec<Artifact>,
/// Installation steps
#[serde(default)]
pub step: Vec<Step>,
}
impl InstallerSpec {
/// Parse an installer specification from TOML content
pub fn parse(content: &str) -> Result<Self> {
toml::from_str(content).map_err(|e| Error::Validation(format!("Invalid TOML: {e}")))
}
/// Serialize the specification back to TOML
pub fn to_toml(&self) -> Result<String> {
toml::to_string_pretty(self)
.map_err(|e| Error::Internal(format!("Failed to serialize to TOML: {e}")))
}
}
/// Installer metadata section
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InstallerMetadata {
/// Installer name
pub name: String,
/// Installer version (semver)
pub version: String,
/// Human-readable description
#[serde(default)]
pub description: String,
/// Author name or email
#[serde(default)]
pub author: String,
/// System requirements
#[serde(default)]
pub requirements: Requirements,
/// Environment variable definitions
#[serde(default)]
pub environment: HashMap<String, EnvVarSpec>,
/// Security configuration
#[serde(default)]
pub security: InstallerSecurity,
/// Hermetic build configuration
#[serde(default)]
pub hermetic: HermeticConfig,
/// Distributed execution configuration
#[serde(default)]
pub distributed: DistributedConfig,
/// Test matrix configuration
#[serde(default)]
pub test_matrix: TestMatrixConfig,
/// Golden trace configuration
#[serde(default)]
pub golden_traces: GoldenTraceConfig,
}
/// System requirements
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Requirements {
/// Supported operating systems (e.g., "ubuntu >= 20.04")
#[serde(default)]
pub os: Vec<String>,
/// Supported architectures (e.g., "x86_64", "aarch64")
#[serde(default)]
pub arch: Vec<String>,
/// Required privileges: "root" or "user"
#[serde(default = "default_privileges")]
pub privileges: String,
/// Whether network access is required
#[serde(default)]
pub network: bool,
}
fn default_privileges() -> String {
"user".to_string()
}
/// Environment variable specification
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EnvVarSpec {
/// Simple default value
Simple(String),
/// Complex specification with validation
Complex {
/// Default value
#[serde(default)]
default: Option<String>,
/// Value from another environment variable
#[serde(default)]
from_env: Option<String>,
/// Whether this variable is required
#[serde(default)]
required: bool,
/// Validation pattern
#[serde(default)]
validate: Option<String>,
},
}
/// Security configuration
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct InstallerSecurity {
/// Trust model: "keyring" or "tofu"
#[serde(default = "default_trust_model")]
pub trust_model: String,
/// Path to keyring file
#[serde(default)]
pub keyring: Option<String>,
/// Whether signatures are required for all artifacts
#[serde(default)]
pub require_signatures: bool,
/// Transparency log URL (Sigstore-compatible)
#[serde(default)]
pub transparency_log: Option<String>,
}
fn default_trust_model() -> String {
"tofu".to_string()
}
/// Hermetic build configuration
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct HermeticConfig {
/// Path to lockfile
#[serde(default)]
pub lockfile: Option<String>,
/// SOURCE_DATE_EPOCH setting: "auto" or a Unix timestamp
#[serde(default)]
pub source_date_epoch: Option<String>,
}
/// Distributed execution configuration
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct DistributedConfig {
/// Maximum parallel steps
#[serde(default)]
pub max_parallel_steps: Option<u32>,
/// sccache server address
#[serde(default)]
pub sccache_server: Option<String>,
}
/// Test matrix configuration
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct TestMatrixConfig {
/// Platforms to test (e.g., "ubuntu:22.04")
#[serde(default)]
pub platforms: Vec<String>,
/// Architectures to test
#[serde(default)]
pub architectures: Vec<String>,
/// Maximum parallel containers
#[serde(default)]
pub parallelism: Option<u32>,
/// Container runtime preference
#[serde(default)]
pub runtime: Option<String>,
}
/// Golden trace configuration
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct GoldenTraceConfig {
/// Whether golden traces are enabled
#[serde(default)]
pub enabled: bool,
/// Directory for golden trace files
#[serde(default)]
pub trace_dir: Option<String>,
/// Syscall categories to capture
#[serde(default)]
pub capture: Vec<String>,
/// Paths to ignore
#[serde(default)]
pub ignore_paths: Vec<String>,
}
/// Artifact definition
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Artifact {
/// Unique identifier for this artifact
pub id: String,
/// Download URL
pub url: String,
/// Expected SHA-256 hash
#[serde(default)]
pub sha256: Option<String>,
/// URL to SHA-256 sums file
#[serde(default)]
pub sha256_url: Option<String>,
/// Signature URL or path
#[serde(default)]
pub signature: Option<String>,
/// Key ID that signed this artifact
#[serde(default)]
pub signed_by: Option<String>,
}
/// Installation step
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Step {
/// Unique step identifier
pub id: String,
/// Human-readable step name
pub name: String,
/// Action type
pub action: String,
/// Dependencies (step IDs that must complete first)
#[serde(default)]
pub depends_on: Vec<String>,
/// Script content (for action = "script")
#[serde(default)]
pub script: Option<StepScript>,
/// Packages to install (for action = "apt-install")
#[serde(default)]
pub packages: Vec<String>,
/// Target path (for file operations)
#[serde(default)]
pub path: Option<String>,
/// Content (for file-write action)
#[serde(default)]
pub content: Option<String>,
/// User (for user-group action)
#[serde(default)]
pub user: Option<String>,
/// Group (for user-group action)
#[serde(default)]
pub group: Option<String>,
/// Privilege level for this step
#[serde(default)]
pub privileges: Option<String>,
/// Preconditions that must be met
#[serde(default)]
pub preconditions: Precondition,
/// Postconditions that must be verified
#[serde(default)]
pub postconditions: Postcondition,
/// Checkpoint configuration
#[serde(default)]
pub checkpoint: StepCheckpoint,
/// Timing configuration
#[serde(default)]
pub timing: StepTiming,
/// Artifacts used by this step
#[serde(default)]
pub uses_artifacts: ArtifactRefs,
/// Verification commands
#[serde(default)]
pub verification: Option<StepVerification>,
/// Failure handling
#[serde(default)]
pub on_failure: Option<FailureAction>,
/// Resource constraints
#[serde(default)]
pub constraints: StepConstraints,
/// Environment variables for this step
#[serde(default)]
pub environment: HashMap<String, EnvVarSpec>,
}
/// Script definition for a step
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct StepScript {
/// Interpreter to use (e.g., "sh", "bash")
#[serde(default = "default_interpreter")]
pub interpreter: String,
/// Script content
#[serde(default)]
pub content: String,
}
fn default_interpreter() -> String {
"sh".to_string()
}
/// Artifact references for a step
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ArtifactRefs {
/// List of artifact IDs
#[serde(default)]
pub artifacts: Vec<String>,
}
/// Preconditions for a step
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Precondition {
/// File must exist
#[serde(default)]
pub file_exists: Option<String>,
/// Command must succeed
#[serde(default)]
pub command_succeeds: Option<String>,
/// Environment variable must match pattern
#[serde(default)]
pub env_matches: HashMap<String, String>,
}
include!("spec_tests_postconditio.rs");