Skip to content

Commit

Permalink
add command for adding missing SOC2 documents (strongdm#36)
Browse files Browse the repository at this point in the history
Co-authored-by: wallrony <[email protected]>
  • Loading branch information
vassalo and wallrony committed Oct 22, 2021
1 parent ecc0219 commit ab32f70
Show file tree
Hide file tree
Showing 5 changed files with 5,802 additions and 59 deletions.
65 changes: 65 additions & 0 deletions internal/cli/add_missing_soc2_documents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cli

import (
"errors"
"github.com/strongdm/comply/internal/config"
"github.com/urfave/cli"
"io/ioutil"
"log"
"path/filepath"
"runtime"
"strings"
)

var addMissingSOC2DocumentsCommand = cli.Command{
Name: "add",
Usage: "add missing default SOC2 documents for a given document type",
Action: addMissingSOC2DocumentsAction,
Before: projectMustExist,
}

func addMissingSOC2DocumentsAction(c *cli.Context) error {
validSOC2Folders := map[string]bool{"narratives": true, "policies": true, "procedures": true, "standards": true}
documentType := c.Args().First()
if !validSOC2Folders[documentType] {
return errors.New("invalid SOC2 document type")
}

_, b, _, _ := runtime.Caller(0)
complyPath := filepath.Dir(b)
documentsRootDir := strings.Split(strings.ReplaceAll(complyPath, "\\", "/"), "/")
documentsRootPath := strings.Join(documentsRootDir[0:len(documentsRootDir)-2], "/") + "/themes/comply-soc2/" + documentType
documentFilesInfo, err := ioutil.ReadDir(documentsRootPath)
if err != nil {
log.Fatal(err)
}

orgDocumentFilesInfo, err := ioutil.ReadDir(config.ProjectRoot() + "/" + documentType)
if err != nil {
log.Fatal(err)
}

for _, documentFileInfo := range documentFilesInfo {
orgAlreadyHasFile := false
for _, orgDocumentFileInfo := range orgDocumentFilesInfo {
if orgDocumentFileInfo.Name() == documentFileInfo.Name() {
orgAlreadyHasFile = true
break
}
}

if !orgAlreadyHasFile {
documentFile, err := ioutil.ReadFile(documentsRootPath + "/" + documentFileInfo.Name())
if err != nil {
return err
}

err = ioutil.WriteFile(config.ProjectRoot()+"/"+documentType+"/"+documentFileInfo.Name(), documentFile, 0644)
if err != nil {
return err
}
}
}

return nil
}
1 change: 1 addition & 0 deletions internal/cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func newApp() *cli.App {
app.Commands = append(app.Commands, beforeCommand(serveCommand, projectMustExist, notifyVersion))
app.Commands = append(app.Commands, beforeCommand(syncCommand, projectMustExist, notifyVersion))
app.Commands = append(app.Commands, beforeCommand(todoCommand, projectMustExist, notifyVersion))
app.Commands = append(app.Commands, beforeCommand(addMissingSOC2DocumentsCommand, projectMustExist, notifyVersion))

// Plugins
github.Register()
Expand Down
Loading

0 comments on commit ab32f70

Please sign in to comment.