-
Notifications
You must be signed in to change notification settings - Fork 34
/
parser.go
66 lines (57 loc) · 1.8 KB
/
parser.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
66
// Package jast implements policies JSON AST (JAST) parser.
package jast
import (
"encoding/json"
"io"
"github.com/infobloxopen/themis/pdp"
"github.com/google/uuid"
)
const (
yastTagTypes = "types"
yastTagMeta = "meta"
yastTagFlags = "flags"
yastTagAttributes = "attributes"
yastTagID = "id"
yastTagTarget = "target"
yastTagPolicies = "policies"
yastTagRules = "rules"
yastTagCondition = "condition"
yastTagAlg = "alg"
yastTagMap = "map"
yastTagDefault = "default"
yastTagError = "error"
yastTagAggregation = "aggregation"
yastTagOrder = "order"
yastTagEffect = "effect"
yastTagObligation = "obligations"
yastTagAny = "any"
yastTagAll = "all"
yastTagAttribute = "attr"
yastTagValue = "val"
yastTagSelector = "selector"
yastTagType = "type"
yastTagContent = "content"
yastTagURI = "uri"
yastTagPath = "path"
yastTagOp = "op"
yastTagEntity = "entity"
)
// Parser is a JAST parser implementation.
type Parser struct{}
// Unmarshal parses policies JSON representation to PDP's internal representation.
func (p Parser) Unmarshal(in io.Reader, tag *uuid.UUID) (*pdp.PolicyStorage, error) {
ctx := newContext()
if err := ctx.unmarshal(json.NewDecoder(in)); err != nil {
return nil, err
}
return pdp.NewPolicyStorage(ctx.rootPolicy, ctx.symbols, tag), nil
}
// UnmarshalUpdate parses policies update JSON representation to PDP's internal representation.
func (p Parser) UnmarshalUpdate(in io.Reader, s pdp.Symbols, oldTag, newTag uuid.UUID) (*pdp.PolicyUpdate, error) {
ctx := newContextWithSymbols(s)
u := pdp.NewPolicyUpdate(oldTag, newTag)
if err := ctx.unmarshalCommands(json.NewDecoder(in), u); err != nil {
return nil, err
}
return u, nil
}