MCPcopy Create free account
hub / github.com/Permify/permify / ValidateSubjectType

Function ValidateSubjectType

pkg/tuple/tuple.go:111–125  ·  view source on GitHub ↗

ValidateSubjectType validates if the subject type and relation are present in the list of allowed relation types

(subject *base.Subject, relationTypes []string)

Source from the content-addressed store, hash-verified

109
110// ValidateSubjectType validates if the subject type and relation are present in the list of allowed relation types
111func ValidateSubjectType(subject *base.Subject, relationTypes []string) (err error) {
112 if len(relationTypes) == 0 {
113 return errors.New(base.ErrorCode_ERROR_CODE_SUBJECT_TYPE_NOT_FOUND.String())
114 }
115
116 key := subject.GetType()
117 if subject.GetRelation() != "" && subject.GetRelation() != ELLIPSIS {
118 key += "#" + subject.GetRelation() // append relation to key
119 }
120
121 if !slices.Contains(relationTypes, key) { // check if key is in relationTypes
122 return errors.New(base.ErrorCode_ERROR_CODE_SUBJECT_TYPE_NOT_FOUND.String()) // return error if not found
123 }
124 return nil // return nil if validation succeeds
125}
126
127// SplitRelation splits a relation string by the separator "." and returns the result as a slice
128func SplitRelation(relation string) (a []string) {

Callers 2

ValidateTupleFunction · 0.92
tuple_test.goFile · 0.85

Calls 3

StringMethod · 0.65
GetTypeMethod · 0.65
GetRelationMethod · 0.45

Tested by

no test coverage detected