forked from docker-archive/oscalkit
/
opencontrol.go
173 lines (141 loc) · 4.03 KB
/
opencontrol.go
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
package oscal
import (
"fmt"
"path"
"strings"
"github.com/opencontrol/oscalkit/types/opencontrol"
)
func convertOC(oc opencontrol.OpenControl, ocComponents []opencontrol.Component) (*OSCAL, error) {
ocOSCAL := Implementation{}
ocOSCAL.Title = oc.Name
ocOSCAL.Paragraphs = append(ocOSCAL.Paragraphs, P{
OptionalClass: "description",
Raw: oc.Metadata.Description,
})
for _, maintainer := range oc.Metadata.Maintainers {
ocOSCAL.Props = append(ocOSCAL.Props, Prop{
OptionalClass: "maintainer",
Value: maintainer,
})
}
implementationProfiles := &Profiles{}
for _, cert := range oc.Certifications {
implementationProfiles.Links = append(implementationProfiles.Links, Link{
Rel: "profile",
Href: cert,
})
}
if oc.Dependencies != nil {
for _, cert := range oc.Dependencies.Certifications {
implementationProfiles.Links = append(implementationProfiles.Links, Link{
Rel: "profile",
Href: "../../FedRAMP/FedRAMP-MODERATE-crude",
Value: parseOCCert(cert.URL),
})
}
}
ocOSCAL.Profiles = implementationProfiles
ocOSCAL.Params = Params{}
ocOSCAL.Components = Components{}
for _, ocComponent := range ocComponents {
item := Item{}
item.Title = &Raw{Value: ocComponent.Name}
item.Prose = &Prose{}
// Outputs "null" JSON value since this is self-closing XML tag
item.Prose.P = append(item.Prose.P, P{
OptionalClass: "description",
})
if ocComponent.ResponsibleRole != "" {
item.Prose.P = append(item.Prose.P, P{
OptionalClass: "responsibleRoles",
Raw: ocComponent.ResponsibleRole,
})
}
for _, ocSatisfy := range ocComponent.Satisfies {
var part Part
part.OptionalClass = "satisfies"
key := strings.ToLower(ocSatisfy.ControlKey)
r := strings.NewReplacer(
" ", "",
"-", ".",
"(", ".",
")", "",
)
key = fmt.Sprintf("#%s", r.Replace(key))
part.Links = append(part.Links, Link{
Rel: "satisfies",
Href: key,
// TODO: Value from linked "catalog"
})
part.Prose = &Prose{}
for _, ocNarrative := range ocSatisfy.Narrative {
raw := ocNarrative.Text
if strings.HasSuffix(raw, "\n") {
raw = strings.TrimSuffix(raw, "\n")
}
part.Prose.P = append(part.Prose.P, P{
OptionalClass: "narrative",
Raw: raw,
})
}
for _, ocOrigin := range ocSatisfy.ControlOrigins {
part.Props = append(part.Props, Prop{
OptionalClass: "origin",
Value: ocOrigin,
})
}
if ocSatisfy.ControlOrigin != "" {
part.Props = append(part.Props, Prop{
OptionalClass: "origin",
Value: ocSatisfy.ControlOrigin,
})
}
for _, ocParameter := range ocSatisfy.Parameters {
ocOSCAL.Params.SetParams = append(ocOSCAL.Params.SetParams, ImplementationParam{
ID: ocParameter.Key,
Desc: Desc{
Raw: ocParameter.Text,
},
})
}
for _, ocStatus := range ocSatisfy.ImplementationStatuses {
part.Props = append(part.Props, Prop{
OptionalClass: "status",
Value: ocStatus,
})
}
if ocSatisfy.ImplementationStatus != "" {
part.Props = append(part.Props, Prop{
OptionalClass: "status",
Value: ocSatisfy.ImplementationStatus,
})
}
item.Parts = append(item.Parts, part)
}
for _, ocReference := range ocComponent.References {
part := Part{
OptionalClass: "reference",
Title: &Raw{Value: ocReference.Name},
}
part.Prose = &Prose{}
part.Prose.P = append(part.Prose.P, P{
OptionalClass: "description",
})
part.Links = append(part.Links, Link{
Value: ocReference.Path,
})
item.Parts = append(item.Parts, part)
}
ocOSCAL.Components.Items = append(ocOSCAL.Components.Items, item)
}
ocOSCAL.Profiles = implementationProfiles
return &OSCAL{Implementation: &ocOSCAL}, nil
}
// Temporary mechanism for converting https://github.com/opencontrol/FedRAMP-Certifications
// to path to OSCAL JSON
func parseOCCert(url string) string {
if path.Base(url) == "FedRAMP-Certifications" {
return "FedRAMP MODERATE Baseline PROFILE"
}
return ""
}