1// Code generated by protoc-gen-validate. DO NOT EDIT.
2// source: envoy/type/matcher/string.proto
3
4package envoy_type_matcher
5
6import (
7	"bytes"
8	"errors"
9	"fmt"
10	"net"
11	"net/mail"
12	"net/url"
13	"regexp"
14	"sort"
15	"strings"
16	"time"
17	"unicode/utf8"
18
19	"google.golang.org/protobuf/types/known/anypb"
20)
21
22// ensure the imports are used
23var (
24	_ = bytes.MinRead
25	_ = errors.New("")
26	_ = fmt.Print
27	_ = utf8.UTFMax
28	_ = (*regexp.Regexp)(nil)
29	_ = (*strings.Reader)(nil)
30	_ = net.IPv4len
31	_ = time.Duration(0)
32	_ = (*url.URL)(nil)
33	_ = (*mail.Address)(nil)
34	_ = anypb.Any{}
35	_ = sort.Sort
36)
37
38// Validate checks the field values on StringMatcher with the rules defined in
39// the proto definition for this message. If any rules are violated, the first
40// error encountered is returned, or nil if there are no violations.
41func (m *StringMatcher) Validate() error {
42	return m.validate(false)
43}
44
45// ValidateAll checks the field values on StringMatcher with the rules defined
46// in the proto definition for this message. If any rules are violated, the
47// result is a list of violation errors wrapped in StringMatcherMultiError, or
48// nil if none found.
49func (m *StringMatcher) ValidateAll() error {
50	return m.validate(true)
51}
52
53func (m *StringMatcher) validate(all bool) error {
54	if m == nil {
55		return nil
56	}
57
58	var errors []error
59
60	// no validation rules for IgnoreCase
61
62	switch m.MatchPattern.(type) {
63
64	case *StringMatcher_Exact:
65		// no validation rules for Exact
66
67	case *StringMatcher_Prefix:
68
69		if utf8.RuneCountInString(m.GetPrefix()) < 1 {
70			err := StringMatcherValidationError{
71				field:  "Prefix",
72				reason: "value length must be at least 1 runes",
73			}
74			if !all {
75				return err
76			}
77			errors = append(errors, err)
78		}
79
80	case *StringMatcher_Suffix:
81
82		if utf8.RuneCountInString(m.GetSuffix()) < 1 {
83			err := StringMatcherValidationError{
84				field:  "Suffix",
85				reason: "value length must be at least 1 runes",
86			}
87			if !all {
88				return err
89			}
90			errors = append(errors, err)
91		}
92
93	case *StringMatcher_Regex:
94
95		if len(m.GetRegex()) > 1024 {
96			err := StringMatcherValidationError{
97				field:  "Regex",
98				reason: "value length must be at most 1024 bytes",
99			}
100			if !all {
101				return err
102			}
103			errors = append(errors, err)
104		}
105
106	case *StringMatcher_SafeRegex:
107
108		if m.GetSafeRegex() == nil {
109			err := StringMatcherValidationError{
110				field:  "SafeRegex",
111				reason: "value is required",
112			}
113			if !all {
114				return err
115			}
116			errors = append(errors, err)
117		}
118
119		if all {
120			switch v := interface{}(m.GetSafeRegex()).(type) {
121			case interface{ ValidateAll() error }:
122				if err := v.ValidateAll(); err != nil {
123					errors = append(errors, StringMatcherValidationError{
124						field:  "SafeRegex",
125						reason: "embedded message failed validation",
126						cause:  err,
127					})
128				}
129			case interface{ Validate() error }:
130				if err := v.Validate(); err != nil {
131					errors = append(errors, StringMatcherValidationError{
132						field:  "SafeRegex",
133						reason: "embedded message failed validation",
134						cause:  err,
135					})
136				}
137			}
138		} else if v, ok := interface{}(m.GetSafeRegex()).(interface{ Validate() error }); ok {
139			if err := v.Validate(); err != nil {
140				return StringMatcherValidationError{
141					field:  "SafeRegex",
142					reason: "embedded message failed validation",
143					cause:  err,
144				}
145			}
146		}
147
148	default:
149		err := StringMatcherValidationError{
150			field:  "MatchPattern",
151			reason: "value is required",
152		}
153		if !all {
154			return err
155		}
156		errors = append(errors, err)
157
158	}
159
160	if len(errors) > 0 {
161		return StringMatcherMultiError(errors)
162	}
163	return nil
164}
165
166// StringMatcherMultiError is an error wrapping multiple validation errors
167// returned by StringMatcher.ValidateAll() if the designated constraints
168// aren't met.
169type StringMatcherMultiError []error
170
171// Error returns a concatenation of all the error messages it wraps.
172func (m StringMatcherMultiError) Error() string {
173	var msgs []string
174	for _, err := range m {
175		msgs = append(msgs, err.Error())
176	}
177	return strings.Join(msgs, "; ")
178}
179
180// AllErrors returns a list of validation violation errors.
181func (m StringMatcherMultiError) AllErrors() []error { return m }
182
183// StringMatcherValidationError is the validation error returned by
184// StringMatcher.Validate if the designated constraints aren't met.
185type StringMatcherValidationError struct {
186	field  string
187	reason string
188	cause  error
189	key    bool
190}
191
192// Field function returns field value.
193func (e StringMatcherValidationError) Field() string { return e.field }
194
195// Reason function returns reason value.
196func (e StringMatcherValidationError) Reason() string { return e.reason }
197
198// Cause function returns cause value.
199func (e StringMatcherValidationError) Cause() error { return e.cause }
200
201// Key function returns key value.
202func (e StringMatcherValidationError) Key() bool { return e.key }
203
204// ErrorName returns error name.
205func (e StringMatcherValidationError) ErrorName() string { return "StringMatcherValidationError" }
206
207// Error satisfies the builtin error interface
208func (e StringMatcherValidationError) Error() string {
209	cause := ""
210	if e.cause != nil {
211		cause = fmt.Sprintf(" | caused by: %v", e.cause)
212	}
213
214	key := ""
215	if e.key {
216		key = "key for "
217	}
218
219	return fmt.Sprintf(
220		"invalid %sStringMatcher.%s: %s%s",
221		key,
222		e.field,
223		e.reason,
224		cause)
225}
226
227var _ error = StringMatcherValidationError{}
228
229var _ interface {
230	Field() string
231	Reason() string
232	Key() bool
233	Cause() error
234	ErrorName() string
235} = StringMatcherValidationError{}
236
237// Validate checks the field values on ListStringMatcher with the rules defined
238// in the proto definition for this message. If any rules are violated, the
239// first error encountered is returned, or nil if there are no violations.
240func (m *ListStringMatcher) Validate() error {
241	return m.validate(false)
242}
243
244// ValidateAll checks the field values on ListStringMatcher with the rules
245// defined in the proto definition for this message. If any rules are
246// violated, the result is a list of violation errors wrapped in
247// ListStringMatcherMultiError, or nil if none found.
248func (m *ListStringMatcher) ValidateAll() error {
249	return m.validate(true)
250}
251
252func (m *ListStringMatcher) validate(all bool) error {
253	if m == nil {
254		return nil
255	}
256
257	var errors []error
258
259	if len(m.GetPatterns()) < 1 {
260		err := ListStringMatcherValidationError{
261			field:  "Patterns",
262			reason: "value must contain at least 1 item(s)",
263		}
264		if !all {
265			return err
266		}
267		errors = append(errors, err)
268	}
269
270	for idx, item := range m.GetPatterns() {
271		_, _ = idx, item
272
273		if all {
274			switch v := interface{}(item).(type) {
275			case interface{ ValidateAll() error }:
276				if err := v.ValidateAll(); err != nil {
277					errors = append(errors, ListStringMatcherValidationError{
278						field:  fmt.Sprintf("Patterns[%v]", idx),
279						reason: "embedded message failed validation",
280						cause:  err,
281					})
282				}
283			case interface{ Validate() error }:
284				if err := v.Validate(); err != nil {
285					errors = append(errors, ListStringMatcherValidationError{
286						field:  fmt.Sprintf("Patterns[%v]", idx),
287						reason: "embedded message failed validation",
288						cause:  err,
289					})
290				}
291			}
292		} else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
293			if err := v.Validate(); err != nil {
294				return ListStringMatcherValidationError{
295					field:  fmt.Sprintf("Patterns[%v]", idx),
296					reason: "embedded message failed validation",
297					cause:  err,
298				}
299			}
300		}
301
302	}
303
304	if len(errors) > 0 {
305		return ListStringMatcherMultiError(errors)
306	}
307	return nil
308}
309
310// ListStringMatcherMultiError is an error wrapping multiple validation errors
311// returned by ListStringMatcher.ValidateAll() if the designated constraints
312// aren't met.
313type ListStringMatcherMultiError []error
314
315// Error returns a concatenation of all the error messages it wraps.
316func (m ListStringMatcherMultiError) Error() string {
317	var msgs []string
318	for _, err := range m {
319		msgs = append(msgs, err.Error())
320	}
321	return strings.Join(msgs, "; ")
322}
323
324// AllErrors returns a list of validation violation errors.
325func (m ListStringMatcherMultiError) AllErrors() []error { return m }
326
327// ListStringMatcherValidationError is the validation error returned by
328// ListStringMatcher.Validate if the designated constraints aren't met.
329type ListStringMatcherValidationError struct {
330	field  string
331	reason string
332	cause  error
333	key    bool
334}
335
336// Field function returns field value.
337func (e ListStringMatcherValidationError) Field() string { return e.field }
338
339// Reason function returns reason value.
340func (e ListStringMatcherValidationError) Reason() string { return e.reason }
341
342// Cause function returns cause value.
343func (e ListStringMatcherValidationError) Cause() error { return e.cause }
344
345// Key function returns key value.
346func (e ListStringMatcherValidationError) Key() bool { return e.key }
347
348// ErrorName returns error name.
349func (e ListStringMatcherValidationError) ErrorName() string {
350	return "ListStringMatcherValidationError"
351}
352
353// Error satisfies the builtin error interface
354func (e ListStringMatcherValidationError) Error() string {
355	cause := ""
356	if e.cause != nil {
357		cause = fmt.Sprintf(" | caused by: %v", e.cause)
358	}
359
360	key := ""
361	if e.key {
362		key = "key for "
363	}
364
365	return fmt.Sprintf(
366		"invalid %sListStringMatcher.%s: %s%s",
367		key,
368		e.field,
369		e.reason,
370		cause)
371}
372
373var _ error = ListStringMatcherValidationError{}
374
375var _ interface {
376	Field() string
377	Reason() string
378	Key() bool
379	Cause() error
380	ErrorName() string
381} = ListStringMatcherValidationError{}
382