Skip to content

Commit 7f45c77

Browse files
committed
refactor: rename proto messages to avoid native type conflicts
1 parent ae19e13 commit 7f45c77

File tree

8 files changed

+497
-470
lines changed

8 files changed

+497
-470
lines changed

internal/engines/check.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func (engine *CheckEngine) checkTupleToUserSet(
412412
// ComputedUserSet data structure. It returns a CheckFunction closure that performs the check.
413413
func (engine *CheckEngine) checkComputedUserSet(
414414
request *base.PermissionCheckRequest, // The request containing details about the permission to be checked
415-
cu *base.ComputedUserSet, // The computed user set containing user set information
415+
cu *base.ComputedUserSet, // The computed user set containing user set information
416416
) CheckFunction {
417417
// The returned CheckFunction invokes a permission check with a new request that is almost the same
418418
// as the incoming request, but changes the Permission to be the relation defined in the computed user set.
@@ -496,14 +496,14 @@ func (engine *CheckEngine) checkDirectAttribute(
496496
}
497497

498498
// Unmarshal the attribute value into a BoolValue message.
499-
var msg base.Boolean
499+
var msg base.BoolValue
500500
if err := val.GetValue().UnmarshalTo(&msg); err != nil {
501501
// If there was an error unmarshaling, return a denied response and the error.
502502
return denied(&base.PermissionCheckResponseMetadata{}), err
503503
}
504504

505505
// If the attribute's value is true, return an allowed response.
506-
if msg.Value {
506+
if msg.Data {
507507
return allowed(&base.PermissionCheckResponseMetadata{}), nil
508508
}
509509

@@ -516,7 +516,7 @@ func (engine *CheckEngine) checkDirectAttribute(
516516
// It returns a function (CheckFunction) that when called, performs the permission check.
517517
func (engine *CheckEngine) checkCall(
518518
request *base.PermissionCheckRequest, // The request containing the details for the permission check
519-
call *base.Call, // The specific call to be checked
519+
call *base.Call, // The specific call to be checked
520520
) CheckFunction {
521521
// The function returned by checkCall
522522
return func(ctx context.Context) (*base.PermissionCheckResponse, error) {

internal/engines/expand.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ func (engine *ExpandEngine) expandDirectAttribute(
519519
},
520520
Attribute: request.GetPermission(),
521521
}
522-
val.Value, err = anypb.New(&base.Boolean{Value: false})
522+
val.Value, err = anypb.New(&base.BoolValue{Data: false})
523523
if err != nil {
524524
expandChan <- expandFailResponse(err)
525525
return
@@ -550,7 +550,7 @@ func (engine *ExpandEngine) expandDirectAttribute(
550550
// It takes a PermissionExpandRequest and a Call as parameters and returns an ExpandFunction.
551551
func (engine *ExpandEngine) expandCall(
552552
request *base.PermissionExpandRequest, // The request object containing information necessary for the expansion.
553-
call *base.Call, // The call object that defines the rule name and its arguments.
553+
call *base.Call, // The call object that defines the rule name and its arguments.
554554
) ExpandFunction { // The function returns an ExpandFunction.
555555
return func(ctx context.Context, expandChan chan<- ExpandResponse) { // defining the returned function.
556556

@@ -688,7 +688,7 @@ func (engine *ExpandEngine) expandCall(
688688
// It takes a PermissionExpandRequest and a ComputedAttribute as parameters and returns an ExpandFunction.
689689
func (engine *ExpandEngine) expandComputedAttribute(
690690
request *base.PermissionExpandRequest, // The request object containing necessary information for the expansion.
691-
ca *base.ComputedAttribute, // The computed attribute object that has the name of the attribute to be computed.
691+
ca *base.ComputedAttribute, // The computed attribute object that has the name of the attribute to be computed.
692692
) ExpandFunction { // The function returns an ExpandFunction.
693693
return func(ctx context.Context, resultChan chan<- ExpandResponse) { // defining the returned function.
694694

@@ -712,11 +712,11 @@ func (engine *ExpandEngine) expandComputedAttribute(
712712
// a slice of arguments, slice of ExpandFunctions, and an operation of type base.ExpandTreeNode_Operation.
713713
// It returns an ExpandResponse.
714714
func expandOperation(
715-
ctx context.Context, // The context of this operation, which may carry deadlines, cancellation signals, etc.
716-
entity *base.Entity, // The entity on which the operation will be performed.
717-
permission string, // The permission string required for the operation.
718-
arguments []*base.Argument, // A slice of arguments required for the operation.
719-
functions []ExpandFunction, // A slice of functions that will be used to expand the operation.
715+
ctx context.Context, // The context of this operation, which may carry deadlines, cancellation signals, etc.
716+
entity *base.Entity, // The entity on which the operation will be performed.
717+
permission string, // The permission string required for the operation.
718+
arguments []*base.Argument, // A slice of arguments required for the operation.
719+
functions []ExpandFunction, // A slice of functions that will be used to expand the operation.
720720
op base.ExpandTreeNode_Operation, // The operation to be performed.
721721
) ExpandResponse { // The function returns an ExpandResponse.
722722

internal/engines/utils.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,63 +169,63 @@ func getEmptyProtoValueForType(typ base.AttributeType) (*anypb.Any, error) {
169169
switch typ {
170170
case base.AttributeType_ATTRIBUTE_TYPE_STRING:
171171
// Create an empty protobuf String message
172-
value, err := anypb.New(&base.String{Value: ""})
172+
value, err := anypb.New(&base.StringValue{Data: ""})
173173
if err != nil {
174174
return nil, err
175175
}
176176
return value, nil
177177

178178
case base.AttributeType_ATTRIBUTE_TYPE_STRING_ARRAY:
179179
// Create an empty protobuf StringArray message
180-
value, err := anypb.New(&base.StringArray{Values: []string{}})
180+
value, err := anypb.New(&base.StringArrayValue{Data: []string{}})
181181
if err != nil {
182182
return nil, err
183183
}
184184
return value, nil
185185

186186
case base.AttributeType_ATTRIBUTE_TYPE_INTEGER:
187187
// Create an empty protobuf Integer message
188-
value, err := anypb.New(&base.Integer{Value: 0})
188+
value, err := anypb.New(&base.IntegerValue{Data: 0})
189189
if err != nil {
190190
return nil, err
191191
}
192192
return value, nil
193193

194194
case base.AttributeType_ATTRIBUTE_TYPE_INTEGER_ARRAY:
195195
// Create an empty protobuf IntegerArray message
196-
value, err := anypb.New(&base.IntegerArray{Values: []int32{}})
196+
value, err := anypb.New(&base.IntegerArrayValue{Data: []int32{}})
197197
if err != nil {
198198
return nil, err
199199
}
200200
return value, nil
201201

202202
case base.AttributeType_ATTRIBUTE_TYPE_DOUBLE:
203203
// Create an empty protobuf Double message
204-
value, err := anypb.New(&base.Double{Value: 0.0})
204+
value, err := anypb.New(&base.DoubleValue{Data: 0.0})
205205
if err != nil {
206206
return nil, err
207207
}
208208
return value, nil
209209

210210
case base.AttributeType_ATTRIBUTE_TYPE_DOUBLE_ARRAY:
211211
// Create an empty protobuf DoubleArray message
212-
value, err := anypb.New(&base.DoubleArray{Values: []float64{}})
212+
value, err := anypb.New(&base.DoubleArrayValue{Data: []float64{}})
213213
if err != nil {
214214
return nil, err
215215
}
216216
return value, nil
217217

218218
case base.AttributeType_ATTRIBUTE_TYPE_BOOLEAN:
219219
// Create an empty protobuf Boolean message with a default value of false
220-
value, err := anypb.New(&base.Boolean{Value: false})
220+
value, err := anypb.New(&base.BoolValue{Data: false})
221221
if err != nil {
222222
return nil, err
223223
}
224224
return value, nil
225225

226226
case base.AttributeType_ATTRIBUTE_TYPE_BOOLEAN_ARRAY:
227227
// Create an empty protobuf BooleanArray message
228-
value, err := anypb.New(&base.BooleanArray{Values: []bool{}})
228+
value, err := anypb.New(&base.BoolArrayValue{Data: []bool{}})
229229
if err != nil {
230230
return nil, err
231231
}
@@ -249,21 +249,21 @@ func ConvertToAnyPB(value interface{}) (*anypb.Any, error) {
249249
// Use a type switch to handle different types of value.
250250
switch v := value.(type) {
251251
case bool:
252-
anyValue, err = anypb.New(&base.Boolean{Value: v})
252+
anyValue, err = anypb.New(&base.BoolValue{Data: v})
253253
case []bool:
254-
anyValue, err = anypb.New(&base.BooleanArray{Values: v})
254+
anyValue, err = anypb.New(&base.BoolArrayValue{Data: v})
255255
case int:
256-
anyValue, err = anypb.New(&base.Integer{Value: int32(v)})
256+
anyValue, err = anypb.New(&base.IntegerValue{Data: int32(v)})
257257
case []int32:
258-
anyValue, err = anypb.New(&base.IntegerArray{Values: v})
258+
anyValue, err = anypb.New(&base.IntegerArrayValue{Data: v})
259259
case float64:
260-
anyValue, err = anypb.New(&base.Double{Value: v})
260+
anyValue, err = anypb.New(&base.DoubleValue{Data: v})
261261
case []float64:
262-
anyValue, err = anypb.New(&base.DoubleArray{Values: v})
262+
anyValue, err = anypb.New(&base.DoubleArrayValue{Data: v})
263263
case string:
264-
anyValue, err = anypb.New(&base.String{Value: v})
264+
anyValue, err = anypb.New(&base.StringValue{Data: v})
265265
case []string:
266-
anyValue, err = anypb.New(&base.StringArray{Values: v})
266+
anyValue, err = anypb.New(&base.StringArrayValue{Data: v})
267267
default:
268268
// In case of an unsupported or unknown type, we return an error.
269269
return nil, errors.New("unknown type")

pkg/attribute/attribute.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func Attribute(attribute string) (*base.Attribute, error) {
5858
if err != nil {
5959
return nil, fmt.Errorf("failed to parse boolean: %v", err)
6060
}
61-
wrapped = &base.Boolean{Value: boolVal}
61+
wrapped = &base.BoolValue{Data: boolVal}
6262
case "boolean[]":
6363
var ba []bool
6464
val := strings.Split(v[1], ",")
@@ -69,22 +69,22 @@ func Attribute(attribute string) (*base.Attribute, error) {
6969
}
7070
ba = append(ba, boolVal)
7171
}
72-
wrapped = &base.BooleanArray{Values: ba}
72+
wrapped = &base.BoolArrayValue{Data: ba}
7373
case "string":
74-
wrapped = &base.String{Value: v[1]}
74+
wrapped = &base.StringValue{Data: v[1]}
7575
case "string[]":
7676
var sa []string
7777
val := strings.Split(v[1], ",")
7878
for _, value := range val {
7979
sa = append(sa, value)
8080
}
81-
wrapped = &base.StringArray{Values: sa}
81+
wrapped = &base.StringArrayValue{Data: sa}
8282
case "double":
8383
doubleVal, err := strconv.ParseFloat(v[1], 64)
8484
if err != nil {
8585
return nil, fmt.Errorf("failed to parse float: %v", err)
8686
}
87-
wrapped = &base.Double{Value: doubleVal}
87+
wrapped = &base.DoubleValue{Data: doubleVal}
8888
case "double[]":
8989
var da []float64
9090
val := strings.Split(v[1], ",")
@@ -95,13 +95,13 @@ func Attribute(attribute string) (*base.Attribute, error) {
9595
}
9696
da = append(da, doubleVal)
9797
}
98-
wrapped = &base.DoubleArray{Values: da}
98+
wrapped = &base.DoubleArrayValue{Data: da}
9999
case "integer":
100100
intVal, err := strconv.ParseInt(v[1], 10, 32)
101101
if err != nil {
102102
return nil, fmt.Errorf("failed to parse integer: %v", err)
103103
}
104-
wrapped = &base.Integer{Value: int32(intVal)}
104+
wrapped = &base.IntegerValue{Data: int32(intVal)}
105105
case "integer[]":
106106

107107
var ia []int32
@@ -113,7 +113,7 @@ func Attribute(attribute string) (*base.Attribute, error) {
113113
}
114114
ia = append(ia, int32(intVal))
115115
}
116-
wrapped = &base.IntegerArray{Values: ia}
116+
wrapped = &base.IntegerArrayValue{Data: ia}
117117
default:
118118
return nil, ErrInvalidValue
119119
}
@@ -184,66 +184,66 @@ func AnyToString(any *anypb.Any) string {
184184
// Convert the Any proto message into string based on its TypeUrl
185185
switch any.TypeUrl {
186186
case "type.googleapis.com/base.v1.Boolean":
187-
boolVal := &base.Boolean{}
187+
boolVal := &base.BoolValue{}
188188
if err := any.UnmarshalTo(boolVal); err != nil {
189189
return "undefined"
190190
}
191-
str = strconv.FormatBool(boolVal.Value)
191+
str = strconv.FormatBool(boolVal.Data)
192192
case "type.googleapis.com/base.v1.BooleanArray":
193-
boolVal := &base.BooleanArray{}
193+
boolVal := &base.BoolArrayValue{}
194194
if err := any.UnmarshalTo(boolVal); err != nil {
195195
return "undefined"
196196
}
197197
var strs []string
198-
for _, b := range boolVal.GetValues() {
198+
for _, b := range boolVal.GetData() {
199199
strs = append(strs, strconv.FormatBool(b))
200200
}
201201
str = strings.Join(strs, ",")
202202
case "type.googleapis.com/base.v1.String":
203-
stringVal := &base.String{}
203+
stringVal := &base.StringValue{}
204204
if err := any.UnmarshalTo(stringVal); err != nil {
205205
return "undefined"
206206
}
207-
str = stringVal.Value
207+
str = stringVal.Data
208208
case "type.googleapis.com/base.v1.StringArray":
209-
stringVal := &base.StringArray{}
209+
stringVal := &base.StringArrayValue{}
210210
if err := any.UnmarshalTo(stringVal); err != nil {
211211
return "undefined"
212212
}
213213
var strs []string
214-
for _, v := range stringVal.GetValues() {
214+
for _, v := range stringVal.GetData() {
215215
strs = append(strs, v)
216216
}
217217
str = strings.Join(strs, ",")
218218
case "type.googleapis.com/base.v1.Double":
219-
doubleVal := &base.Double{}
219+
doubleVal := &base.DoubleValue{}
220220
if err := any.UnmarshalTo(doubleVal); err != nil {
221221
return "undefined"
222222
}
223-
str = strconv.FormatFloat(doubleVal.Value, 'f', -1, 64)
223+
str = strconv.FormatFloat(doubleVal.Data, 'f', -1, 64)
224224
case "type.googleapis.com/base.v1.DoubleArray":
225-
doubleVal := &base.DoubleArray{}
225+
doubleVal := &base.DoubleArrayValue{}
226226
if err := any.UnmarshalTo(doubleVal); err != nil {
227227
return "undefined"
228228
}
229229
var strs []string
230-
for _, v := range doubleVal.GetValues() {
230+
for _, v := range doubleVal.GetData() {
231231
strs = append(strs, strconv.FormatFloat(v, 'f', -1, 64))
232232
}
233233
str = strings.Join(strs, ",")
234234
case "type.googleapis.com/base.v1.Integer":
235-
intVal := &base.Integer{}
235+
intVal := &base.IntegerValue{}
236236
if err := any.UnmarshalTo(intVal); err != nil {
237237
return "undefined"
238238
}
239-
str = strconv.Itoa(int(intVal.Value))
239+
str = strconv.Itoa(int(intVal.Data))
240240
case "type.googleapis.com/base.v1.IntegerArray":
241-
intVal := &base.IntegerArray{}
241+
intVal := &base.IntegerArrayValue{}
242242
if err := any.UnmarshalTo(intVal); err != nil {
243243
return "undefined"
244244
}
245245
var strs []string
246-
for _, v := range intVal.GetValues() {
246+
for _, v := range intVal.GetData() {
247247
strs = append(strs, strconv.Itoa(int(v)))
248248
}
249249
str = strings.Join(strs, ",")
@@ -293,21 +293,21 @@ func ValidateValue(any *anypb.Any, attributeType base.AttributeType) error {
293293
// Depending on the expected attribute type, assign 'target' a new instance of the corresponding specific type.
294294
switch attributeType {
295295
case base.AttributeType_ATTRIBUTE_TYPE_INTEGER:
296-
target = &base.Integer{}
296+
target = &base.IntegerValue{}
297297
case base.AttributeType_ATTRIBUTE_TYPE_INTEGER_ARRAY:
298-
target = &base.IntegerArray{}
298+
target = &base.IntegerArrayValue{}
299299
case base.AttributeType_ATTRIBUTE_TYPE_DOUBLE:
300-
target = &base.Double{}
300+
target = &base.DoubleValue{}
301301
case base.AttributeType_ATTRIBUTE_TYPE_DOUBLE_ARRAY:
302-
target = &base.DoubleArray{}
302+
target = &base.DoubleArrayValue{}
303303
case base.AttributeType_ATTRIBUTE_TYPE_STRING:
304-
target = &base.String{}
304+
target = &base.StringValue{}
305305
case base.AttributeType_ATTRIBUTE_TYPE_STRING_ARRAY:
306-
target = &base.StringArray{}
306+
target = &base.StringArrayValue{}
307307
case base.AttributeType_ATTRIBUTE_TYPE_BOOLEAN:
308-
target = &base.Boolean{}
308+
target = &base.BoolValue{}
309309
case base.AttributeType_ATTRIBUTE_TYPE_BOOLEAN_ARRAY:
310-
target = &base.BooleanArray{}
310+
target = &base.BoolArrayValue{}
311311
default:
312312
// If attributeType doesn't match any of the known types, return an error indicating invalid argument.
313313
return errors.New(base.ErrorCode_ERROR_CODE_INVALID_ARGUMENT.String())

0 commit comments

Comments
 (0)