-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from salsadigitalauorg/feature/DEVOPS-406-reme…
…diate-drush-yaml [DEVOPS-406] Add remediation support for drush yaml checks
- Loading branch information
Showing
68 changed files
with
2,100 additions
and
1,247 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
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# Generated files | ||
registry_gen.go | ||
pkg/result/breach_gen.go | ||
|
||
build | ||
dist/ | ||
docker-compose.override.yml | ||
node_modules | ||
registry_gen.go | ||
venom-output |
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
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,77 @@ | ||
package gen | ||
|
||
import ( | ||
"bytes" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
func BreachType(breachTypes []string) { | ||
log.Println("Generating breach type funcs -", strings.Join(breachTypes, ",")) | ||
|
||
breachTypeFile := "breach_gen.go" | ||
breachTypeFullFilePath := filepath.Join(getScriptPath(), "..", "..", "pkg", "result", breachTypeFile) | ||
if err := os.Remove(breachTypeFullFilePath); err != nil && !os.IsNotExist(err) { | ||
log.Fatalln(err) | ||
} | ||
createFile(breachTypeFullFilePath, "package result\n") | ||
|
||
for _, bt := range breachTypes { | ||
appendFileContent(breachTypeFullFilePath, breachTypeFuncs(bt)) | ||
} | ||
} | ||
|
||
func breachTypeFuncs(bt string) string { | ||
tmplStr := ` | ||
/* | ||
* {{.BreachType}}Breach | ||
*/ | ||
func (b *{{.BreachType}}Breach) GetCheckName() string { | ||
return b.CheckName | ||
} | ||
func (b *{{.BreachType}}Breach) GetCheckType() string { | ||
return b.CheckType | ||
} | ||
func (b *{{.BreachType}}Breach) GetRemediation() *Remediation { | ||
return &b.Remediation | ||
} | ||
func (b *{{.BreachType}}Breach) GetSeverity() string { | ||
return b.Severity | ||
} | ||
func (b *{{.BreachType}}Breach) GetType() BreachType { | ||
return BreachType{{.BreachType}} | ||
} | ||
func (b *{{.BreachType}}Breach) SetCommonValues(checkType string, checkName string, severity string) { | ||
b.BreachType = b.GetType() | ||
b.CheckType = checkType | ||
b.CheckName = checkName | ||
b.Severity = severity | ||
} | ||
func (b *{{.BreachType}}Breach) SetRemediation(status RemediationStatus, msg string) { | ||
b.Remediation.Status = status | ||
if msg != "" { | ||
b.Remediation.Messages = []string{msg} | ||
} | ||
} | ||
` | ||
tmpl, err := template.New("breachTypeFuncs").Parse(tmplStr) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
buf := &bytes.Buffer{} | ||
err = tmpl.Execute(buf, struct{ BreachType string }{bt}) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
return buf.String() | ||
} |
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,79 @@ | ||
package gen | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
func getScriptPath() string { | ||
_, b, _, _ := runtime.Caller(0) | ||
return filepath.Dir(b) | ||
} | ||
|
||
func createFile(fullpath string, firstTimeContent string) { | ||
if f, err := os.Stat(fullpath); err == nil && !f.IsDir() { | ||
return | ||
} else if !os.IsNotExist(err) { | ||
log.Fatalln(err) | ||
} | ||
|
||
f, err := os.OpenFile(fullpath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer func() { | ||
f.Close() | ||
}() | ||
|
||
if firstTimeContent == "" { | ||
return | ||
} | ||
|
||
if _, err := f.Write([]byte(firstTimeContent)); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func getFileLines(fullpath string) []string { | ||
input, err := os.ReadFile(fullpath) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
return strings.Split(string(input), "\n") | ||
} | ||
|
||
func writeFileContent(fullpath string, content string) { | ||
err := os.WriteFile(fullpath, []byte(content), 0644) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
} | ||
|
||
func appendFileContent(fullpath string, content string) { | ||
input, err := os.ReadFile(fullpath) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
output := string(input) + content | ||
writeFileContent(fullpath, output) | ||
} | ||
|
||
func writeFileLines(fullpath string, lines []string) { | ||
output := strings.Join(lines, "\n") | ||
err := os.WriteFile(fullpath, []byte(output), 0644) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
} | ||
|
||
func stringSliceMatch(slice []string, item string) bool { | ||
for _, s := range slice { | ||
if strings.Contains(s, item) { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
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
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
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
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.