github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_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  // WritableObjectPermission writable object permission
    34  //
    35  // swagger:model WritableObjectPermission
    36  type WritableObjectPermission 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 []int64 `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 []int64 `json:"users"`
    85  }
    86  
    87  // Validate validates this writable object permission
    88  func (m *WritableObjectPermission) 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 *WritableObjectPermission) 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 *WritableObjectPermission) 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 *WritableObjectPermission) 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  	return nil
   168  }
   169  
   170  func (m *WritableObjectPermission) validateName(formats strfmt.Registry) error {
   171  
   172  	if err := validate.Required("name", "body", m.Name); err != nil {
   173  		return err
   174  	}
   175  
   176  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   177  		return err
   178  	}
   179  
   180  	if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil {
   181  		return err
   182  	}
   183  
   184  	return nil
   185  }
   186  
   187  func (m *WritableObjectPermission) validateObjectTypes(formats strfmt.Registry) error {
   188  
   189  	if err := validate.Required("object_types", "body", m.ObjectTypes); err != nil {
   190  		return err
   191  	}
   192  
   193  	if err := validate.UniqueItems("object_types", "body", m.ObjectTypes); err != nil {
   194  		return err
   195  	}
   196  
   197  	return nil
   198  }
   199  
   200  func (m *WritableObjectPermission) validateURL(formats strfmt.Registry) error {
   201  	if swag.IsZero(m.URL) { // not required
   202  		return nil
   203  	}
   204  
   205  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   206  		return err
   207  	}
   208  
   209  	return nil
   210  }
   211  
   212  func (m *WritableObjectPermission) validateUsers(formats strfmt.Registry) error {
   213  	if swag.IsZero(m.Users) { // not required
   214  		return nil
   215  	}
   216  
   217  	if err := validate.UniqueItems("users", "body", m.Users); err != nil {
   218  		return err
   219  	}
   220  
   221  	return nil
   222  }
   223  
   224  // ContextValidate validate this writable object permission based on the context it is used
   225  func (m *WritableObjectPermission) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   226  	var res []error
   227  
   228  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   229  		res = append(res, err)
   230  	}
   231  
   232  	if err := m.contextValidateID(ctx, formats); err != nil {
   233  		res = append(res, err)
   234  	}
   235  
   236  	if err := m.contextValidateURL(ctx, formats); err != nil {
   237  		res = append(res, err)
   238  	}
   239  
   240  	if len(res) > 0 {
   241  		return errors.CompositeValidationError(res...)
   242  	}
   243  	return nil
   244  }
   245  
   246  func (m *WritableObjectPermission) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   247  
   248  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   249  		return err
   250  	}
   251  
   252  	return nil
   253  }
   254  
   255  func (m *WritableObjectPermission) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   256  
   257  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   258  		return err
   259  	}
   260  
   261  	return nil
   262  }
   263  
   264  func (m *WritableObjectPermission) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   265  
   266  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   267  		return err
   268  	}
   269  
   270  	return nil
   271  }
   272  
   273  // MarshalBinary interface implementation
   274  func (m *WritableObjectPermission) MarshalBinary() ([]byte, error) {
   275  	if m == nil {
   276  		return nil, nil
   277  	}
   278  	return swag.WriteJSON(m)
   279  }
   280  
   281  // UnmarshalBinary interface implementation
   282  func (m *WritableObjectPermission) UnmarshalBinary(b []byte) error {
   283  	var res WritableObjectPermission
   284  	if err := swag.ReadJSON(b, &res); err != nil {
   285  		return err
   286  	}
   287  	*m = res
   288  	return nil
   289  }