1// Code generated by protoc-gen-validate. DO NOT EDIT.
2// source: envoy/type/matcher/v3/metadata.proto
3
4package envoy_type_matcher_v3
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 MetadataMatcher with the rules defined
39// in the proto definition for this message. If any rules are violated, the
40// first error encountered is returned, or nil if there are no violations.
41func (m *MetadataMatcher) Validate() error {
42	return m.validate(false)
43}
44
45// ValidateAll checks the field values on MetadataMatcher with the rules
46// defined in the proto definition for this message. If any rules are
47// violated, the result is a list of violation errors wrapped in
48// MetadataMatcherMultiError, or nil if none found.
49func (m *MetadataMatcher) ValidateAll() error {
50	return m.validate(true)
51}
52
53func (m *MetadataMatcher) validate(all bool) error {
54	if m == nil {
55		return nil
56	}
57
58	var errors []error
59
60	if utf8.RuneCountInString(m.GetFilter()) < 1 {
61		err := MetadataMatcherValidationError{
62			field:  "Filter",
63			reason: "value length must be at least 1 runes",
64		}
65		if !all {
66			return err
67		}
68		errors = append(errors, err)
69	}
70
71	if len(m.GetPath()) < 1 {
72		err := MetadataMatcherValidationError{
73			field:  "Path",
74			reason: "value must contain at least 1 item(s)",
75		}
76		if !all {
77			return err
78		}
79		errors = append(errors, err)
80	}
81
82	for idx, item := range m.GetPath() {
83		_, _ = idx, item
84
85		if all {
86			switch v := interface{}(item).(type) {
87			case interface{ ValidateAll() error }:
88				if err := v.ValidateAll(); err != nil {
89					errors = append(errors, MetadataMatcherValidationError{
90						field:  fmt.Sprintf("Path[%v]", idx),
91						reason: "embedded message failed validation",
92						cause:  err,
93					})
94				}
95			case interface{ Validate() error }:
96				if err := v.Validate(); err != nil {
97					errors = append(errors, MetadataMatcherValidationError{
98						field:  fmt.Sprintf("Path[%v]", idx),
99						reason: "embedded message failed validation",
100						cause:  err,
101					})
102				}
103			}
104		} else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
105			if err := v.Validate(); err != nil {
106				return MetadataMatcherValidationError{
107					field:  fmt.Sprintf("Path[%v]", idx),
108					reason: "embedded message failed validation",
109					cause:  err,
110				}
111			}
112		}
113
114	}
115
116	if m.GetValue() == nil {
117		err := MetadataMatcherValidationError{
118			field:  "Value",
119			reason: "value is required",
120		}
121		if !all {
122			return err
123		}
124		errors = append(errors, err)
125	}
126
127	if all {
128		switch v := interface{}(m.GetValue()).(type) {
129		case interface{ ValidateAll() error }:
130			if err := v.ValidateAll(); err != nil {
131				errors = append(errors, MetadataMatcherValidationError{
132					field:  "Value",
133					reason: "embedded message failed validation",
134					cause:  err,
135				})
136			}
137		case interface{ Validate() error }:
138			if err := v.Validate(); err != nil {
139				errors = append(errors, MetadataMatcherValidationError{
140					field:  "Value",
141					reason: "embedded message failed validation",
142					cause:  err,
143				})
144			}
145		}
146	} else if v, ok := interface{}(m.GetValue()).(interface{ Validate() error }); ok {
147		if err := v.Validate(); err != nil {
148			return MetadataMatcherValidationError{
149				field:  "Value",
150				reason: "embedded message failed validation",
151				cause:  err,
152			}
153		}
154	}
155
156	// no validation rules for Invert
157
158	if len(errors) > 0 {
159		return MetadataMatcherMultiError(errors)
160	}
161	return nil
162}
163
164// MetadataMatcherMultiError is an error wrapping multiple validation errors
165// returned by MetadataMatcher.ValidateAll() if the designated constraints
166// aren't met.
167type MetadataMatcherMultiError []error
168
169// Error returns a concatenation of all the error messages it wraps.
170func (m MetadataMatcherMultiError) Error() string {
171	var msgs []string
172	for _, err := range m {
173		msgs = append(msgs, err.Error())
174	}
175	return strings.Join(msgs, "; ")
176}
177
178// AllErrors returns a list of validation violation errors.
179func (m MetadataMatcherMultiError) AllErrors() []error { return m }
180
181// MetadataMatcherValidationError is the validation error returned by
182// MetadataMatcher.Validate if the designated constraints aren't met.
183type MetadataMatcherValidationError struct {
184	field  string
185	reason string
186	cause  error
187	key    bool
188}
189
190// Field function returns field value.
191func (e MetadataMatcherValidationError) Field() string { return e.field }
192
193// Reason function returns reason value.
194func (e MetadataMatcherValidationError) Reason() string { return e.reason }
195
196// Cause function returns cause value.
197func (e MetadataMatcherValidationError) Cause() error { return e.cause }
198
199// Key function returns key value.
200func (e MetadataMatcherValidationError) Key() bool { return e.key }
201
202// ErrorName returns error name.
203func (e MetadataMatcherValidationError) ErrorName() string { return "MetadataMatcherValidationError" }
204
205// Error satisfies the builtin error interface
206func (e MetadataMatcherValidationError) Error() string {
207	cause := ""
208	if e.cause != nil {
209		cause = fmt.Sprintf(" | caused by: %v", e.cause)
210	}
211
212	key := ""
213	if e.key {
214		key = "key for "
215	}
216
217	return fmt.Sprintf(
218		"invalid %sMetadataMatcher.%s: %s%s",
219		key,
220		e.field,
221		e.reason,
222		cause)
223}
224
225var _ error = MetadataMatcherValidationError{}
226
227var _ interface {
228	Field() string
229	Reason() string
230	Key() bool
231	Cause() error
232	ErrorName() string
233} = MetadataMatcherValidationError{}
234
235// Validate checks the field values on MetadataMatcher_PathSegment with the
236// rules defined in the proto definition for this message. If any rules are
237// violated, the first error encountered is returned, or nil if there are no violations.
238func (m *MetadataMatcher_PathSegment) Validate() error {
239	return m.validate(false)
240}
241
242// ValidateAll checks the field values on MetadataMatcher_PathSegment with the
243// rules defined in the proto definition for this message. If any rules are
244// violated, the result is a list of violation errors wrapped in
245// MetadataMatcher_PathSegmentMultiError, or nil if none found.
246func (m *MetadataMatcher_PathSegment) ValidateAll() error {
247	return m.validate(true)
248}
249
250func (m *MetadataMatcher_PathSegment) validate(all bool) error {
251	if m == nil {
252		return nil
253	}
254
255	var errors []error
256
257	switch m.Segment.(type) {
258
259	case *MetadataMatcher_PathSegment_Key:
260
261		if utf8.RuneCountInString(m.GetKey()) < 1 {
262			err := MetadataMatcher_PathSegmentValidationError{
263				field:  "Key",
264				reason: "value length must be at least 1 runes",
265			}
266			if !all {
267				return err
268			}
269			errors = append(errors, err)
270		}
271
272	default:
273		err := MetadataMatcher_PathSegmentValidationError{
274			field:  "Segment",
275			reason: "value is required",
276		}
277		if !all {
278			return err
279		}
280		errors = append(errors, err)
281
282	}
283
284	if len(errors) > 0 {
285		return MetadataMatcher_PathSegmentMultiError(errors)
286	}
287	return nil
288}
289
290// MetadataMatcher_PathSegmentMultiError is an error wrapping multiple
291// validation errors returned by MetadataMatcher_PathSegment.ValidateAll() if
292// the designated constraints aren't met.
293type MetadataMatcher_PathSegmentMultiError []error
294
295// Error returns a concatenation of all the error messages it wraps.
296func (m MetadataMatcher_PathSegmentMultiError) Error() string {
297	var msgs []string
298	for _, err := range m {
299		msgs = append(msgs, err.Error())
300	}
301	return strings.Join(msgs, "; ")
302}
303
304// AllErrors returns a list of validation violation errors.
305func (m MetadataMatcher_PathSegmentMultiError) AllErrors() []error { return m }
306
307// MetadataMatcher_PathSegmentValidationError is the validation error returned
308// by MetadataMatcher_PathSegment.Validate if the designated constraints
309// aren't met.
310type MetadataMatcher_PathSegmentValidationError struct {
311	field  string
312	reason string
313	cause  error
314	key    bool
315}
316
317// Field function returns field value.
318func (e MetadataMatcher_PathSegmentValidationError) Field() string { return e.field }
319
320// Reason function returns reason value.
321func (e MetadataMatcher_PathSegmentValidationError) Reason() string { return e.reason }
322
323// Cause function returns cause value.
324func (e MetadataMatcher_PathSegmentValidationError) Cause() error { return e.cause }
325
326// Key function returns key value.
327func (e MetadataMatcher_PathSegmentValidationError) Key() bool { return e.key }
328
329// ErrorName returns error name.
330func (e MetadataMatcher_PathSegmentValidationError) ErrorName() string {
331	return "MetadataMatcher_PathSegmentValidationError"
332}
333
334// Error satisfies the builtin error interface
335func (e MetadataMatcher_PathSegmentValidationError) Error() string {
336	cause := ""
337	if e.cause != nil {
338		cause = fmt.Sprintf(" | caused by: %v", e.cause)
339	}
340
341	key := ""
342	if e.key {
343		key = "key for "
344	}
345
346	return fmt.Sprintf(
347		"invalid %sMetadataMatcher_PathSegment.%s: %s%s",
348		key,
349		e.field,
350		e.reason,
351		cause)
352}
353
354var _ error = MetadataMatcher_PathSegmentValidationError{}
355
356var _ interface {
357	Field() string
358	Reason() string
359	Key() bool
360	Cause() error
361	ErrorName() string
362} = MetadataMatcher_PathSegmentValidationError{}
363