github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_secret.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  // WritableSecret writable secret
    34  //
    35  // swagger:model WritableSecret
    36  type WritableSecret struct {
    37  
    38  	// Assigned object
    39  	// Read Only: true
    40  	AssignedObject map[string]*string `json:"assigned_object,omitempty"`
    41  
    42  	// Assigned object id
    43  	// Required: true
    44  	// Maximum: 2.147483647e+09
    45  	// Minimum: 0
    46  	AssignedObjectID *int64 `json:"assigned_object_id"`
    47  
    48  	// Assigned object type
    49  	// Required: true
    50  	AssignedObjectType *string `json:"assigned_object_type"`
    51  
    52  	// Created
    53  	// Read Only: true
    54  	// Format: date
    55  	Created strfmt.Date `json:"created,omitempty"`
    56  
    57  	// Custom fields
    58  	CustomFields interface{} `json:"custom_fields,omitempty"`
    59  
    60  	// Display
    61  	// Read Only: true
    62  	Display string `json:"display,omitempty"`
    63  
    64  	// Hash
    65  	// Read Only: true
    66  	// Min Length: 1
    67  	Hash string `json:"hash,omitempty"`
    68  
    69  	// Id
    70  	// Read Only: true
    71  	ID int64 `json:"id,omitempty"`
    72  
    73  	// Last updated
    74  	// Read Only: true
    75  	// Format: date-time
    76  	LastUpdated strfmt.DateTime `json:"last_updated,omitempty"`
    77  
    78  	// Name
    79  	// Max Length: 100
    80  	Name string `json:"name,omitempty"`
    81  
    82  	// Plaintext
    83  	// Required: true
    84  	// Min Length: 1
    85  	Plaintext *string `json:"plaintext"`
    86  
    87  	// Role
    88  	// Required: true
    89  	Role *int64 `json:"role"`
    90  
    91  	// tags
    92  	Tags []*NestedTag `json:"tags"`
    93  
    94  	// Url
    95  	// Read Only: true
    96  	// Format: uri
    97  	URL strfmt.URI `json:"url,omitempty"`
    98  }
    99  
   100  // Validate validates this writable secret
   101  func (m *WritableSecret) Validate(formats strfmt.Registry) error {
   102  	var res []error
   103  
   104  	if err := m.validateAssignedObjectID(formats); err != nil {
   105  		res = append(res, err)
   106  	}
   107  
   108  	if err := m.validateAssignedObjectType(formats); err != nil {
   109  		res = append(res, err)
   110  	}
   111  
   112  	if err := m.validateCreated(formats); err != nil {
   113  		res = append(res, err)
   114  	}
   115  
   116  	if err := m.validateHash(formats); err != nil {
   117  		res = append(res, err)
   118  	}
   119  
   120  	if err := m.validateLastUpdated(formats); err != nil {
   121  		res = append(res, err)
   122  	}
   123  
   124  	if err := m.validateName(formats); err != nil {
   125  		res = append(res, err)
   126  	}
   127  
   128  	if err := m.validatePlaintext(formats); err != nil {
   129  		res = append(res, err)
   130  	}
   131  
   132  	if err := m.validateRole(formats); err != nil {
   133  		res = append(res, err)
   134  	}
   135  
   136  	if err := m.validateTags(formats); err != nil {
   137  		res = append(res, err)
   138  	}
   139  
   140  	if err := m.validateURL(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 *WritableSecret) validateAssignedObjectID(formats strfmt.Registry) error {
   151  
   152  	if err := validate.Required("assigned_object_id", "body", m.AssignedObjectID); err != nil {
   153  		return err
   154  	}
   155  
   156  	if err := validate.MinimumInt("assigned_object_id", "body", *m.AssignedObjectID, 0, false); err != nil {
   157  		return err
   158  	}
   159  
   160  	if err := validate.MaximumInt("assigned_object_id", "body", *m.AssignedObjectID, 2.147483647e+09, false); err != nil {
   161  		return err
   162  	}
   163  
   164  	return nil
   165  }
   166  
   167  func (m *WritableSecret) validateAssignedObjectType(formats strfmt.Registry) error {
   168  
   169  	if err := validate.Required("assigned_object_type", "body", m.AssignedObjectType); err != nil {
   170  		return err
   171  	}
   172  
   173  	return nil
   174  }
   175  
   176  func (m *WritableSecret) validateCreated(formats strfmt.Registry) error {
   177  	if swag.IsZero(m.Created) { // not required
   178  		return nil
   179  	}
   180  
   181  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   182  		return err
   183  	}
   184  
   185  	return nil
   186  }
   187  
   188  func (m *WritableSecret) validateHash(formats strfmt.Registry) error {
   189  	if swag.IsZero(m.Hash) { // not required
   190  		return nil
   191  	}
   192  
   193  	if err := validate.MinLength("hash", "body", m.Hash, 1); err != nil {
   194  		return err
   195  	}
   196  
   197  	return nil
   198  }
   199  
   200  func (m *WritableSecret) validateLastUpdated(formats strfmt.Registry) error {
   201  	if swag.IsZero(m.LastUpdated) { // not required
   202  		return nil
   203  	}
   204  
   205  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   206  		return err
   207  	}
   208  
   209  	return nil
   210  }
   211  
   212  func (m *WritableSecret) validateName(formats strfmt.Registry) error {
   213  	if swag.IsZero(m.Name) { // not required
   214  		return nil
   215  	}
   216  
   217  	if err := validate.MaxLength("name", "body", m.Name, 100); err != nil {
   218  		return err
   219  	}
   220  
   221  	return nil
   222  }
   223  
   224  func (m *WritableSecret) validatePlaintext(formats strfmt.Registry) error {
   225  
   226  	if err := validate.Required("plaintext", "body", m.Plaintext); err != nil {
   227  		return err
   228  	}
   229  
   230  	if err := validate.MinLength("plaintext", "body", *m.Plaintext, 1); err != nil {
   231  		return err
   232  	}
   233  
   234  	return nil
   235  }
   236  
   237  func (m *WritableSecret) validateRole(formats strfmt.Registry) error {
   238  
   239  	if err := validate.Required("role", "body", m.Role); err != nil {
   240  		return err
   241  	}
   242  
   243  	return nil
   244  }
   245  
   246  func (m *WritableSecret) validateTags(formats strfmt.Registry) error {
   247  	if swag.IsZero(m.Tags) { // not required
   248  		return nil
   249  	}
   250  
   251  	for i := 0; i < len(m.Tags); i++ {
   252  		if swag.IsZero(m.Tags[i]) { // not required
   253  			continue
   254  		}
   255  
   256  		if m.Tags[i] != nil {
   257  			if err := m.Tags[i].Validate(formats); err != nil {
   258  				if ve, ok := err.(*errors.Validation); ok {
   259  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   260  				} else if ce, ok := err.(*errors.CompositeError); ok {
   261  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   262  				}
   263  				return err
   264  			}
   265  		}
   266  
   267  	}
   268  
   269  	return nil
   270  }
   271  
   272  func (m *WritableSecret) validateURL(formats strfmt.Registry) error {
   273  	if swag.IsZero(m.URL) { // not required
   274  		return nil
   275  	}
   276  
   277  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   278  		return err
   279  	}
   280  
   281  	return nil
   282  }
   283  
   284  // ContextValidate validate this writable secret based on the context it is used
   285  func (m *WritableSecret) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   286  	var res []error
   287  
   288  	if err := m.contextValidateAssignedObject(ctx, formats); err != nil {
   289  		res = append(res, err)
   290  	}
   291  
   292  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   293  		res = append(res, err)
   294  	}
   295  
   296  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   297  		res = append(res, err)
   298  	}
   299  
   300  	if err := m.contextValidateHash(ctx, formats); err != nil {
   301  		res = append(res, err)
   302  	}
   303  
   304  	if err := m.contextValidateID(ctx, formats); err != nil {
   305  		res = append(res, err)
   306  	}
   307  
   308  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   309  		res = append(res, err)
   310  	}
   311  
   312  	if err := m.contextValidateTags(ctx, formats); err != nil {
   313  		res = append(res, err)
   314  	}
   315  
   316  	if err := m.contextValidateURL(ctx, formats); err != nil {
   317  		res = append(res, err)
   318  	}
   319  
   320  	if len(res) > 0 {
   321  		return errors.CompositeValidationError(res...)
   322  	}
   323  	return nil
   324  }
   325  
   326  func (m *WritableSecret) contextValidateAssignedObject(ctx context.Context, formats strfmt.Registry) error {
   327  
   328  	return nil
   329  }
   330  
   331  func (m *WritableSecret) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   332  
   333  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   334  		return err
   335  	}
   336  
   337  	return nil
   338  }
   339  
   340  func (m *WritableSecret) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   341  
   342  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   343  		return err
   344  	}
   345  
   346  	return nil
   347  }
   348  
   349  func (m *WritableSecret) contextValidateHash(ctx context.Context, formats strfmt.Registry) error {
   350  
   351  	if err := validate.ReadOnly(ctx, "hash", "body", string(m.Hash)); err != nil {
   352  		return err
   353  	}
   354  
   355  	return nil
   356  }
   357  
   358  func (m *WritableSecret) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   359  
   360  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   361  		return err
   362  	}
   363  
   364  	return nil
   365  }
   366  
   367  func (m *WritableSecret) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   368  
   369  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   370  		return err
   371  	}
   372  
   373  	return nil
   374  }
   375  
   376  func (m *WritableSecret) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   377  
   378  	for i := 0; i < len(m.Tags); i++ {
   379  
   380  		if m.Tags[i] != nil {
   381  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   382  				if ve, ok := err.(*errors.Validation); ok {
   383  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   384  				} else if ce, ok := err.(*errors.CompositeError); ok {
   385  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   386  				}
   387  				return err
   388  			}
   389  		}
   390  
   391  	}
   392  
   393  	return nil
   394  }
   395  
   396  func (m *WritableSecret) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   397  
   398  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   399  		return err
   400  	}
   401  
   402  	return nil
   403  }
   404  
   405  // MarshalBinary interface implementation
   406  func (m *WritableSecret) MarshalBinary() ([]byte, error) {
   407  	if m == nil {
   408  		return nil, nil
   409  	}
   410  	return swag.WriteJSON(m)
   411  }
   412  
   413  // UnmarshalBinary interface implementation
   414  func (m *WritableSecret) UnmarshalBinary(b []byte) error {
   415  	var res WritableSecret
   416  	if err := swag.ReadJSON(b, &res); err != nil {
   417  		return err
   418  	}
   419  	*m = res
   420  	return nil
   421  }