forked from strongdm/comply
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add command for adding missing SOC2 documents (strongdm#36)
Co-authored-by: wallrony <[email protected]>
- Loading branch information
Showing
5 changed files
with
5,802 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.