-
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 #75 from salsadigitalauorg/feature/DEVOPS-713-2fa-…
…enforcement [DEVOPS-713] Implement remediation for Config V2
- Loading branch information
Showing
61 changed files
with
1,241 additions
and
318 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
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,77 +1,30 @@ | ||
package gen | ||
|
||
import ( | ||
"bytes" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
func BreachType(breachTypes []string) { | ||
log.Println("Generating breach type funcs -", strings.Join(breachTypes, ",")) | ||
|
||
tmplPath := filepath.Join("..", "..", "pkg", "breach", "gen_templates", "breachtype.go.tmpl") | ||
tmplTestPath := filepath.Join("..", "..", "pkg", "breach", "gen_templates", "breachtype_test.go.tmpl") | ||
|
||
breachTypeFile := "breach_gen.go" | ||
breachTypeFullFilePath := filepath.Join(getScriptPath(), "..", "..", "pkg", "breach", breachTypeFile) | ||
if err := os.Remove(breachTypeFullFilePath); err != nil && !os.IsNotExist(err) { | ||
log.Fatalln(err) | ||
} | ||
createFileWithString(breachTypeFullFilePath, "package breach\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) | ||
} | ||
templateToFile(tmplPath, struct{ BreachTypes []string }{breachTypes}, breachTypeFullFilePath) | ||
|
||
buf := &bytes.Buffer{} | ||
err = tmpl.Execute(buf, struct{ BreachType string }{bt}) | ||
if err != nil { | ||
// Test file. | ||
breachTypeTestFile := "breach_gen_test.go" | ||
breachTypeFullTestFilePath := filepath.Join(getScriptPath(), "..", "..", "pkg", "breach", breachTypeTestFile) | ||
if err := os.Remove(breachTypeFullTestFilePath); err != nil && !os.IsNotExist(err) { | ||
log.Fatalln(err) | ||
} | ||
return buf.String() | ||
templateToFile(tmplTestPath, struct{ BreachTypes []string }{breachTypes}, breachTypeFullTestFilePath) | ||
} |
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,28 @@ | ||
package gen | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func RemediatorPlugin(plugins []string, names []string) { | ||
log.Println("Generating remediator plugin funcs -", strings.Join(plugins, ",")) | ||
|
||
tmplPath := filepath.Join("..", "..", "pkg", "remediation", "templates", "remediatorplugin.go.tmpl") | ||
|
||
for i, p := range plugins { | ||
name := names[i] | ||
pluginFile := strings.ToLower(p) + "_gen.go" | ||
pluginFullFilePath := filepath.Join(getScriptPath(), "..", "..", "pkg", "remediation", pluginFile) | ||
if err := os.Remove(pluginFullFilePath); err != nil && !os.IsNotExist(err) { | ||
log.Fatalln(err) | ||
} | ||
|
||
templateToFile(tmplPath, struct { | ||
Plugin string | ||
Name string | ||
}{Plugin: p, Name: name}, pluginFullFilePath) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Analysing Data | ||
# Analysing data | ||
|
||
## Simple string check | ||
... | ||
|
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,4 +1,4 @@ | ||
# Collecting Data | ||
# Collecting data | ||
|
||
|
||
|
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 @@ | ||
# Remediating breaches |
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,13 @@ | ||
# equals | ||
|
||
The `equals` plugin checks if a value is exactly equal to an input. | ||
|
||
## Plugin fields | ||
|
||
| Field | Description | Required | Default | | ||
| ----- | -------------------------------------------------------------- | :------: | :-----: | | ||
| value | The value to compare against. | Yes | "" | | ||
| key | A key to look up the value when the input is a map of strings. | No | [] | | ||
|
||
|
||
<Content :page-key="$site.pages.find(p => p.path === '/reference/common/analyse.html').key"/> |
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,6 @@ | ||
## Common fields | ||
|
||
| Field | Description | Required | Default | | ||
| ------ | --------------------------------------------------------------- | :------: | :----------------------: | | ||
| plugin | The plugin to use for remediation. | No | "command" | | ||
| msg | The message to display when remediation completes successfully. | No | "remediation successful" | |
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,4 @@ | ||
--- | ||
title: Remediate | ||
--- | ||
# Remediate plugin reference |
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,11 @@ | ||
# command | ||
|
||
## Plugin fields | ||
|
||
| Field | Description | Required | Default | | ||
| ----- | --------------------------------- | :------: | :-----: | | ||
| cmd | The command to run. | Yes | - | | ||
| args | Arguments to pass to the command. | No | [] | | ||
|
||
|
||
<Content :page-key="$site.pages.find(p => p.path === '/reference/common/remediate.html').key"/> |
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.