github.com/digitalocean/go-netbox@v0.0.2/netbox/models/service.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  	"encoding/json"
    26  	"strconv"
    27  
    28  	"github.com/go-openapi/errors"
    29  	"github.com/go-openapi/strfmt"
    30  	"github.com/go-openapi/swag"
    31  	"github.com/go-openapi/validate"
    32  )
    33  
    34  // Service service
    35  //
    36  // swagger:model Service
    37  type Service struct {
    38  
    39  	// Created
    40  	// Read Only: true
    41  	// Format: date
    42  	Created strfmt.Date `json:"created,omitempty"`
    43  
    44  	// Custom fields
    45  	CustomFields interface{} `json:"custom_fields,omitempty"`
    46  
    47  	// Description
    48  	// Max Length: 200
    49  	Description string `json:"description,omitempty"`
    50  
    51  	// device
    52  	Device *NestedDevice `json:"device,omitempty"`
    53  
    54  	// Display
    55  	// Read Only: true
    56  	Display string `json:"display,omitempty"`
    57  
    58  	// Id
    59  	// Read Only: true
    60  	ID int64 `json:"id,omitempty"`
    61  
    62  	// ipaddresses
    63  	// Unique: true
    64  	Ipaddresses []*NestedIPAddress `json:"ipaddresses"`
    65  
    66  	// Last updated
    67  	// Read Only: true
    68  	// Format: date-time
    69  	LastUpdated strfmt.DateTime `json:"last_updated,omitempty"`
    70  
    71  	// Name
    72  	// Required: true
    73  	// Max Length: 100
    74  	// Min Length: 1
    75  	Name *string `json:"name"`
    76  
    77  	// ports
    78  	// Required: true
    79  	Ports []int64 `json:"ports"`
    80  
    81  	// protocol
    82  	Protocol *ServiceProtocol `json:"protocol,omitempty"`
    83  
    84  	// tags
    85  	Tags []*NestedTag `json:"tags"`
    86  
    87  	// Url
    88  	// Read Only: true
    89  	// Format: uri
    90  	URL strfmt.URI `json:"url,omitempty"`
    91  
    92  	// virtual machine
    93  	VirtualMachine *NestedVirtualMachine `json:"virtual_machine,omitempty"`
    94  }
    95  
    96  // Validate validates this service
    97  func (m *Service) Validate(formats strfmt.Registry) error {
    98  	var res []error
    99  
   100  	if err := m.validateCreated(formats); err != nil {
   101  		res = append(res, err)
   102  	}
   103  
   104  	if err := m.validateDescription(formats); err != nil {
   105  		res = append(res, err)
   106  	}
   107  
   108  	if err := m.validateDevice(formats); err != nil {
   109  		res = append(res, err)
   110  	}
   111  
   112  	if err := m.validateIpaddresses(formats); err != nil {
   113  		res = append(res, err)
   114  	}
   115  
   116  	if err := m.validateLastUpdated(formats); err != nil {
   117  		res = append(res, err)
   118  	}
   119  
   120  	if err := m.validateName(formats); err != nil {
   121  		res = append(res, err)
   122  	}
   123  
   124  	if err := m.validatePorts(formats); err != nil {
   125  		res = append(res, err)
   126  	}
   127  
   128  	if err := m.validateProtocol(formats); err != nil {
   129  		res = append(res, err)
   130  	}
   131  
   132  	if err := m.validateTags(formats); err != nil {
   133  		res = append(res, err)
   134  	}
   135  
   136  	if err := m.validateURL(formats); err != nil {
   137  		res = append(res, err)
   138  	}
   139  
   140  	if err := m.validateVirtualMachine(formats); err != nil {
   141  		res = append(res, err)
   142  	}
   143  
   144  	if len(res) > 0 {
   145  		return errors.CompositeValidationError(res...)
   146  	}
   147  	return nil
   148  }
   149  
   150  func (m *Service) validateCreated(formats strfmt.Registry) error {
   151  	if swag.IsZero(m.Created) { // not required
   152  		return nil
   153  	}
   154  
   155  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   156  		return err
   157  	}
   158  
   159  	return nil
   160  }
   161  
   162  func (m *Service) validateDescription(formats strfmt.Registry) error {
   163  	if swag.IsZero(m.Description) { // not required
   164  		return nil
   165  	}
   166  
   167  	if err := validate.MaxLength("description", "body", m.Description, 200); err != nil {
   168  		return err
   169  	}
   170  
   171  	return nil
   172  }
   173  
   174  func (m *Service) validateDevice(formats strfmt.Registry) error {
   175  	if swag.IsZero(m.Device) { // not required
   176  		return nil
   177  	}
   178  
   179  	if m.Device != nil {
   180  		if err := m.Device.Validate(formats); err != nil {
   181  			if ve, ok := err.(*errors.Validation); ok {
   182  				return ve.ValidateName("device")
   183  			} else if ce, ok := err.(*errors.CompositeError); ok {
   184  				return ce.ValidateName("device")
   185  			}
   186  			return err
   187  		}
   188  	}
   189  
   190  	return nil
   191  }
   192  
   193  func (m *Service) validateIpaddresses(formats strfmt.Registry) error {
   194  	if swag.IsZero(m.Ipaddresses) { // not required
   195  		return nil
   196  	}
   197  
   198  	if err := validate.UniqueItems("ipaddresses", "body", m.Ipaddresses); err != nil {
   199  		return err
   200  	}
   201  
   202  	for i := 0; i < len(m.Ipaddresses); i++ {
   203  		if swag.IsZero(m.Ipaddresses[i]) { // not required
   204  			continue
   205  		}
   206  
   207  		if m.Ipaddresses[i] != nil {
   208  			if err := m.Ipaddresses[i].Validate(formats); err != nil {
   209  				if ve, ok := err.(*errors.Validation); ok {
   210  					return ve.ValidateName("ipaddresses" + "." + strconv.Itoa(i))
   211  				} else if ce, ok := err.(*errors.CompositeError); ok {
   212  					return ce.ValidateName("ipaddresses" + "." + strconv.Itoa(i))
   213  				}
   214  				return err
   215  			}
   216  		}
   217  
   218  	}
   219  
   220  	return nil
   221  }
   222  
   223  func (m *Service) validateLastUpdated(formats strfmt.Registry) error {
   224  	if swag.IsZero(m.LastUpdated) { // not required
   225  		return nil
   226  	}
   227  
   228  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   229  		return err
   230  	}
   231  
   232  	return nil
   233  }
   234  
   235  func (m *Service) validateName(formats strfmt.Registry) error {
   236  
   237  	if err := validate.Required("name", "body", m.Name); err != nil {
   238  		return err
   239  	}
   240  
   241  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   242  		return err
   243  	}
   244  
   245  	if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil {
   246  		return err
   247  	}
   248  
   249  	return nil
   250  }
   251  
   252  func (m *Service) validatePorts(formats strfmt.Registry) error {
   253  
   254  	if err := validate.Required("ports", "body", m.Ports); err != nil {
   255  		return err
   256  	}
   257  
   258  	for i := 0; i < len(m.Ports); i++ {
   259  
   260  		if err := validate.MinimumInt("ports"+"."+strconv.Itoa(i), "body", m.Ports[i], 1, false); err != nil {
   261  			return err
   262  		}
   263  
   264  		if err := validate.MaximumInt("ports"+"."+strconv.Itoa(i), "body", m.Ports[i], 65535, false); err != nil {
   265  			return err
   266  		}
   267  
   268  	}
   269  
   270  	return nil
   271  }
   272  
   273  func (m *Service) validateProtocol(formats strfmt.Registry) error {
   274  	if swag.IsZero(m.Protocol) { // not required
   275  		return nil
   276  	}
   277  
   278  	if m.Protocol != nil {
   279  		if err := m.Protocol.Validate(formats); err != nil {
   280  			if ve, ok := err.(*errors.Validation); ok {
   281  				return ve.ValidateName("protocol")
   282  			} else if ce, ok := err.(*errors.CompositeError); ok {
   283  				return ce.ValidateName("protocol")
   284  			}
   285  			return err
   286  		}
   287  	}
   288  
   289  	return nil
   290  }
   291  
   292  func (m *Service) validateTags(formats strfmt.Registry) error {
   293  	if swag.IsZero(m.Tags) { // not required
   294  		return nil
   295  	}
   296  
   297  	for i := 0; i < len(m.Tags); i++ {
   298  		if swag.IsZero(m.Tags[i]) { // not required
   299  			continue
   300  		}
   301  
   302  		if m.Tags[i] != nil {
   303  			if err := m.Tags[i].Validate(formats); err != nil {
   304  				if ve, ok := err.(*errors.Validation); ok {
   305  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   306  				} else if ce, ok := err.(*errors.CompositeError); ok {
   307  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   308  				}
   309  				return err
   310  			}
   311  		}
   312  
   313  	}
   314  
   315  	return nil
   316  }
   317  
   318  func (m *Service) validateURL(formats strfmt.Registry) error {
   319  	if swag.IsZero(m.URL) { // not required
   320  		return nil
   321  	}
   322  
   323  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   324  		return err
   325  	}
   326  
   327  	return nil
   328  }
   329  
   330  func (m *Service) validateVirtualMachine(formats strfmt.Registry) error {
   331  	if swag.IsZero(m.VirtualMachine) { // not required
   332  		return nil
   333  	}
   334  
   335  	if m.VirtualMachine != nil {
   336  		if err := m.VirtualMachine.Validate(formats); err != nil {
   337  			if ve, ok := err.(*errors.Validation); ok {
   338  				return ve.ValidateName("virtual_machine")
   339  			} else if ce, ok := err.(*errors.CompositeError); ok {
   340  				return ce.ValidateName("virtual_machine")
   341  			}
   342  			return err
   343  		}
   344  	}
   345  
   346  	return nil
   347  }
   348  
   349  // ContextValidate validate this service based on the context it is used
   350  func (m *Service) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   351  	var res []error
   352  
   353  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   354  		res = append(res, err)
   355  	}
   356  
   357  	if err := m.contextValidateDevice(ctx, formats); err != nil {
   358  		res = append(res, err)
   359  	}
   360  
   361  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   362  		res = append(res, err)
   363  	}
   364  
   365  	if err := m.contextValidateID(ctx, formats); err != nil {
   366  		res = append(res, err)
   367  	}
   368  
   369  	if err := m.contextValidateIpaddresses(ctx, formats); err != nil {
   370  		res = append(res, err)
   371  	}
   372  
   373  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   374  		res = append(res, err)
   375  	}
   376  
   377  	if err := m.contextValidateProtocol(ctx, formats); err != nil {
   378  		res = append(res, err)
   379  	}
   380  
   381  	if err := m.contextValidateTags(ctx, formats); err != nil {
   382  		res = append(res, err)
   383  	}
   384  
   385  	if err := m.contextValidateURL(ctx, formats); err != nil {
   386  		res = append(res, err)
   387  	}
   388  
   389  	if err := m.contextValidateVirtualMachine(ctx, formats); err != nil {
   390  		res = append(res, err)
   391  	}
   392  
   393  	if len(res) > 0 {
   394  		return errors.CompositeValidationError(res...)
   395  	}
   396  	return nil
   397  }
   398  
   399  func (m *Service) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   400  
   401  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   402  		return err
   403  	}
   404  
   405  	return nil
   406  }
   407  
   408  func (m *Service) contextValidateDevice(ctx context.Context, formats strfmt.Registry) error {
   409  
   410  	if m.Device != nil {
   411  		if err := m.Device.ContextValidate(ctx, formats); err != nil {
   412  			if ve, ok := err.(*errors.Validation); ok {
   413  				return ve.ValidateName("device")
   414  			} else if ce, ok := err.(*errors.CompositeError); ok {
   415  				return ce.ValidateName("device")
   416  			}
   417  			return err
   418  		}
   419  	}
   420  
   421  	return nil
   422  }
   423  
   424  func (m *Service) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   425  
   426  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   427  		return err
   428  	}
   429  
   430  	return nil
   431  }
   432  
   433  func (m *Service) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   434  
   435  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   436  		return err
   437  	}
   438  
   439  	return nil
   440  }
   441  
   442  func (m *Service) contextValidateIpaddresses(ctx context.Context, formats strfmt.Registry) error {
   443  
   444  	for i := 0; i < len(m.Ipaddresses); i++ {
   445  
   446  		if m.Ipaddresses[i] != nil {
   447  			if err := m.Ipaddresses[i].ContextValidate(ctx, formats); err != nil {
   448  				if ve, ok := err.(*errors.Validation); ok {
   449  					return ve.ValidateName("ipaddresses" + "." + strconv.Itoa(i))
   450  				} else if ce, ok := err.(*errors.CompositeError); ok {
   451  					return ce.ValidateName("ipaddresses" + "." + strconv.Itoa(i))
   452  				}
   453  				return err
   454  			}
   455  		}
   456  
   457  	}
   458  
   459  	return nil
   460  }
   461  
   462  func (m *Service) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   463  
   464  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   465  		return err
   466  	}
   467  
   468  	return nil
   469  }
   470  
   471  func (m *Service) contextValidateProtocol(ctx context.Context, formats strfmt.Registry) error {
   472  
   473  	if m.Protocol != nil {
   474  		if err := m.Protocol.ContextValidate(ctx, formats); err != nil {
   475  			if ve, ok := err.(*errors.Validation); ok {
   476  				return ve.ValidateName("protocol")
   477  			} else if ce, ok := err.(*errors.CompositeError); ok {
   478  				return ce.ValidateName("protocol")
   479  			}
   480  			return err
   481  		}
   482  	}
   483  
   484  	return nil
   485  }
   486  
   487  func (m *Service) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   488  
   489  	for i := 0; i < len(m.Tags); i++ {
   490  
   491  		if m.Tags[i] != nil {
   492  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   493  				if ve, ok := err.(*errors.Validation); ok {
   494  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   495  				} else if ce, ok := err.(*errors.CompositeError); ok {
   496  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   497  				}
   498  				return err
   499  			}
   500  		}
   501  
   502  	}
   503  
   504  	return nil
   505  }
   506  
   507  func (m *Service) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   508  
   509  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   510  		return err
   511  	}
   512  
   513  	return nil
   514  }
   515  
   516  func (m *Service) contextValidateVirtualMachine(ctx context.Context, formats strfmt.Registry) error {
   517  
   518  	if m.VirtualMachine != nil {
   519  		if err := m.VirtualMachine.ContextValidate(ctx, formats); err != nil {
   520  			if ve, ok := err.(*errors.Validation); ok {
   521  				return ve.ValidateName("virtual_machine")
   522  			} else if ce, ok := err.(*errors.CompositeError); ok {
   523  				return ce.ValidateName("virtual_machine")
   524  			}
   525  			return err
   526  		}
   527  	}
   528  
   529  	return nil
   530  }
   531  
   532  // MarshalBinary interface implementation
   533  func (m *Service) MarshalBinary() ([]byte, error) {
   534  	if m == nil {
   535  		return nil, nil
   536  	}
   537  	return swag.WriteJSON(m)
   538  }
   539  
   540  // UnmarshalBinary interface implementation
   541  func (m *Service) UnmarshalBinary(b []byte) error {
   542  	var res Service
   543  	if err := swag.ReadJSON(b, &res); err != nil {
   544  		return err
   545  	}
   546  	*m = res
   547  	return nil
   548  }
   549  
   550  // ServiceProtocol Protocol
   551  //
   552  // swagger:model ServiceProtocol
   553  type ServiceProtocol struct {
   554  
   555  	// label
   556  	// Required: true
   557  	// Enum: [TCP UDP]
   558  	Label *string `json:"label"`
   559  
   560  	// value
   561  	// Required: true
   562  	// Enum: [tcp udp]
   563  	Value *string `json:"value"`
   564  }
   565  
   566  // Validate validates this service protocol
   567  func (m *ServiceProtocol) Validate(formats strfmt.Registry) error {
   568  	var res []error
   569  
   570  	if err := m.validateLabel(formats); err != nil {
   571  		res = append(res, err)
   572  	}
   573  
   574  	if err := m.validateValue(formats); err != nil {
   575  		res = append(res, err)
   576  	}
   577  
   578  	if len(res) > 0 {
   579  		return errors.CompositeValidationError(res...)
   580  	}
   581  	return nil
   582  }
   583  
   584  var serviceProtocolTypeLabelPropEnum []interface{}
   585  
   586  func init() {
   587  	var res []string
   588  	if err := json.Unmarshal([]byte(`["TCP","UDP"]`), &res); err != nil {
   589  		panic(err)
   590  	}
   591  	for _, v := range res {
   592  		serviceProtocolTypeLabelPropEnum = append(serviceProtocolTypeLabelPropEnum, v)
   593  	}
   594  }
   595  
   596  const (
   597  
   598  	// ServiceProtocolLabelTCP captures enum value "TCP"
   599  	ServiceProtocolLabelTCP string = "TCP"
   600  
   601  	// ServiceProtocolLabelUDP captures enum value "UDP"
   602  	ServiceProtocolLabelUDP string = "UDP"
   603  )
   604  
   605  // prop value enum
   606  func (m *ServiceProtocol) validateLabelEnum(path, location string, value string) error {
   607  	if err := validate.EnumCase(path, location, value, serviceProtocolTypeLabelPropEnum, true); err != nil {
   608  		return err
   609  	}
   610  	return nil
   611  }
   612  
   613  func (m *ServiceProtocol) validateLabel(formats strfmt.Registry) error {
   614  
   615  	if err := validate.Required("protocol"+"."+"label", "body", m.Label); err != nil {
   616  		return err
   617  	}
   618  
   619  	// value enum
   620  	if err := m.validateLabelEnum("protocol"+"."+"label", "body", *m.Label); err != nil {
   621  		return err
   622  	}
   623  
   624  	return nil
   625  }
   626  
   627  var serviceProtocolTypeValuePropEnum []interface{}
   628  
   629  func init() {
   630  	var res []string
   631  	if err := json.Unmarshal([]byte(`["tcp","udp"]`), &res); err != nil {
   632  		panic(err)
   633  	}
   634  	for _, v := range res {
   635  		serviceProtocolTypeValuePropEnum = append(serviceProtocolTypeValuePropEnum, v)
   636  	}
   637  }
   638  
   639  const (
   640  
   641  	// ServiceProtocolValueTCP captures enum value "tcp"
   642  	ServiceProtocolValueTCP string = "tcp"
   643  
   644  	// ServiceProtocolValueUDP captures enum value "udp"
   645  	ServiceProtocolValueUDP string = "udp"
   646  )
   647  
   648  // prop value enum
   649  func (m *ServiceProtocol) validateValueEnum(path, location string, value string) error {
   650  	if err := validate.EnumCase(path, location, value, serviceProtocolTypeValuePropEnum, true); err != nil {
   651  		return err
   652  	}
   653  	return nil
   654  }
   655  
   656  func (m *ServiceProtocol) validateValue(formats strfmt.Registry) error {
   657  
   658  	if err := validate.Required("protocol"+"."+"value", "body", m.Value); err != nil {
   659  		return err
   660  	}
   661  
   662  	// value enum
   663  	if err := m.validateValueEnum("protocol"+"."+"value", "body", *m.Value); err != nil {
   664  		return err
   665  	}
   666  
   667  	return nil
   668  }
   669  
   670  // ContextValidate validates this service protocol based on context it is used
   671  func (m *ServiceProtocol) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   672  	return nil
   673  }
   674  
   675  // MarshalBinary interface implementation
   676  func (m *ServiceProtocol) MarshalBinary() ([]byte, error) {
   677  	if m == nil {
   678  		return nil, nil
   679  	}
   680  	return swag.WriteJSON(m)
   681  }
   682  
   683  // UnmarshalBinary interface implementation
   684  func (m *ServiceProtocol) UnmarshalBinary(b []byte) error {
   685  	var res ServiceProtocol
   686  	if err := swag.ReadJSON(b, &res); err != nil {
   687  		return err
   688  	}
   689  	*m = res
   690  	return nil
   691  }