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