MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / ValidateFields

Method ValidateFields

pkg/ttnpb/rights.pb.validate.go:131–225  ·  view source on GitHub ↗

ValidateFields checks the field values on APIKey with the rules defined in the proto definition for this message. If any rules are violated, an error is returned.

(paths ...string)

Source from the content-addressed store, hash-verified

129// the proto definition for this message. If any rules are violated, an error
130// is returned.
131func (m *APIKey) ValidateFields(paths ...string) error {
132 if m == nil {
133 return nil
134 }
135
136 if len(paths) == 0 {
137 paths = APIKeyFieldPathsNested
138 }
139
140 for name, subs := range _processPaths(append(paths[:0:0], paths...)) {
141 _ = subs
142 switch name {
143 case "id":
144 // no validation rules for Id
145 case "key":
146 // no validation rules for Key
147 case "name":
148
149 if utf8.RuneCountInString(m.GetName()) > 50 {
150 return APIKeyValidationError{
151 field: "name",
152 reason: "value length must be at most 50 runes",
153 }
154 }
155
156 case "rights":
157
158 for idx, item := range m.GetRights() {
159 _, _ = idx, item
160
161 if _, ok := Right_name[int32(item)]; !ok {
162 return APIKeyValidationError{
163 field: fmt.Sprintf("rights[%v]", idx),
164 reason: "value must be one of the defined enum values",
165 }
166 }
167
168 }
169
170 case "created_at":
171
172 if v, ok := interface{}(m.GetCreatedAt()).(interface{ ValidateFields(...string) error }); ok {
173 if err := v.ValidateFields(subs...); err != nil {
174 return APIKeyValidationError{
175 field: "created_at",
176 reason: "embedded message failed validation",
177 cause: err,
178 }
179 }
180 }
181
182 case "updated_at":
183
184 if v, ok := interface{}(m.GetUpdatedAt()).(interface{ ValidateFields(...string) error }); ok {
185 if err := v.ValidateFields(subs...); err != nil {
186 return APIKeyValidationError{
187 field: "updated_at",
188 reason: "embedded message failed validation",

Callers

nothing calls this directly

Calls 9

GetNameMethod · 0.95
GetRightsMethod · 0.95
GetCreatedAtMethod · 0.95
GetUpdatedAtMethod · 0.95
GetExpiresAtMethod · 0.95
_processPathsFunction · 0.85
SubMethod · 0.80
NowMethod · 0.65
ValidateFieldsMethod · 0.45

Tested by

no test coverage detected