Skip to content

Commit 176b132

Browse files
committed
chore(policy): create policy folder.
1 parent bd4a232 commit 176b132

File tree

9 files changed

+16
-15
lines changed

9 files changed

+16
-15
lines changed

.github/workflows/opa.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ jobs:
3737
3838
- name: Run Testing
3939
run: |
40-
./opa test -v *.rego
40+
./opa test -v policy/*.rego

Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
opa_test:
2-
opa test -v *.rego
3-
4-
rbac_test:
5-
opa test -v ./rbac/*.rego
2+
opa test -v policy/*.rego
63

74
go_test:
85
go test -v .
96

10-
test: rbac_test opa_test go_test
7+
test: opa_test go_test

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/go-training/opa-demo
1+
module github.com/go-training/opa-embed
22

33
go 1.16
44

main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"log"
66

7+
"github.com/go-training/opa-embed/policy"
8+
79
"github.com/open-policy-agent/opa/rego"
810
)
911

@@ -29,15 +31,15 @@ func main() {
2931
"object": s.Object,
3032
}
3133

32-
policy, err := readPolicy(policyFile)
34+
p, err := policy.ReadPolicy(policyFile)
3335
if err != nil {
3436
log.Fatal(err)
3537
}
3638

3739
ctx := context.TODO()
3840
query, err := rego.New(
3941
rego.Query(defaultQuery),
40-
rego.Module(policyFile, string(policy)),
42+
rego.Module(policyFile, string(p)),
4143
).PrepareForEval(ctx)
4244

4345
if err != nil {

main_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@ import (
66
"os"
77
"testing"
88

9+
"github.com/go-training/opa-embed/policy"
10+
911
"github.com/open-policy-agent/opa/rego"
1012
)
1113

1214
var query rego.PreparedEvalQuery
1315

1416
func setup() {
1517
var err error
16-
policy, err := readPolicy(policyFile)
18+
p, err := policy.ReadPolicy(policyFile)
1719
if err != nil {
1820
log.Fatal(err)
1921
}
2022

2123
query, err = rego.New(
2224
rego.Query(defaultQuery),
23-
rego.Module(policyFile, string(policy)),
25+
rego.Module(policyFile, string(p)),
2426
).PrepareForEval(context.TODO())
2527

2628
if err != nil {
File renamed without changes.
File renamed without changes.

policy.go renamed to policy/policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// +build !go1.16
22

3-
package main
3+
package policy
44

55
import (
66
"io/ioutil"
77
"log"
88
)
99

10-
func readPolicy(path string) ([]byte, error) {
10+
func ReadPolicy(path string) ([]byte, error) {
1111
// load policy
1212
policy, err := ioutil.ReadFile(policyFile)
1313
if err != nil {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// +build go1.16
22

3-
package main
3+
package policy
44

55
import (
66
_ "embed"
@@ -9,6 +9,6 @@ import (
99
//go:embed example.rego
1010
var policy []byte
1111

12-
func readPolicy(path string) ([]byte, error) {
12+
func ReadPolicy(path string) ([]byte, error) {
1313
return policy, nil
1414
}

0 commit comments

Comments
 (0)