forked from Normation/rudder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataTypes.elm
348 lines (297 loc) · 9.66 KB
/
DataTypes.elm
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
module DataTypes exposing (..)
import Dict exposing (Dict)
import Http exposing (Error)
import Time.ZonedDateTime exposing (ZonedDateTime)
--
-- All our data types
--
type TabMenu
= Information
| Directives
| Nodes
| Groups
| TechnicalLogs
type alias Tag =
{ key : String
, value : String
}
type ModalState = NoModal | DeletionValidation Rule | DeactivationValidation Rule | DeletionValidationCat (Category Rule)
type RuleTarget = Composition RuleTarget RuleTarget | And (List RuleTarget) | Or (List RuleTarget) | NodeGroupId String | Special String | Node String
type alias RuleId = { value : String }
type alias DirectiveId = { value : String }
type alias NodeId = { value : String }
type alias Rule =
{ id : RuleId
, name : String
, categoryId : String
, shortDescription : String
, longDescription : String
, enabled : Bool
, isSystem : Bool
, directives : List DirectiveId
, targets : List RuleTarget
, policyMode : String
, status : RuleStatus
, tags : List Tag
}
type alias Directive =
{ id : DirectiveId
, displayName : String
, longDescription : String
, techniqueName : String
, techniqueVersion : String
, enabled : Bool
, system : Bool
, policyMode : String
, tags : List Tag
}
type alias Technique =
{ name : String
, directives : List Directive
}
type alias NodeInfo =
{ id : String
, hostname : String
, description : String
, policyMode : String
}
type alias Category a =
{ id : String
, name : String
, description : String
, subElems : SubCategories a
, elems : List a
}
type SubCategories a = SubCategories (List (Category a))
type alias Group =
{ id : String
, name : String
, description : String
, nodeIds : List String
, dynamic : Bool
, enabled : Bool
, target : String
}
getAllElems: Category a -> List a
getAllElems category =
let
subElems = case category.subElems of SubCategories l -> l
in
List.append category.elems (List.concatMap getAllElems subElems)
getSubElems: Category a -> List (Category a)
getSubElems cat =
case cat.subElems of
SubCategories subs -> subs
getAllCats: Category a -> List (Category a)
getAllCats category =
let
subElems = case category.subElems of SubCategories l -> l
in
category :: (List.concatMap getAllCats subElems)
-- get all missing categories
getAllMissingCats: Category a -> List (Category a)
getAllMissingCats category =
let
missingCategory = List.filter (\sub -> sub.id == missingCategoryId) (getSubElems category)
in
List.concatMap getAllCats missingCategory
-- get all rules who as an unknown category id
getAllMissingCatsRules: Category a -> List a
getAllMissingCatsRules category =
let
missingCategory = List.filter (\sub -> sub.id == missingCategoryId) (getSubElems category)
in
List.concatMap getAllElems missingCategory
type alias RuleComplianceGlobal =
{ id : RuleId
, compliance : Float
, complianceDetails : ComplianceDetails
}
type alias RuleCompliance =
{ ruleId : RuleId
, mode : String
, compliance : Float
, complianceDetails : ComplianceDetails
, directives : List (DirectiveCompliance NodeValueCompliance)
, nodes : List NodeCompliance
}
type alias NodeCompliance =
{ nodeId : NodeId
, name : String
, compliance : Float
, complianceDetails : ComplianceDetails
, directives : List (DirectiveCompliance ValueLine)
}
type alias DirectiveCompliance value =
{ directiveId : DirectiveId
, name : String
, compliance : Float
, complianceDetails : ComplianceDetails
, components : List (ComponentCompliance value)
}
type ComponentCompliance value = Block (BlockCompliance value) | Value (ComponentValueCompliance value)
type alias BlockCompliance value =
{ component : String
, compliance : Float
, complianceDetails : ComplianceDetails
, components : List (ComponentCompliance value)
}
type alias ComponentValueCompliance value =
{ component : String
, compliance : Float
, complianceDetails : ComplianceDetails
, values : List value
}
type SortOrder = Asc | Desc
type alias NodeValueCompliance =
{ nodeId : NodeId
, name : String
, compliance : Float
, complianceDetails : ComplianceDetails
, values : List ValueLine
}
type alias ValueLine =
{ value : String
, message : String
, status : String
}
type alias Report =
{ status : String
, message : Maybe String
}
type alias RuleStatus =
{ value : String
, details : Maybe String
}
type alias RepairedReport =
{ directiveId : DirectiveId
, nodeId : NodeId
, component : String
, value : String
, executionTimeStamp : ZonedDateTime
, executionDate : ZonedDateTime
, message : String
}
type alias ComplianceDetails =
{ successNotApplicable : Maybe Float
, successAlreadyOK : Maybe Float
, successRepaired : Maybe Float
, error : Maybe Float
, auditCompliant : Maybe Float
, auditNonCompliant : Maybe Float
, auditError : Maybe Float
, auditNotApplicable : Maybe Float
, unexpectedUnknownComponent : Maybe Float
, unexpectedMissingComponent : Maybe Float
, noReport : Maybe Float
, reportsDisabled : Maybe Float
, applying : Maybe Float
, badPolicyMode : Maybe Float
}
type alias RuleDetailsUI = { editDirectives: Bool, editGroups : Bool, newTag : Tag, openedRows : Dict String (String, SortOrder) }
type alias RuleDetails = { originRule : Maybe Rule, rule : Rule, tab : TabMenu, ui : RuleDetailsUI, numberOfNodes: Maybe Int, numberOfDirectives: Maybe Int, compliance : Maybe RuleCompliance, reports : List RepairedReport }
type alias RuleNodesDirectives = { id: String, numberOfNodes: Int, numberOfDirectives: Int }
type alias CategoryDetails = { originCategory : Maybe (Category Rule), category : Category Rule, parentId : String, tab : TabMenu}
type Mode
= Loading
| RuleTable
| RuleForm RuleDetails
| CategoryForm CategoryDetails
type SortBy
= Name
| Parent
| Status
| Compliance
| RuleChanges
type alias TableFilters =
{ sortBy : SortBy
, sortOrder : SortOrder
, filter : String
, unfolded : List String
}
type alias TreeFilters =
{ filter : String
, folded : List String
, newTag : Tag
, tags : List Tag
}
type alias Filters =
{ tableFilters : TableFilters
, treeFilters : TreeFilters
}
type alias UI =
{ ruleFilters : Filters
, directiveFilters : Filters
, groupFilters : Filters
, modal : ModalState
, hasWriteRights : Bool
, loadingRules : Bool
, isAllCatFold : Bool
, saving : Bool
}
type alias Changes =
{ start : ZonedDateTime
, end : ZonedDateTime
, changes : Float
}
-- this is the Id used by the API to group missing categories with their rules
missingCategoryId = "ui-missing-rule-category"
type alias Model =
{ contextPath : String
, mode : Mode
, policyMode : String
, rulesTree : Category Rule
, groupsTree : Category Group
, techniquesTree : Category Technique
, rulesCompliance : Dict String RuleComplianceGlobal
, changes : Dict String (List Changes)
, directives : Dict String Directive
, nodes : Dict String NodeInfo
, ui : UI
}
type Msg
= Copy String
| GenerateId (String -> Msg)
| OpenRuleDetails RuleId Bool
| OpenCategoryDetails String Bool
| CloseDetails
| SelectGroup String Bool
| UpdateRuleForm RuleDetails
| UpdateCategoryForm CategoryDetails
| NewRule RuleId
| NewCategory String
| GetRepairedReport RuleId Int
| CallApi Bool (Model -> Cmd Msg)
| GetRuleDetailsResult (Result Error Rule)
| GetPolicyModeResult (Result Error String)
| GetCategoryDetailsResult (Result Error (Category Rule))
| GetRulesComplianceResult (Result Error (List RuleComplianceGlobal))
| GetRuleNodesDirectivesResult RuleId (Result Error RuleNodesDirectives)
| GetRuleComplianceResult RuleId (Result Error RuleCompliance)
| GetNodesList (Result Error (List NodeInfo))
| SaveRuleDetails (Result Error Rule)
| SaveDisableAction (Result Error Rule)
| SaveCategoryResult (Result Error (Category Rule))
| GetRulesResult (Result Error (Category Rule))
| GetGroupsTreeResult (Result Error (Category Group))
| GetRuleChanges (Result Error (Dict String (List Changes)))
| GetRepairedReportsResult RuleId ZonedDateTime ZonedDateTime (Result Error (List RepairedReport))
| GetTechniquesTreeResult (Result Error ((Category Technique, List Technique)))
| DeleteRule (Result Error (RuleId, String))
| DeleteCategory (Result Error (String, String))
| DisableRule
| CloneRule Rule RuleId
| OpenDeletionPopup Rule
| OpenDeletionPopupCat (Category Rule)
| OpenDeactivationPopup Rule
| ClosePopup Msg
| Ignore
| ToggleRow String String
| ToggleRowSort String String SortOrder
| UpdateRuleFilters Filters
| UpdateDirectiveFilters Filters
| UpdateGroupFilters Filters
| GoTo String
| FoldAllCategories Filters
| RefreshComplianceTable RuleId
| RefreshReportsTable RuleId