-
Notifications
You must be signed in to change notification settings - Fork 1
/
access-pdp-examples_test.go
65 lines (60 loc) · 1.5 KB
/
access-pdp-examples_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package pdp_test
import (
ctx "context"
"fmt"
"log/slog"
attrs "github.com/virtru/access-pdp/attributes"
accesspdp "github.com/virtru/access-pdp/pdp"
)
// AnyOf tests
func Example() {
entityID := "4f6636ca-c60c-40d1-9f3f-015086303f74"
attrAuthorities := []string{"https://example.org"}
AttrDefinitions := []attrs.AttributeDefinition{
{
Authority: attrAuthorities[0],
Name: "MyAttr",
Rule: "anyOf",
Order: []string{"Value1", "Value2"},
},
}
DataAttrs := []attrs.AttributeInstance{
{
Authority: attrAuthorities[0],
Name: AttrDefinitions[0].Name,
Value: AttrDefinitions[0].Order[1],
},
{
Authority: attrAuthorities[0],
Name: AttrDefinitions[0].Name,
Value: AttrDefinitions[0].Order[0],
},
{
Authority: attrAuthorities[0],
Name: AttrDefinitions[0].Name,
Value: "NegativeTypoValue",
},
}
EntityAttrs := map[string][]attrs.AttributeInstance{
entityID: {
{
Authority: "https://example.org",
Name: "MyAttr",
Value: "Value2",
},
{
Authority: "https://meep.org",
Name: "meep",
Value: "beepbeep",
},
},
}
slog.Default().Handler().Enabled(ctx.Background(), slog.LevelInfo)
accessPDP := accesspdp.NewAccessPDPWithSlog(slog.Default())
context := ctx.Background()
decisions, err := accessPDP.DetermineAccess(DataAttrs, EntityAttrs, AttrDefinitions, &context)
if err != nil {
slog.Error("Could not generate a decision!")
}
fmt.Printf("Decision result: %+v", decisions)
}