github.com/digitalocean/go-netbox@v0.0.2/netbox/models/user.go (about)

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