Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create the codes json file during docs build #960

Merged
merged 1 commit into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 58 additions & 0 deletions cmd/tfsec-docs/extension_codes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"encoding/json"
"fmt"
"os"
)

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),
})

}
}

file, err := os.Create("checkdocs/codes.json")
if err != nil {
panic(err)
}

out, err := json.MarshalIndent(checksBlock{
Checks: blocks,
}, "", " ")
if err != nil {
panic(err)
}

_, err = file.Write(out)

return err
}
4 changes: 4 additions & 0 deletions cmd/tfsec-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ var rootCmd = &cobra.Command{
return err
}

if err := generateExtensionCodeFile(fileContents); err != nil {
return err
}

return generateWebPages(fileContents)
},
}
Expand Down
16 changes: 9 additions & 7 deletions example/custom/custom_check.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ resource "aws_instance" "non_compliant" {
}

resource "aws_instance" "compliant" {
ami = "ami-12345"
instance_type = "t2.small"
ami = "ami-12345"
instance_type = "t2.small"
cpu_core_count = 4

tags = {
Expand All @@ -24,6 +24,7 @@ resource "aws_s3_bucket" "unversioned_bucket" {
acl = "private"
}

#tfsec:ignore:AWS017:exp:2021-01-01:ws:testworkspace
resource "aws_s3_bucket" "versioned_bucket" {
bucket = "my-tf-test-bucket"
acl = "private"
Expand All @@ -32,7 +33,7 @@ resource "aws_s3_bucket" "versioned_bucket" {
enabled = true
}
}

# tfsec:ignore:AWS017
resource "aws_s3_bucket" "disabled_versioned_bucket" {
bucket = "my-tf-test-bucket"
acl = "private"
Expand All @@ -48,11 +49,12 @@ module "custom_bucket" {
acl = "private"
}

#tfsec:ignore:aws-s3-enable-bucket-encryption
resource "aws_s3_bucket" "bucket_with_public_acl" {
bucket = "my-tf-test-bucket"
// acl = "public-read"
//
versioning {
// acl = "public-read"
//
versioning {
enabled = true
}
}
}
1 change: 1 addition & 0 deletions scripts/publish-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ clone_site
go run ./cmd/tfsec-docs
cp -r checkdocs/docs/* ./_site/_docs/
cp -r checkdocs/data/* ./_site/_data/
cp =r checkdocs/codes.json ./_site/assets/codes.json
deploy

rm -rf checkdocs