-
Notifications
You must be signed in to change notification settings - Fork 1
/
warrant.go
172 lines (147 loc) · 4.75 KB
/
warrant.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package warrant
import (
"encoding/json"
)
type Warrant struct {
ObjectType string `json:"objectType"`
ObjectId string `json:"objectId"`
Relation string `json:"relation"`
Subject Subject `json:"subject"`
Policy string `json:"policy,omitempty"`
IsImplicit bool `json:"isImplicit,omitempty"`
WarrantToken string `json:"warrantToken,omitempty"`
}
type PolicyContext map[string]interface{}
type Subject struct {
ObjectType string `json:"objectType"`
ObjectId string `json:"objectId"`
Relation string `json:"relation,omitempty"`
}
func (subject Subject) GetObjectType() string {
return subject.ObjectType
}
func (subject Subject) GetObjectId() string {
return subject.ObjectId
}
func (subject Subject) GetRelation() string {
return subject.Relation
}
type WarrantParams struct {
ObjectType string `json:"objectType"`
ObjectId string `json:"objectId"`
Relation string `json:"relation"`
Subject Subject `json:"subject"`
Policy string `json:"policy,omitempty"`
}
type ListWarrantParams struct {
ListParams
ObjectType string `json:"objectType,omitempty" url:"objectType,omitempty"`
ObjectId string `json:"objectId,omitempty" url:"objectId,omitempty"`
Relation string `json:"relation,omitempty" url:"relation,omitempty"`
SubjectType string `json:"subjectType,omitempty" url:"subjectType,omitempty"`
SubjectId string `json:"subjectId,omitempty" url:"subjectId,omitempty"`
SubjectRelation string `json:"subjectRelation,omitempty" url:"subjectRelation,omitempty"`
}
type Object struct {
ObjectType string `json:"objectType"`
ObjectId string `json:"objectId"`
Meta map[string]interface{} `json:"meta"`
}
func (object Object) GetObjectType() string {
return object.ObjectType
}
func (object Object) GetObjectId() string {
return object.ObjectId
}
type ObjectParams struct {
RequestOptions
ObjectType string `json:"objectType"`
ObjectId string `json:"objectId,omitempty"`
Meta map[string]interface{} `json:"meta,omitempty"`
}
type ListObjectParams struct {
ListParams
ObjectType string `json:"objectType,omitempty" url:"objectType,omitempty"`
Query string `json:"q,omitempty" url:"q,omitempty"`
}
type WarrantObject interface {
GetObjectType() string
GetObjectId() string
}
type WarrantCheck struct {
Object WarrantObject `json:"object"`
Relation string `json:"relation"`
Subject WarrantObject `json:"subject"`
Context PolicyContext `json:"context,omitempty"`
}
func (warrantCheck WarrantCheck) MarshalJSON() ([]byte, error) {
var m map[string]interface{}
subject, ok := warrantCheck.Subject.(*Subject)
if ok {
m = map[string]interface{}{
"objectType": warrantCheck.Object.GetObjectType(),
"objectId": warrantCheck.Object.GetObjectId(),
"relation": warrantCheck.Relation,
"subject": map[string]interface{}{
"objectType": subject.GetObjectType(),
"objectId": subject.GetObjectId(),
"relation": subject.GetRelation(),
},
"context": warrantCheck.Context,
}
} else {
m = map[string]interface{}{
"objectType": warrantCheck.Object.GetObjectType(),
"objectId": warrantCheck.Object.GetObjectId(),
"relation": warrantCheck.Relation,
"subject": map[string]interface{}{
"objectType": warrantCheck.Subject.GetObjectType(),
"objectId": warrantCheck.Subject.GetObjectId(),
},
"context": warrantCheck.Context,
}
}
return json.Marshal(m)
}
type WarrantCheckParams struct {
RequestOptions
WarrantCheck WarrantCheck `json:"warrantCheck"`
Debug bool `json:"debug,omitempty"`
}
type WarrantCheckManyParams struct {
RequestOptions
Op string `json:"op"`
Warrants []WarrantCheck `json:"warrants"`
Debug bool `json:"debug,omitempty"`
}
type WarrantCheckResult struct {
Code int64 `json:"code"`
Result string `json:"result"`
}
type PermissionCheckParams struct {
RequestOptions
PermissionId string `json:"permissionId"`
UserId string `json:"userId"`
Context PolicyContext `json:"context,omitempty"`
Debug bool `json:"debug,omitempty"`
}
type RoleCheckParams struct {
RequestOptions
RoleId string `json:"roleId"`
UserId string `json:"userId"`
Context PolicyContext `json:"context,omitempty"`
Debug bool `json:"debug,omitempty"`
}
type FeatureCheckParams struct {
RequestOptions
FeatureId string `json:"featureId"`
Subject Subject `json:"subject"`
Context PolicyContext `json:"context,omitempty"`
Debug bool `json:"debug,omitempty"`
}
type AccessCheckRequest struct {
RequestOptions
Op string `json:"op"`
Warrants []WarrantCheck `json:"warrants"`
Debug bool `json:"debug,omitempty"`
}