forked from netbox-community/go-netbox
/
writable_user.go
318 lines (244 loc) · 7.13 KB
/
writable_user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
// Code generated by go-swagger; DO NOT EDIT.
// Copyright 2020 The go-netbox Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// WritableUser writable user
//
// swagger:model WritableUser
type WritableUser struct {
// Date joined
// Format: date-time
DateJoined strfmt.DateTime `json:"date_joined,omitempty"`
// Display
// Read Only: true
Display string `json:"display,omitempty"`
// Email address
// Max Length: 254
// Format: email
Email strfmt.Email `json:"email,omitempty"`
// First name
// Max Length: 150
FirstName string `json:"first_name,omitempty"`
// The groups this user belongs to. A user will get all permissions granted to each of their groups.
// Unique: true
Groups []int64 `json:"groups"`
// ID
// Read Only: true
ID int64 `json:"id,omitempty"`
// Active
//
// Designates whether this user should be treated as active. Unselect this instead of deleting accounts.
IsActive bool `json:"is_active,omitempty"`
// Staff status
//
// Designates whether the user can log into this admin site.
IsStaff bool `json:"is_staff,omitempty"`
// Last name
// Max Length: 150
LastName string `json:"last_name,omitempty"`
// Password
// Required: true
// Max Length: 128
// Min Length: 1
Password *string `json:"password"`
// Url
// Read Only: true
// Format: uri
URL strfmt.URI `json:"url,omitempty"`
// Username
//
// Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.
// Required: true
// Max Length: 150
// Min Length: 1
// Pattern: ^[\w.@+-]+$
Username *string `json:"username"`
}
// Validate validates this writable user
func (m *WritableUser) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateDateJoined(formats); err != nil {
res = append(res, err)
}
if err := m.validateEmail(formats); err != nil {
res = append(res, err)
}
if err := m.validateFirstName(formats); err != nil {
res = append(res, err)
}
if err := m.validateGroups(formats); err != nil {
res = append(res, err)
}
if err := m.validateLastName(formats); err != nil {
res = append(res, err)
}
if err := m.validatePassword(formats); err != nil {
res = append(res, err)
}
if err := m.validateURL(formats); err != nil {
res = append(res, err)
}
if err := m.validateUsername(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *WritableUser) validateDateJoined(formats strfmt.Registry) error {
if swag.IsZero(m.DateJoined) { // not required
return nil
}
if err := validate.FormatOf("date_joined", "body", "date-time", m.DateJoined.String(), formats); err != nil {
return err
}
return nil
}
func (m *WritableUser) validateEmail(formats strfmt.Registry) error {
if swag.IsZero(m.Email) { // not required
return nil
}
if err := validate.MaxLength("email", "body", m.Email.String(), 254); err != nil {
return err
}
if err := validate.FormatOf("email", "body", "email", m.Email.String(), formats); err != nil {
return err
}
return nil
}
func (m *WritableUser) validateFirstName(formats strfmt.Registry) error {
if swag.IsZero(m.FirstName) { // not required
return nil
}
if err := validate.MaxLength("first_name", "body", m.FirstName, 150); err != nil {
return err
}
return nil
}
func (m *WritableUser) validateGroups(formats strfmt.Registry) error {
if swag.IsZero(m.Groups) { // not required
return nil
}
if err := validate.UniqueItems("groups", "body", m.Groups); err != nil {
return err
}
return nil
}
func (m *WritableUser) validateLastName(formats strfmt.Registry) error {
if swag.IsZero(m.LastName) { // not required
return nil
}
if err := validate.MaxLength("last_name", "body", m.LastName, 150); err != nil {
return err
}
return nil
}
func (m *WritableUser) validatePassword(formats strfmt.Registry) error {
if err := validate.Required("password", "body", m.Password); err != nil {
return err
}
if err := validate.MinLength("password", "body", *m.Password, 1); err != nil {
return err
}
if err := validate.MaxLength("password", "body", *m.Password, 128); err != nil {
return err
}
return nil
}
func (m *WritableUser) validateURL(formats strfmt.Registry) error {
if swag.IsZero(m.URL) { // not required
return nil
}
if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
return err
}
return nil
}
func (m *WritableUser) validateUsername(formats strfmt.Registry) error {
if err := validate.Required("username", "body", m.Username); err != nil {
return err
}
if err := validate.MinLength("username", "body", *m.Username, 1); err != nil {
return err
}
if err := validate.MaxLength("username", "body", *m.Username, 150); err != nil {
return err
}
if err := validate.Pattern("username", "body", *m.Username, `^[\w.@+-]+$`); err != nil {
return err
}
return nil
}
// ContextValidate validate this writable user based on the context it is used
func (m *WritableUser) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
if err := m.contextValidateDisplay(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateID(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateURL(ctx, formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *WritableUser) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
return err
}
return nil
}
func (m *WritableUser) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
return err
}
return nil
}
func (m *WritableUser) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *WritableUser) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *WritableUser) UnmarshalBinary(b []byte) error {
var res WritableUser
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}