/
gitbook.go
75 lines (66 loc) · 1.84 KB
/
gitbook.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
/*
Copyright (C) 2018 OpenControl Contributors. See LICENSE.md for license.
*/
package gitbook
import (
"fmt"
"path/filepath"
"github.com/opencontrol/compliance-masonry/pkg/lib"
"github.com/opencontrol/compliance-masonry/pkg/lib/common"
"github.com/opencontrol/compliance-masonry/tools/fs"
)
// Config contains data for gitbook export configurations
type Config struct {
OpencontrolDir string
Certification string
ExportPath string
MarkdownPath string
}
// OpenControlGitBook struct is an extension of models.OpenControl that adds
// an exportPath
type OpenControlGitBook struct {
common.Workspace
markdownPath string
exportPath string
FSUtil fs.Util
}
// ComponentGitbook struct is an extension of models.Component that adds
// an exportPath
type ComponentGitbook struct {
common.Component
exportPath string
}
// ControlGitbook struct is an extension of models.Control that adds
// an exportPath
type ControlGitbook struct {
common.Control
exportPath string
standardKey string
controlKey string
}
func exportLink(text string, location string) string {
return fmt.Sprintf("* [%s](%s)\n", text, location)
}
// BuildGitbook entry point for creating gitbook
func (config Config) BuildGitbook() []error {
var errs []error
openControlData, err := lib.LoadData(config.OpencontrolDir, config.Certification)
if err != nil && len(err) > 0 {
return append(errs, err...)
}
openControl := OpenControlGitBook{
openControlData,
config.MarkdownPath,
config.ExportPath,
fs.OSUtil{},
}
openControl.FSUtil.Mkdirs(config.ExportPath)
openControl.FSUtil.Mkdirs(filepath.Join(config.ExportPath, "components"))
openControl.FSUtil.Mkdirs(filepath.Join(config.ExportPath, "standards"))
if err := openControl.buildSummaries(); err != nil {
return append(errs, err)
}
openControl.exportComponents()
openControl.exportStandards()
return nil
}