-
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.
check policy against user repository metadata
- Loading branch information
Showing
6 changed files
with
86 additions
and
6 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,46 @@ | ||
package check | ||
|
||
import ( | ||
"context" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/kobtea/gorgo/config" | ||
"github.com/kobtea/gorgo/fetch" | ||
"github.com/open-policy-agent/conftest/output" | ||
"github.com/open-policy-agent/conftest/runner" | ||
) | ||
|
||
func Check(ctx context.Context, cfg *config.Config) error { | ||
var result []output.CheckResult | ||
for _, elm := range cfg.Users { | ||
pat := filepath.Join(cfg.WorkingDir, fetch.MetadataDirname, elm.Name, "*", fetch.RepoFilename) | ||
files, err := filepath.Glob(pat) | ||
if err != nil { | ||
return err | ||
} | ||
var matchFiles []string | ||
for _, file := range files { | ||
l := strings.Split(file, "/") | ||
repoName := l[len(l)-2] | ||
if elm.Regex.Match([]byte(repoName)) { | ||
matchFiles = append(matchFiles, file) | ||
} | ||
} | ||
r := runner.TestRunner{ | ||
AllNamespaces: true, | ||
Policy: elm.RepoPolicies, | ||
} | ||
res, err := r.Run(ctx, matchFiles) | ||
if err != nil { | ||
return err | ||
} | ||
result = append(result, res...) | ||
} | ||
// FIXME: support multi format | ||
outputter := output.Get("", output.Options{}) | ||
if err := outputter.Output(result); err != nil { | ||
return err | ||
} | ||
return 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,22 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/kobtea/gorgo/check" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// checkCmd represents the check command | ||
var checkCmd = &cobra.Command{ | ||
Use: "check", | ||
Short: "Test policies", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
ctx := context.Background() | ||
check.Check(ctx, cfg) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(checkCmd) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package github.repo | ||
|
||
warn[msg] { | ||
[y, m, _, _, _, _] := time.diff(time.now_ns(), time.parse_rfc3339_ns(input.pushed_at)) | ||
y * 12 + m > 6 | ||
msg := "GitHub repository should be pushed at least once every 6 month" | ||
} |
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