forked from Normation/rudder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JsonDecoder.elm
68 lines (57 loc) · 2.29 KB
/
JsonDecoder.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
module Groups.JsonDecoder exposing (..)
import Json.Decode exposing (..)
import Json.Decode.Pipeline exposing (..)
import Groups.DataTypes exposing (..)
import GroupCompliance.DataTypes exposing (GroupId)
import Compliance.JsonDecoder exposing (decodeComplianceDetails)
decodeGetGroupsCompliance : Decoder (List GroupComplianceSummary)
decodeGetGroupsCompliance =
at [ "data" , "nodeGroups" ] (list decodeGroupCompliance)
decodeGroupCompliance : Decoder GroupComplianceSummary
decodeGroupCompliance =
succeed GroupComplianceSummary
|> required "id" (map GroupId string)
|> required "targeted" decodeComplianceSummaryValue
|> required "global" decodeComplianceSummaryValue
decodeComplianceSummaryValue : Decoder ComplianceSummaryValue
decodeComplianceSummaryValue =
succeed ComplianceSummaryValue
|> required "compliance" float
|> required "complianceDetails" decodeComplianceDetails
decodeGetGroupsTree : Decoder (Category Group)
decodeGetGroupsTree =
at ["data", "groupCategories"] decodeCategoryGroupTarget
decodeCategoryGroupTarget : Decoder (Category Group)
decodeCategoryGroupTarget =
succeed ( \id name description categories groups targets ->
let
elems = if id == rootGroupCategoryId then groups else (List.append groups targets)
in
Category id name description categories elems
)
|> required "id" string
|> required "name" string
|> required "description" string
|> required "categories" (map SubCategories (list (lazy (\_ -> decodeCategoryGroupTarget))))
|> required "groups" (list decodeGroup)
|> required "targets" (list decodeTarget)
decodeGroup : Decoder Group
decodeGroup =
succeed Group
|> required "id" (map GroupId string)
|> required "displayName" string
|> required "description" string
|> optional "category" (map Just string) Nothing
|> required "dynamic" bool
|> required "enabled" bool
|> required "target" string
decodeTarget : Decoder Group
decodeTarget =
succeed Group
|> required "id" (map GroupId string)
|> required "displayName" string
|> required "description" string
|> optional "category" (map Just string) Nothing
|> hardcoded True
|> required "enabled" bool
|> required "target" string