/envoy/type/matcher/string.pb.validate.go

https://github.com/envoyproxy/go-control-plane · Go · 252 lines · 175 code · 49 blank · 28 comment · 24 complexity · 7c34def21d0933b384b95e134fc383dc MD5 · raw file

  1. // Code generated by protoc-gen-validate. DO NOT EDIT.
  2. // source: envoy/type/matcher/string.proto
  3. package envoy_type_matcher
  4. import (
  5. "bytes"
  6. "errors"
  7. "fmt"
  8. "net"
  9. "net/mail"
  10. "net/url"
  11. "regexp"
  12. "strings"
  13. "time"
  14. "unicode/utf8"
  15. "github.com/golang/protobuf/ptypes"
  16. )
  17. // ensure the imports are used
  18. var (
  19. _ = bytes.MinRead
  20. _ = errors.New("")
  21. _ = fmt.Print
  22. _ = utf8.UTFMax
  23. _ = (*regexp.Regexp)(nil)
  24. _ = (*strings.Reader)(nil)
  25. _ = net.IPv4len
  26. _ = time.Duration(0)
  27. _ = (*url.URL)(nil)
  28. _ = (*mail.Address)(nil)
  29. _ = ptypes.DynamicAny{}
  30. )
  31. // define the regex for a UUID once up-front
  32. var _string_uuidPattern = regexp.MustCompile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
  33. // Validate checks the field values on StringMatcher with the rules defined in
  34. // the proto definition for this message. If any rules are violated, an error
  35. // is returned.
  36. func (m *StringMatcher) Validate() error {
  37. if m == nil {
  38. return nil
  39. }
  40. // no validation rules for IgnoreCase
  41. switch m.MatchPattern.(type) {
  42. case *StringMatcher_Exact:
  43. // no validation rules for Exact
  44. case *StringMatcher_Prefix:
  45. if utf8.RuneCountInString(m.GetPrefix()) < 1 {
  46. return StringMatcherValidationError{
  47. field: "Prefix",
  48. reason: "value length must be at least 1 runes",
  49. }
  50. }
  51. case *StringMatcher_Suffix:
  52. if utf8.RuneCountInString(m.GetSuffix()) < 1 {
  53. return StringMatcherValidationError{
  54. field: "Suffix",
  55. reason: "value length must be at least 1 runes",
  56. }
  57. }
  58. case *StringMatcher_Regex:
  59. if len(m.GetRegex()) > 1024 {
  60. return StringMatcherValidationError{
  61. field: "Regex",
  62. reason: "value length must be at most 1024 bytes",
  63. }
  64. }
  65. case *StringMatcher_SafeRegex:
  66. if m.GetSafeRegex() == nil {
  67. return StringMatcherValidationError{
  68. field: "SafeRegex",
  69. reason: "value is required",
  70. }
  71. }
  72. if v, ok := interface{}(m.GetSafeRegex()).(interface{ Validate() error }); ok {
  73. if err := v.Validate(); err != nil {
  74. return StringMatcherValidationError{
  75. field: "SafeRegex",
  76. reason: "embedded message failed validation",
  77. cause: err,
  78. }
  79. }
  80. }
  81. default:
  82. return StringMatcherValidationError{
  83. field: "MatchPattern",
  84. reason: "value is required",
  85. }
  86. }
  87. return nil
  88. }
  89. // StringMatcherValidationError is the validation error returned by
  90. // StringMatcher.Validate if the designated constraints aren't met.
  91. type StringMatcherValidationError struct {
  92. field string
  93. reason string
  94. cause error
  95. key bool
  96. }
  97. // Field function returns field value.
  98. func (e StringMatcherValidationError) Field() string { return e.field }
  99. // Reason function returns reason value.
  100. func (e StringMatcherValidationError) Reason() string { return e.reason }
  101. // Cause function returns cause value.
  102. func (e StringMatcherValidationError) Cause() error { return e.cause }
  103. // Key function returns key value.
  104. func (e StringMatcherValidationError) Key() bool { return e.key }
  105. // ErrorName returns error name.
  106. func (e StringMatcherValidationError) ErrorName() string { return "StringMatcherValidationError" }
  107. // Error satisfies the builtin error interface
  108. func (e StringMatcherValidationError) Error() string {
  109. cause := ""
  110. if e.cause != nil {
  111. cause = fmt.Sprintf(" | caused by: %v", e.cause)
  112. }
  113. key := ""
  114. if e.key {
  115. key = "key for "
  116. }
  117. return fmt.Sprintf(
  118. "invalid %sStringMatcher.%s: %s%s",
  119. key,
  120. e.field,
  121. e.reason,
  122. cause)
  123. }
  124. var _ error = StringMatcherValidationError{}
  125. var _ interface {
  126. Field() string
  127. Reason() string
  128. Key() bool
  129. Cause() error
  130. ErrorName() string
  131. } = StringMatcherValidationError{}
  132. // Validate checks the field values on ListStringMatcher with the rules defined
  133. // in the proto definition for this message. If any rules are violated, an
  134. // error is returned.
  135. func (m *ListStringMatcher) Validate() error {
  136. if m == nil {
  137. return nil
  138. }
  139. if len(m.GetPatterns()) < 1 {
  140. return ListStringMatcherValidationError{
  141. field: "Patterns",
  142. reason: "value must contain at least 1 item(s)",
  143. }
  144. }
  145. for idx, item := range m.GetPatterns() {
  146. _, _ = idx, item
  147. if v, ok := interface{}(item).(interface{ Validate() error }); ok {
  148. if err := v.Validate(); err != nil {
  149. return ListStringMatcherValidationError{
  150. field: fmt.Sprintf("Patterns[%v]", idx),
  151. reason: "embedded message failed validation",
  152. cause: err,
  153. }
  154. }
  155. }
  156. }
  157. return nil
  158. }
  159. // ListStringMatcherValidationError is the validation error returned by
  160. // ListStringMatcher.Validate if the designated constraints aren't met.
  161. type ListStringMatcherValidationError struct {
  162. field string
  163. reason string
  164. cause error
  165. key bool
  166. }
  167. // Field function returns field value.
  168. func (e ListStringMatcherValidationError) Field() string { return e.field }
  169. // Reason function returns reason value.
  170. func (e ListStringMatcherValidationError) Reason() string { return e.reason }
  171. // Cause function returns cause value.
  172. func (e ListStringMatcherValidationError) Cause() error { return e.cause }
  173. // Key function returns key value.
  174. func (e ListStringMatcherValidationError) Key() bool { return e.key }
  175. // ErrorName returns error name.
  176. func (e ListStringMatcherValidationError) ErrorName() string {
  177. return "ListStringMatcherValidationError"
  178. }
  179. // Error satisfies the builtin error interface
  180. func (e ListStringMatcherValidationError) Error() string {
  181. cause := ""
  182. if e.cause != nil {
  183. cause = fmt.Sprintf(" | caused by: %v", e.cause)
  184. }
  185. key := ""
  186. if e.key {
  187. key = "key for "
  188. }
  189. return fmt.Sprintf(
  190. "invalid %sListStringMatcher.%s: %s%s",
  191. key,
  192. e.field,
  193. e.reason,
  194. cause)
  195. }
  196. var _ error = ListStringMatcherValidationError{}
  197. var _ interface {
  198. Field() string
  199. Reason() string
  200. Key() bool
  201. Cause() error
  202. ErrorName() string
  203. } = ListStringMatcherValidationError{}