-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the codes json file during docs build
this will be downloaded by the vscode plugin for ignore resolution
- Loading branch information
Owen Rumney
committed
Jul 27, 2021
1 parent
ff1bf69
commit ed3bc5c
Showing
4 changed files
with
93 additions
and
7 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,79 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
const extensionJsonTemplate = ` | ||
{ | ||
"checks": [ | ||
{{ range c := .Checks }} | ||
{ | ||
"code": "{{ c.ID }}", | ||
"legacy_code": "{{ c.LegacyID }}", | ||
"service": "{{ c.Service }}", | ||
"provider": "{{ c.Provider }}", | ||
"description": "{{ c.Documentation.Summary }}", | ||
"impact": "{{ c.Documentation.Impact }}", | ||
"resolution": "{{ c.Documentation.Resolution }}", | ||
"doc_url": "https://tfsec.dev/docs/aws/{{ c.Service }}/{{ c.ShortCode }} | ||
} | ||
{{ end }} | ||
] | ||
} | ||
` | ||
|
||
type checkBlock struct { | ||
Code string `json:"code"` | ||
LegacyCode string `json:"legacy_code"` | ||
Service string `json:"service"` | ||
Provider string `json:"provider"` | ||
Description string `json:"description"` | ||
Impact string `json:"impact"` | ||
Resolution string `json:"resolution"` | ||
DocUrl string `json:"doc_url"` | ||
} | ||
|
||
type checksBlock struct { | ||
Checks []checkBlock `json:"checks"` | ||
} | ||
|
||
func generateExtensionCodeFile(registeredChecks []*FileContent) error { | ||
var blocks []checkBlock | ||
|
||
for _, c := range registeredChecks { | ||
for _, check := range c.Checks { | ||
blocks = append(blocks, checkBlock{ | ||
Code: check.ID(), | ||
LegacyCode: check.LegacyID, | ||
Service: check.Service, | ||
Provider: string(check.Provider), | ||
Description: check.Documentation.Summary, | ||
Impact: check.Documentation.Impact, | ||
Resolution: check.Documentation.Resolution, | ||
DocUrl: fmt.Sprintf("https://tfsec.dev/docs/%s/%s/%s/", check.Provider, check.Service, check.ShortCode), | ||
}) | ||
|
||
} | ||
} | ||
|
||
root := checksBlock{ | ||
Checks: blocks, | ||
} | ||
|
||
file, err := os.Create("checkdocs/codes.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
out, err := json.MarshalIndent(root, "", " ") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
_, err = file.Write(out) | ||
|
||
return err | ||
} |
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