github.com/digitalocean/go-netbox@v0.0.2/netbox/models/object_permission.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  // ObjectPermission object permission
    34  //
    35  // swagger:model ObjectPermission
    36  type ObjectPermission struct {
    37  
    38  	// The list of actions granted by this permission
    39  	// Required: true
    40  	Actions []string `json:"actions"`
    41  
    42  	// Constraints
    43  	//
    44  	// Queryset filter matching the applicable objects of the selected type(s)
    45  	Constraints *string `json:"constraints,omitempty"`
    46  
    47  	// Description
    48  	// Max Length: 200
    49  	Description string `json:"description,omitempty"`
    50  
    51  	// Display
    52  	// Read Only: true
    53  	Display string `json:"display,omitempty"`
    54  
    55  	// Enabled
    56  	Enabled bool `json:"enabled,omitempty"`
    57  
    58  	// groups
    59  	// Unique: true
    60  	Groups []*NestedGroup `json:"groups"`
    61  
    62  	// Id
    63  	// Read Only: true
    64  	ID int64 `json:"id,omitempty"`
    65  
    66  	// Name
    67  	// Required: true
    68  	// Max Length: 100
    69  	// Min Length: 1
    70  	Name *string `json:"name"`
    71  
    72  	// object types
    73  	// Required: true
    74  	// Unique: true
    75  	ObjectTypes []string `json:"object_types"`
    76  
    77  	// Url
    78  	// Read Only: true
    79  	// Format: uri
    80  	URL strfmt.URI `json:"url,omitempty"`
    81  
    82  	// users
    83  	// Unique: true
    84  	Users []*NestedUser `json:"users"`
    85  }
    86  
    87  // Validate validates this object permission
    88  func (m *ObjectPermission) Validate(formats strfmt.Registry) error {
    89  	var res []error
    90  
    91  	if err := m.validateActions(formats); err != nil {
    92  		res = append(res, err)
    93  	}
    94  
    95  	if err := m.validateDescription(formats); err != nil {
    96  		res = append(res, err)
    97  	}
    98  
    99  	if err := m.validateGroups(formats); err != nil {
   100  		res = append(res, err)
   101  	}
   102  
   103  	if err := m.validateName(formats); err != nil {
   104  		res = append(res, err)
   105  	}
   106  
   107  	if err := m.validateObjectTypes(formats); err != nil {
   108  		res = append(res, err)
   109  	}
   110  
   111  	if err := m.validateURL(formats); err != nil {
   112  		res = append(res, err)
   113  	}
   114  
   115  	if err := m.validateUsers(formats); err != nil {
   116  		res = append(res, err)
   117  	}
   118  
   119  	if len(res) > 0 {
   120  		return errors.CompositeValidationError(res...)
   121  	}
   122  	return nil
   123  }
   124  
   125  func (m *ObjectPermission) validateActions(formats strfmt.Registry) error {
   126  
   127  	if err := validate.Required("actions", "body", m.Actions); err != nil {
   128  		return err
   129  	}
   130  
   131  	for i := 0; i < len(m.Actions); i++ {
   132  
   133  		if err := validate.MinLength("actions"+"."+strconv.Itoa(i), "body", m.Actions[i], 1); err != nil {
   134  			return err
   135  		}
   136  
   137  		if err := validate.MaxLength("actions"+"."+strconv.Itoa(i), "body", m.Actions[i], 30); err != nil {
   138  			return err
   139  		}
   140  
   141  	}
   142  
   143  	return nil
   144  }
   145  
   146  func (m *ObjectPermission) validateDescription(formats strfmt.Registry) error {
   147  	if swag.IsZero(m.Description) { // not required
   148  		return nil
   149  	}
   150  
   151  	if err := validate.MaxLength("description", "body", m.Description, 200); err != nil {
   152  		return err
   153  	}
   154  
   155  	return nil
   156  }
   157  
   158  func (m *ObjectPermission) validateGroups(formats strfmt.Registry) error {
   159  	if swag.IsZero(m.Groups) { // not required
   160  		return nil
   161  	}
   162  
   163  	if err := validate.UniqueItems("groups", "body", m.Groups); err != nil {
   164  		return err
   165  	}
   166  
   167  	for i := 0; i < len(m.Groups); i++ {
   168  		if swag.IsZero(m.Groups[i]) { // not required
   169  			continue
   170  		}
   171  
   172  		if m.Groups[i] != nil {
   173  			if err := m.Groups[i].Validate(formats); err != nil {
   174  				if ve, ok := err.(*errors.Validation); ok {
   175  					return ve.ValidateName("groups" + "." + strconv.Itoa(i))
   176  				} else if ce, ok := err.(*errors.CompositeError); ok {
   177  					return ce.ValidateName("groups" + "." + strconv.Itoa(i))
   178  				}
   179  				return err
   180  			}
   181  		}
   182  
   183  	}
   184  
   185  	return nil
   186  }
   187  
   188  func (m *ObjectPermission) validateName(formats strfmt.Registry) error {
   189  
   190  	if err := validate.Required("name", "body", m.Name); err != nil {
   191  		return err
   192  	}
   193  
   194  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   195  		return err
   196  	}
   197  
   198  	if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil {
   199  		return err
   200  	}
   201  
   202  	return nil
   203  }
   204  
   205  func (m *ObjectPermission) validateObjectTypes(formats strfmt.Registry) error {
   206  
   207  	if err := validate.Required("object_types", "body", m.ObjectTypes); err != nil {
   208  		return err
   209  	}
   210  
   211  	if err := validate.UniqueItems("object_types", "body", m.ObjectTypes); err != nil {
   212  		return err
   213  	}
   214  
   215  	return nil
   216  }
   217  
   218  func (m *ObjectPermission) validateURL(formats strfmt.Registry) error {
   219  	if swag.IsZero(m.URL) { // not required
   220  		return nil
   221  	}
   222  
   223  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   224  		return err
   225  	}
   226  
   227  	return nil
   228  }
   229  
   230  func (m *ObjectPermission) validateUsers(formats strfmt.Registry) error {
   231  	if swag.IsZero(m.Users) { // not required
   232  		return nil
   233  	}
   234  
   235  	if err := validate.UniqueItems("users", "body", m.Users); err != nil {
   236  		return err
   237  	}
   238  
   239  	for i := 0; i < len(m.Users); i++ {
   240  		if swag.IsZero(m.Users[i]) { // not required
   241  			continue
   242  		}
   243  
   244  		if m.Users[i] != nil {
   245  			if err := m.Users[i].Validate(formats); err != nil {
   246  				if ve, ok := err.(*errors.Validation); ok {
   247  					return ve.ValidateName("users" + "." + strconv.Itoa(i))
   248  				} else if ce, ok := err.(*errors.CompositeError); ok {
   249  					return ce.ValidateName("users" + "." + strconv.Itoa(i))
   250  				}
   251  				return err
   252  			}
   253  		}
   254  
   255  	}
   256  
   257  	return nil
   258  }
   259  
   260  // ContextValidate validate this object permission based on the context it is used
   261  func (m *ObjectPermission) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   262  	var res []error
   263  
   264  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   265  		res = append(res, err)
   266  	}
   267  
   268  	if err := m.contextValidateGroups(ctx, formats); err != nil {
   269  		res = append(res, err)
   270  	}
   271  
   272  	if err := m.contextValidateID(ctx, formats); err != nil {
   273  		res = append(res, err)
   274  	}
   275  
   276  	if err := m.contextValidateURL(ctx, formats); err != nil {
   277  		res = append(res, err)
   278  	}
   279  
   280  	if err := m.contextValidateUsers(ctx, formats); err != nil {
   281  		res = append(res, err)
   282  	}
   283  
   284  	if len(res) > 0 {
   285  		return errors.CompositeValidationError(res...)
   286  	}
   287  	return nil
   288  }
   289  
   290  func (m *ObjectPermission) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   291  
   292  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   293  		return err
   294  	}
   295  
   296  	return nil
   297  }
   298  
   299  func (m *ObjectPermission) contextValidateGroups(ctx context.Context, formats strfmt.Registry) error {
   300  
   301  	for i := 0; i < len(m.Groups); i++ {
   302  
   303  		if m.Groups[i] != nil {
   304  			if err := m.Groups[i].ContextValidate(ctx, formats); err != nil {
   305  				if ve, ok := err.(*errors.Validation); ok {
   306  					return ve.ValidateName("groups" + "." + strconv.Itoa(i))
   307  				} else if ce, ok := err.(*errors.CompositeError); ok {
   308  					return ce.ValidateName("groups" + "." + strconv.Itoa(i))
   309  				}
   310  				return err
   311  			}
   312  		}
   313  
   314  	}
   315  
   316  	return nil
   317  }
   318  
   319  func (m *ObjectPermission) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   320  
   321  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   322  		return err
   323  	}
   324  
   325  	return nil
   326  }
   327  
   328  func (m *ObjectPermission) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   329  
   330  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   331  		return err
   332  	}
   333  
   334  	return nil
   335  }
   336  
   337  func (m *ObjectPermission) contextValidateUsers(ctx context.Context, formats strfmt.Registry) error {
   338  
   339  	for i := 0; i < len(m.Users); i++ {
   340  
   341  		if m.Users[i] != nil {
   342  			if err := m.Users[i].ContextValidate(ctx, formats); err != nil {
   343  				if ve, ok := err.(*errors.Validation); ok {
   344  					return ve.ValidateName("users" + "." + strconv.Itoa(i))
   345  				} else if ce, ok := err.(*errors.CompositeError); ok {
   346  					return ce.ValidateName("users" + "." + strconv.Itoa(i))
   347  				}
   348  				return err
   349  			}
   350  		}
   351  
   352  	}
   353  
   354  	return nil
   355  }
   356  
   357  // MarshalBinary interface implementation
   358  func (m *ObjectPermission) MarshalBinary() ([]byte, error) {
   359  	if m == nil {
   360  		return nil, nil
   361  	}
   362  	return swag.WriteJSON(m)
   363  }
   364  
   365  // UnmarshalBinary interface implementation
   366  func (m *ObjectPermission) UnmarshalBinary(b []byte) error {
   367  	var res ObjectPermission
   368  	if err := swag.ReadJSON(b, &res); err != nil {
   369  		return err
   370  	}
   371  	*m = res
   372  	return nil
   373  }