1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package models
20
21
22
23
24 import (
25 "context"
26 "encoding/json"
27
28 "github.com/go-openapi/errors"
29 "github.com/go-openapi/strfmt"
30 "github.com/go-openapi/swag"
31 "github.com/go-openapi/validate"
32 )
33
34
35
36
37 type SearchIndex struct {
38
39
40
41 Email strfmt.Email `json:"email,omitempty"`
42
43
44
45 Hash string `json:"hash,omitempty"`
46
47
48
49 Operator string `json:"operator,omitempty"`
50
51
52 PublicKey *SearchIndexPublicKey `json:"publicKey,omitempty"`
53 }
54
55
56 func (m *SearchIndex) Validate(formats strfmt.Registry) error {
57 var res []error
58
59 if err := m.validateEmail(formats); err != nil {
60 res = append(res, err)
61 }
62
63 if err := m.validateHash(formats); err != nil {
64 res = append(res, err)
65 }
66
67 if err := m.validateOperator(formats); err != nil {
68 res = append(res, err)
69 }
70
71 if err := m.validatePublicKey(formats); err != nil {
72 res = append(res, err)
73 }
74
75 if len(res) > 0 {
76 return errors.CompositeValidationError(res...)
77 }
78 return nil
79 }
80
81 func (m *SearchIndex) validateEmail(formats strfmt.Registry) error {
82 if swag.IsZero(m.Email) {
83 return nil
84 }
85
86 if err := validate.FormatOf("email", "body", "email", m.Email.String(), formats); err != nil {
87 return err
88 }
89
90 return nil
91 }
92
93 func (m *SearchIndex) validateHash(formats strfmt.Registry) error {
94 if swag.IsZero(m.Hash) {
95 return nil
96 }
97
98 if err := validate.Pattern("hash", "body", m.Hash, `^(sha512:)?[0-9a-fA-F]{128}$|^(sha256:)?[0-9a-fA-F]{64}$|^(sha1:)?[0-9a-fA-F]{40}$`); err != nil {
99 return err
100 }
101
102 return nil
103 }
104
105 var searchIndexTypeOperatorPropEnum []interface{}
106
107 func init() {
108 var res []string
109 if err := json.Unmarshal([]byte(`["and","or"]`), &res); err != nil {
110 panic(err)
111 }
112 for _, v := range res {
113 searchIndexTypeOperatorPropEnum = append(searchIndexTypeOperatorPropEnum, v)
114 }
115 }
116
117 const (
118
119
120 SearchIndexOperatorAnd string = "and"
121
122
123 SearchIndexOperatorOr string = "or"
124 )
125
126
127 func (m *SearchIndex) validateOperatorEnum(path, location string, value string) error {
128 if err := validate.EnumCase(path, location, value, searchIndexTypeOperatorPropEnum, true); err != nil {
129 return err
130 }
131 return nil
132 }
133
134 func (m *SearchIndex) validateOperator(formats strfmt.Registry) error {
135 if swag.IsZero(m.Operator) {
136 return nil
137 }
138
139
140 if err := m.validateOperatorEnum("operator", "body", m.Operator); err != nil {
141 return err
142 }
143
144 return nil
145 }
146
147 func (m *SearchIndex) validatePublicKey(formats strfmt.Registry) error {
148 if swag.IsZero(m.PublicKey) {
149 return nil
150 }
151
152 if m.PublicKey != nil {
153 if err := m.PublicKey.Validate(formats); err != nil {
154 if ve, ok := err.(*errors.Validation); ok {
155 return ve.ValidateName("publicKey")
156 } else if ce, ok := err.(*errors.CompositeError); ok {
157 return ce.ValidateName("publicKey")
158 }
159 return err
160 }
161 }
162
163 return nil
164 }
165
166
167 func (m *SearchIndex) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
168 var res []error
169
170 if err := m.contextValidatePublicKey(ctx, formats); err != nil {
171 res = append(res, err)
172 }
173
174 if len(res) > 0 {
175 return errors.CompositeValidationError(res...)
176 }
177 return nil
178 }
179
180 func (m *SearchIndex) contextValidatePublicKey(ctx context.Context, formats strfmt.Registry) error {
181
182 if m.PublicKey != nil {
183
184 if swag.IsZero(m.PublicKey) {
185 return nil
186 }
187
188 if err := m.PublicKey.ContextValidate(ctx, formats); err != nil {
189 if ve, ok := err.(*errors.Validation); ok {
190 return ve.ValidateName("publicKey")
191 } else if ce, ok := err.(*errors.CompositeError); ok {
192 return ce.ValidateName("publicKey")
193 }
194 return err
195 }
196 }
197
198 return nil
199 }
200
201
202 func (m *SearchIndex) MarshalBinary() ([]byte, error) {
203 if m == nil {
204 return nil, nil
205 }
206 return swag.WriteJSON(m)
207 }
208
209
210 func (m *SearchIndex) UnmarshalBinary(b []byte) error {
211 var res SearchIndex
212 if err := swag.ReadJSON(b, &res); err != nil {
213 return err
214 }
215 *m = res
216 return nil
217 }
218
219
220
221
222 type SearchIndexPublicKey struct {
223
224
225
226 Content strfmt.Base64 `json:"content,omitempty"`
227
228
229
230
231 Format *string `json:"format"`
232
233
234
235 URL strfmt.URI `json:"url,omitempty"`
236 }
237
238
239 func (m *SearchIndexPublicKey) Validate(formats strfmt.Registry) error {
240 var res []error
241
242 if err := m.validateFormat(formats); err != nil {
243 res = append(res, err)
244 }
245
246 if err := m.validateURL(formats); err != nil {
247 res = append(res, err)
248 }
249
250 if len(res) > 0 {
251 return errors.CompositeValidationError(res...)
252 }
253 return nil
254 }
255
256 var searchIndexPublicKeyTypeFormatPropEnum []interface{}
257
258 func init() {
259 var res []string
260 if err := json.Unmarshal([]byte(`["pgp","x509","minisign","ssh","tuf"]`), &res); err != nil {
261 panic(err)
262 }
263 for _, v := range res {
264 searchIndexPublicKeyTypeFormatPropEnum = append(searchIndexPublicKeyTypeFormatPropEnum, v)
265 }
266 }
267
268 const (
269
270
271 SearchIndexPublicKeyFormatPgp string = "pgp"
272
273
274 SearchIndexPublicKeyFormatX509 string = "x509"
275
276
277 SearchIndexPublicKeyFormatMinisign string = "minisign"
278
279
280 SearchIndexPublicKeyFormatSSH string = "ssh"
281
282
283 SearchIndexPublicKeyFormatTUF string = "tuf"
284 )
285
286
287 func (m *SearchIndexPublicKey) validateFormatEnum(path, location string, value string) error {
288 if err := validate.EnumCase(path, location, value, searchIndexPublicKeyTypeFormatPropEnum, true); err != nil {
289 return err
290 }
291 return nil
292 }
293
294 func (m *SearchIndexPublicKey) validateFormat(formats strfmt.Registry) error {
295
296 if err := validate.Required("publicKey"+"."+"format", "body", m.Format); err != nil {
297 return err
298 }
299
300
301 if err := m.validateFormatEnum("publicKey"+"."+"format", "body", *m.Format); err != nil {
302 return err
303 }
304
305 return nil
306 }
307
308 func (m *SearchIndexPublicKey) validateURL(formats strfmt.Registry) error {
309 if swag.IsZero(m.URL) {
310 return nil
311 }
312
313 if err := validate.FormatOf("publicKey"+"."+"url", "body", "uri", m.URL.String(), formats); err != nil {
314 return err
315 }
316
317 return nil
318 }
319
320
321 func (m *SearchIndexPublicKey) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
322 return nil
323 }
324
325
326 func (m *SearchIndexPublicKey) MarshalBinary() ([]byte, error) {
327 if m == nil {
328 return nil, nil
329 }
330 return swag.WriteJSON(m)
331 }
332
333
334 func (m *SearchIndexPublicKey) UnmarshalBinary(b []byte) error {
335 var res SearchIndexPublicKey
336 if err := swag.ReadJSON(b, &res); err != nil {
337 return err
338 }
339 *m = res
340 return nil
341 }
342
View as plain text