-
Notifications
You must be signed in to change notification settings - Fork 117
/
bytes_value.go
executable file
·74 lines (61 loc) · 1.51 KB
/
bytes_value.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
67
68
69
70
71
72
73
74
package types
import (
"encoding/json"
)
type BytesValue interface {
metadataProvider
Value() []byte
Len() int
}
type bytesValue struct {
BaseAttribute
value []byte
}
func (b *bytesValue) MarshalJSON() ([]byte, error) {
return json.Marshal(b.value)
}
func (b *bytesValue) Value() []byte {
return b.value
}
func (b *bytesValue) GetRawValue() interface{} {
return b.value
}
func (b *bytesValue) Len() int {
return len(b.value)
}
func (b *bytesValue) GetMetadata() Metadata {
return b.metadata
}
func Bytes(value []byte, m Metadata) BytesValue {
return &bytesValue{
value: value,
BaseAttribute: BaseAttribute{metadata: m},
}
}
func BytesDefault(value []byte, m Metadata) BytesValue {
b := Bytes(value, m)
b.(*bytesValue).BaseAttribute.metadata.isDefault = true
return b
}
func BytesExplicit(value []byte, m Metadata) BytesValue {
b := Bytes(value, m)
b.(*bytesValue).BaseAttribute.metadata.isExplicit = true
return b
}
func BytesUnresolvable(m Metadata) BytesValue {
b := Bytes(nil, m)
b.(*bytesValue).BaseAttribute.metadata.isUnresolvable = true
return b
}
func (s *bytesValue) ToRego() interface{} {
return map[string]interface{}{
"filepath": s.metadata.Range().GetFilename(),
"startline": s.metadata.Range().GetStartLine(),
"endline": s.metadata.Range().GetEndLine(),
"managed": s.metadata.isManaged,
"explicit": s.metadata.isExplicit,
"value": string(s.Value()),
"fskey": CreateFSKey(s.metadata.Range().GetFS()),
"resource": s.metadata.Reference().String(),
}
}