-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add go embed removed static upgrade to go1.16
Signed-off-by: david-doit-intl <david@doit-intl.com>
- Loading branch information
david-doit-intl
committed
Mar 1, 2021
1 parent
8421287
commit 6df64d1
Showing
15 changed files
with
90 additions
and
69 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
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,35 @@ | ||
package rules | ||
|
||
import ( | ||
"embed" | ||
"path" | ||
) | ||
|
||
//go:embed rego | ||
var local embed.FS | ||
|
||
type Rule struct { | ||
Name string | ||
Rule string | ||
} | ||
|
||
func FetchRegoRules() ([]Rule, error) { | ||
fis, err := local.ReadDir("rego") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rules := []Rule{} | ||
for _, info := range fis { | ||
data, err := local.ReadFile(path.Join("rego", info.Name())) | ||
if err != nil { | ||
return nil, err | ||
} | ||
rules = append(rules, Rule{ | ||
Name: info.Name(), | ||
Rule: string(data), | ||
}) | ||
} | ||
|
||
return rules, 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,28 @@ | ||
package rules | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestFetchRules(t *testing.T) { | ||
var expected []string | ||
root := "rego/" | ||
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { | ||
if info.Name() != "rego" { | ||
expected = append(expected, info.Name()) | ||
} | ||
return nil | ||
}) | ||
|
||
rules, err := FetchRegoRules() | ||
if err != nil { | ||
t.Errorf("Failed to load rules with: %s", err) | ||
} | ||
for i, rule := range rules { | ||
if rule.Name != expected[i] { | ||
t.Errorf("expected to get %s finding, instead got: %s", expected[i], rule.Name) | ||
} | ||
} | ||
} |
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