-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModels.cs
More file actions
183 lines (159 loc) · 6.76 KB
/
Copy pathModels.cs
File metadata and controls
183 lines (159 loc) · 6.76 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
namespace SCAScanner;
using YamlDotNet.Serialization;
// ---------------------------------------------------------------------------
// Check status enumeration
// ---------------------------------------------------------------------------
/// <summary>Status of a check result: Passed, Failed, or Invalid (unexecutable).</summary>
public enum CheckStatus
{
Passed,
Failed,
Invalid
}
// ---------------------------------------------------------------------------
// Console output verbosity level
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Check condition enumeration
// ---------------------------------------------------------------------------
/// <summary>Logic applied to the rule list when evaluating a check or requirements block.</summary>
public enum CheckCondition
{
/// <summary>ALL rules must pass.</summary>
All,
/// <summary>At least one rule must pass.</summary>
Any,
/// <summary>No rules may pass (all must fail).</summary>
None,
/// <summary>Unrecognised condition string — check will be marked Invalid.</summary>
Unknown
}
// ---------------------------------------------------------------------------
// Console output verbosity level
// ---------------------------------------------------------------------------
/// <summary>Controls how much detail the console reporter outputs.</summary>
public enum OutputLevel
{
/// <summary>Only banner, policy header, and summary counts/score.</summary>
Compact,
/// <summary>Default: banner, policy header, requirements, per-check results, full summary.</summary>
Standard,
/// <summary>Everything: includes rule explanations and rule results per check.</summary>
Detailed
}
// ---------------------------------------------------------------------------
// Policy variables for substitution (e.g., $hosts -> /etc/hosts)
// ---------------------------------------------------------------------------
public sealed class PolicyVariables
{
/// <summary>
/// Mapping of variable names (e.g., "$hosts") to their values (e.g., "/etc/hosts").
/// Used for variable substitution in rule strings.
/// </summary>
public Dictionary<string, string> Values { get; set; } = new();
/// <summary>
/// Determines if this variables collection has any entries.
/// </summary>
public bool HasVariables => Values.Count > 0;
}
// ---------------------------------------------------------------------------
// Top-level policy file (YAML root)
// ---------------------------------------------------------------------------
public sealed class SCAPolicy
{
public PolicyMetadata Policy { get; set; } = new();
public Requirements? Requirements { get; set; }
/// <summary>
/// YAML-mapped variables (deserialized as Dictionary).
/// Converted to PolicyVariables on access via Variables property.
/// </summary>
[YamlMember(Alias = "variables")]
public Dictionary<string, string>? VariablesDict { get; set; }
private PolicyVariables? _variables;
/// <summary>
/// Parsed and wrapped variables for use throughout the application.
/// </summary>
[YamlIgnore]
public PolicyVariables? Variables
{
get
{
if (VariablesDict is null) return null;
return _variables ??= new PolicyVariables { Values = VariablesDict };
}
}
public List<Check> Checks { get; set; } = [];
}
// ---------------------------------------------------------------------------
// policy: section
// ---------------------------------------------------------------------------
public sealed class PolicyMetadata
{
public string Id { get; set; } = string.Empty;
public string File { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public List<string>? References { get; set; }
}
// ---------------------------------------------------------------------------
// requirements: section — must pass before any checks run
// ---------------------------------------------------------------------------
public sealed class Requirements
{
public string Title { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
/// <summary>YAML value: all | any | none</summary>
public string Condition { get; set; } = "any";
public List<string> Rules { get; set; } = [];
private CheckCondition? _conditionEnum;
/// <summary>Parsed <see cref="CheckCondition"/> derived from the YAML <see cref="Condition"/> string.</summary>
[YamlIgnore]
public CheckCondition ConditionEnum =>
_conditionEnum ??= Condition.ToLowerInvariant() switch
{
"all" => CheckCondition.All,
"any" => CheckCondition.Any,
"none" => CheckCondition.None,
_ => CheckCondition.Unknown
};
}
// ---------------------------------------------------------------------------
// checks: list item
// ---------------------------------------------------------------------------
public sealed class Check
{
public int Id { get; set; }
public string Title { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string Rationale { get; set; } = string.Empty;
public string Remediation { get; set; } = string.Empty;
/// <summary>YAML value: all | any | none</summary>
public string Condition { get; set; } = "all";
public List<string> Rules { get; set; } = [];
private CheckCondition? _conditionEnum;
/// <summary>Parsed <see cref="CheckCondition"/> derived from the YAML <see cref="Condition"/> string.</summary>
[YamlIgnore]
public CheckCondition ConditionEnum =>
_conditionEnum ??= Condition.ToLowerInvariant() switch
{
"all" => CheckCondition.All,
"any" => CheckCondition.Any,
"none" => CheckCondition.None,
_ => CheckCondition.Unknown
};
}
/// <summary>
/// Represents the result of executing a single check during a scan.
/// Used for reporting and summarization.
/// </summary>
public sealed class ScanCheckResult
{
/// <summary>Check identifier.</summary>
public required int Id { get; init; }
/// <summary>Check title/name.</summary>
public required string Title { get; init; }
/// <summary>Status of the check result.</summary>
public required CheckStatus Status { get; init; }
/// <summary>Reason for the result (e.g., "Condition 'ALL': 19/19 rules passed").</summary>
public required string Reason { get; init; }
}