github.com/digitalocean/go-netbox@v0.0.2/netbox/models/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  // Secret secret
    34  //
    35  // swagger:model Secret
    36  type Secret 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 *NestedSecretRole `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 secret
   101  func (m *Secret) 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 *Secret) 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 *Secret) 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 *Secret) 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 *Secret) 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 *Secret) 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 *Secret) 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 *Secret) 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 *Secret) validateRole(formats strfmt.Registry) error {
   238  
   239  	if err := validate.Required("role", "body", m.Role); err != nil {
   240  		return err
   241  	}
   242  
   243  	if m.Role != nil {
   244  		if err := m.Role.Validate(formats); err != nil {
   245  			if ve, ok := err.(*errors.Validation); ok {
   246  				return ve.ValidateName("role")
   247  			} else if ce, ok := err.(*errors.CompositeError); ok {
   248  				return ce.ValidateName("role")
   249  			}
   250  			return err
   251  		}
   252  	}
   253  
   254  	return nil
   255  }
   256  
   257  func (m *Secret) validateTags(formats strfmt.Registry) error {
   258  	if swag.IsZero(m.Tags) { // not required
   259  		return nil
   260  	}
   261  
   262  	for i := 0; i < len(m.Tags); i++ {
   263  		if swag.IsZero(m.Tags[i]) { // not required
   264  			continue
   265  		}
   266  
   267  		if m.Tags[i] != nil {
   268  			if err := m.Tags[i].Validate(formats); err != nil {
   269  				if ve, ok := err.(*errors.Validation); ok {
   270  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   271  				} else if ce, ok := err.(*errors.CompositeError); ok {
   272  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   273  				}
   274  				return err
   275  			}
   276  		}
   277  
   278  	}
   279  
   280  	return nil
   281  }
   282  
   283  func (m *Secret) validateURL(formats strfmt.Registry) error {
   284  	if swag.IsZero(m.URL) { // not required
   285  		return nil
   286  	}
   287  
   288  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   289  		return err
   290  	}
   291  
   292  	return nil
   293  }
   294  
   295  // ContextValidate validate this secret based on the context it is used
   296  func (m *Secret) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   297  	var res []error
   298  
   299  	if err := m.contextValidateAssignedObject(ctx, formats); err != nil {
   300  		res = append(res, err)
   301  	}
   302  
   303  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   304  		res = append(res, err)
   305  	}
   306  
   307  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   308  		res = append(res, err)
   309  	}
   310  
   311  	if err := m.contextValidateHash(ctx, formats); err != nil {
   312  		res = append(res, err)
   313  	}
   314  
   315  	if err := m.contextValidateID(ctx, formats); err != nil {
   316  		res = append(res, err)
   317  	}
   318  
   319  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   320  		res = append(res, err)
   321  	}
   322  
   323  	if err := m.contextValidateRole(ctx, formats); err != nil {
   324  		res = append(res, err)
   325  	}
   326  
   327  	if err := m.contextValidateTags(ctx, formats); err != nil {
   328  		res = append(res, err)
   329  	}
   330  
   331  	if err := m.contextValidateURL(ctx, formats); err != nil {
   332  		res = append(res, err)
   333  	}
   334  
   335  	if len(res) > 0 {
   336  		return errors.CompositeValidationError(res...)
   337  	}
   338  	return nil
   339  }
   340  
   341  func (m *Secret) contextValidateAssignedObject(ctx context.Context, formats strfmt.Registry) error {
   342  
   343  	return nil
   344  }
   345  
   346  func (m *Secret) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   347  
   348  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   349  		return err
   350  	}
   351  
   352  	return nil
   353  }
   354  
   355  func (m *Secret) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   356  
   357  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   358  		return err
   359  	}
   360  
   361  	return nil
   362  }
   363  
   364  func (m *Secret) contextValidateHash(ctx context.Context, formats strfmt.Registry) error {
   365  
   366  	if err := validate.ReadOnly(ctx, "hash", "body", string(m.Hash)); err != nil {
   367  		return err
   368  	}
   369  
   370  	return nil
   371  }
   372  
   373  func (m *Secret) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   374  
   375  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   376  		return err
   377  	}
   378  
   379  	return nil
   380  }
   381  
   382  func (m *Secret) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   383  
   384  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   385  		return err
   386  	}
   387  
   388  	return nil
   389  }
   390  
   391  func (m *Secret) contextValidateRole(ctx context.Context, formats strfmt.Registry) error {
   392  
   393  	if m.Role != nil {
   394  		if err := m.Role.ContextValidate(ctx, formats); err != nil {
   395  			if ve, ok := err.(*errors.Validation); ok {
   396  				return ve.ValidateName("role")
   397  			} else if ce, ok := err.(*errors.CompositeError); ok {
   398  				return ce.ValidateName("role")
   399  			}
   400  			return err
   401  		}
   402  	}
   403  
   404  	return nil
   405  }
   406  
   407  func (m *Secret) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   408  
   409  	for i := 0; i < len(m.Tags); i++ {
   410  
   411  		if m.Tags[i] != nil {
   412  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   413  				if ve, ok := err.(*errors.Validation); ok {
   414  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   415  				} else if ce, ok := err.(*errors.CompositeError); ok {
   416  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   417  				}
   418  				return err
   419  			}
   420  		}
   421  
   422  	}
   423  
   424  	return nil
   425  }
   426  
   427  func (m *Secret) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   428  
   429  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   430  		return err
   431  	}
   432  
   433  	return nil
   434  }
   435  
   436  // MarshalBinary interface implementation
   437  func (m *Secret) MarshalBinary() ([]byte, error) {
   438  	if m == nil {
   439  		return nil, nil
   440  	}
   441  	return swag.WriteJSON(m)
   442  }
   443  
   444  // UnmarshalBinary interface implementation
   445  func (m *Secret) UnmarshalBinary(b []byte) error {
   446  	var res Secret
   447  	if err := swag.ReadJSON(b, &res); err != nil {
   448  		return err
   449  	}
   450  	*m = res
   451  	return nil
   452  }