forked from boostsecurityio/poutine
-
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 docs module and add documentation to SARIF (boostsecurityio#23)
- Loading branch information
Showing
3 changed files
with
76 additions
and
3 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,50 @@ | ||
package docs | ||
|
||
import ( | ||
"embed" | ||
"fmt" | ||
"path" | ||
"strings" | ||
) | ||
|
||
//go:embed content | ||
var content embed.FS | ||
|
||
type Page struct { | ||
Content string `yaml:"-"` | ||
} | ||
|
||
func GetPagesContent() map[string]string { | ||
docs := map[string]string{} | ||
entries, err := content.ReadDir(path.Join("content", "en", "rules")) | ||
if err != nil { | ||
return docs | ||
} | ||
|
||
for _, entry := range entries { | ||
ruleId := strings.TrimSuffix(entry.Name(), ".md") | ||
page, err := GetPage(ruleId) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
docs[ruleId] = page.Content | ||
} | ||
|
||
return docs | ||
} | ||
|
||
func GetPage(ruleId string) (*Page, error) { | ||
doc, err := content.ReadFile( | ||
path.Join("content", "en", "rules", ruleId+".md")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
parts := strings.SplitAfterN(string(doc), "---\n", 3) | ||
if len(parts) != 3 { | ||
return nil, fmt.Errorf("invalid doc page %s.md", ruleId) | ||
} | ||
|
||
return &Page{Content: strings.TrimSpace(parts[2])}, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package docs | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetRuleDocs(t *testing.T) { | ||
page, err := GetPage("debug_enabled") | ||
|
||
assert.Nil(t, err) | ||
assert.True(t, | ||
strings.HasPrefix(page.Content, "## Description"), | ||
"content should be trimmed '%s'...", page.Content[0:10], | ||
) | ||
} |
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