...

Source file src/github.com/sigstore/rekor/pkg/generated/models/search_index.go

Documentation: github.com/sigstore/rekor/pkg/generated/models

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  //
     4  // Copyright 2021 The Sigstore Authors.
     5  //
     6  // Licensed under the Apache License, Version 2.0 (the "License");
     7  // you may not use this file except in compliance with the License.
     8  // You may obtain a copy of the License at
     9  //
    10  //     http://www.apache.org/licenses/LICENSE-2.0
    11  //
    12  // Unless required by applicable law or agreed to in writing, software
    13  // distributed under the License is distributed on an "AS IS" BASIS,
    14  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  // See the License for the specific language governing permissions and
    16  // limitations under the License.
    17  //
    18  
    19  package models
    20  
    21  // This file was generated by the swagger tool.
    22  // Editing this file might prove futile when you re-run the swagger generate command
    23  
    24  import (
    25  	"context"
    26  	"encoding/json"
    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  // SearchIndex search index
    35  //
    36  // swagger:model SearchIndex
    37  type SearchIndex struct {
    38  
    39  	// email
    40  	// Format: email
    41  	Email strfmt.Email `json:"email,omitempty"`
    42  
    43  	// hash
    44  	// Pattern: ^(sha512:)?[0-9a-fA-F]{128}$|^(sha256:)?[0-9a-fA-F]{64}$|^(sha1:)?[0-9a-fA-F]{40}$
    45  	Hash string `json:"hash,omitempty"`
    46  
    47  	// operator
    48  	// Enum: [and or]
    49  	Operator string `json:"operator,omitempty"`
    50  
    51  	// public key
    52  	PublicKey *SearchIndexPublicKey `json:"publicKey,omitempty"`
    53  }
    54  
    55  // Validate validates this search index
    56  func (m *SearchIndex) Validate(formats strfmt.Registry) error {
    57  	var res []error
    58  
    59  	if err := m.validateEmail(formats); err != nil {
    60  		res = append(res, err)
    61  	}
    62  
    63  	if err := m.validateHash(formats); err != nil {
    64  		res = append(res, err)
    65  	}
    66  
    67  	if err := m.validateOperator(formats); err != nil {
    68  		res = append(res, err)
    69  	}
    70  
    71  	if err := m.validatePublicKey(formats); err != nil {
    72  		res = append(res, err)
    73  	}
    74  
    75  	if len(res) > 0 {
    76  		return errors.CompositeValidationError(res...)
    77  	}
    78  	return nil
    79  }
    80  
    81  func (m *SearchIndex) validateEmail(formats strfmt.Registry) error {
    82  	if swag.IsZero(m.Email) { // not required
    83  		return nil
    84  	}
    85  
    86  	if err := validate.FormatOf("email", "body", "email", m.Email.String(), formats); err != nil {
    87  		return err
    88  	}
    89  
    90  	return nil
    91  }
    92  
    93  func (m *SearchIndex) validateHash(formats strfmt.Registry) error {
    94  	if swag.IsZero(m.Hash) { // not required
    95  		return nil
    96  	}
    97  
    98  	if err := validate.Pattern("hash", "body", m.Hash, `^(sha512:)?[0-9a-fA-F]{128}$|^(sha256:)?[0-9a-fA-F]{64}$|^(sha1:)?[0-9a-fA-F]{40}$`); err != nil {
    99  		return err
   100  	}
   101  
   102  	return nil
   103  }
   104  
   105  var searchIndexTypeOperatorPropEnum []interface{}
   106  
   107  func init() {
   108  	var res []string
   109  	if err := json.Unmarshal([]byte(`["and","or"]`), &res); err != nil {
   110  		panic(err)
   111  	}
   112  	for _, v := range res {
   113  		searchIndexTypeOperatorPropEnum = append(searchIndexTypeOperatorPropEnum, v)
   114  	}
   115  }
   116  
   117  const (
   118  
   119  	// SearchIndexOperatorAnd captures enum value "and"
   120  	SearchIndexOperatorAnd string = "and"
   121  
   122  	// SearchIndexOperatorOr captures enum value "or"
   123  	SearchIndexOperatorOr string = "or"
   124  )
   125  
   126  // prop value enum
   127  func (m *SearchIndex) validateOperatorEnum(path, location string, value string) error {
   128  	if err := validate.EnumCase(path, location, value, searchIndexTypeOperatorPropEnum, true); err != nil {
   129  		return err
   130  	}
   131  	return nil
   132  }
   133  
   134  func (m *SearchIndex) validateOperator(formats strfmt.Registry) error {
   135  	if swag.IsZero(m.Operator) { // not required
   136  		return nil
   137  	}
   138  
   139  	// value enum
   140  	if err := m.validateOperatorEnum("operator", "body", m.Operator); err != nil {
   141  		return err
   142  	}
   143  
   144  	return nil
   145  }
   146  
   147  func (m *SearchIndex) validatePublicKey(formats strfmt.Registry) error {
   148  	if swag.IsZero(m.PublicKey) { // not required
   149  		return nil
   150  	}
   151  
   152  	if m.PublicKey != nil {
   153  		if err := m.PublicKey.Validate(formats); err != nil {
   154  			if ve, ok := err.(*errors.Validation); ok {
   155  				return ve.ValidateName("publicKey")
   156  			} else if ce, ok := err.(*errors.CompositeError); ok {
   157  				return ce.ValidateName("publicKey")
   158  			}
   159  			return err
   160  		}
   161  	}
   162  
   163  	return nil
   164  }
   165  
   166  // ContextValidate validate this search index based on the context it is used
   167  func (m *SearchIndex) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   168  	var res []error
   169  
   170  	if err := m.contextValidatePublicKey(ctx, formats); err != nil {
   171  		res = append(res, err)
   172  	}
   173  
   174  	if len(res) > 0 {
   175  		return errors.CompositeValidationError(res...)
   176  	}
   177  	return nil
   178  }
   179  
   180  func (m *SearchIndex) contextValidatePublicKey(ctx context.Context, formats strfmt.Registry) error {
   181  
   182  	if m.PublicKey != nil {
   183  
   184  		if swag.IsZero(m.PublicKey) { // not required
   185  			return nil
   186  		}
   187  
   188  		if err := m.PublicKey.ContextValidate(ctx, formats); err != nil {
   189  			if ve, ok := err.(*errors.Validation); ok {
   190  				return ve.ValidateName("publicKey")
   191  			} else if ce, ok := err.(*errors.CompositeError); ok {
   192  				return ce.ValidateName("publicKey")
   193  			}
   194  			return err
   195  		}
   196  	}
   197  
   198  	return nil
   199  }
   200  
   201  // MarshalBinary interface implementation
   202  func (m *SearchIndex) MarshalBinary() ([]byte, error) {
   203  	if m == nil {
   204  		return nil, nil
   205  	}
   206  	return swag.WriteJSON(m)
   207  }
   208  
   209  // UnmarshalBinary interface implementation
   210  func (m *SearchIndex) UnmarshalBinary(b []byte) error {
   211  	var res SearchIndex
   212  	if err := swag.ReadJSON(b, &res); err != nil {
   213  		return err
   214  	}
   215  	*m = res
   216  	return nil
   217  }
   218  
   219  // SearchIndexPublicKey search index public key
   220  //
   221  // swagger:model SearchIndexPublicKey
   222  type SearchIndexPublicKey struct {
   223  
   224  	// content
   225  	// Format: byte
   226  	Content strfmt.Base64 `json:"content,omitempty"`
   227  
   228  	// format
   229  	// Required: true
   230  	// Enum: [pgp x509 minisign ssh tuf]
   231  	Format *string `json:"format"`
   232  
   233  	// url
   234  	// Format: uri
   235  	URL strfmt.URI `json:"url,omitempty"`
   236  }
   237  
   238  // Validate validates this search index public key
   239  func (m *SearchIndexPublicKey) Validate(formats strfmt.Registry) error {
   240  	var res []error
   241  
   242  	if err := m.validateFormat(formats); err != nil {
   243  		res = append(res, err)
   244  	}
   245  
   246  	if err := m.validateURL(formats); err != nil {
   247  		res = append(res, err)
   248  	}
   249  
   250  	if len(res) > 0 {
   251  		return errors.CompositeValidationError(res...)
   252  	}
   253  	return nil
   254  }
   255  
   256  var searchIndexPublicKeyTypeFormatPropEnum []interface{}
   257  
   258  func init() {
   259  	var res []string
   260  	if err := json.Unmarshal([]byte(`["pgp","x509","minisign","ssh","tuf"]`), &res); err != nil {
   261  		panic(err)
   262  	}
   263  	for _, v := range res {
   264  		searchIndexPublicKeyTypeFormatPropEnum = append(searchIndexPublicKeyTypeFormatPropEnum, v)
   265  	}
   266  }
   267  
   268  const (
   269  
   270  	// SearchIndexPublicKeyFormatPgp captures enum value "pgp"
   271  	SearchIndexPublicKeyFormatPgp string = "pgp"
   272  
   273  	// SearchIndexPublicKeyFormatX509 captures enum value "x509"
   274  	SearchIndexPublicKeyFormatX509 string = "x509"
   275  
   276  	// SearchIndexPublicKeyFormatMinisign captures enum value "minisign"
   277  	SearchIndexPublicKeyFormatMinisign string = "minisign"
   278  
   279  	// SearchIndexPublicKeyFormatSSH captures enum value "ssh"
   280  	SearchIndexPublicKeyFormatSSH string = "ssh"
   281  
   282  	// SearchIndexPublicKeyFormatTUF captures enum value "tuf"
   283  	SearchIndexPublicKeyFormatTUF string = "tuf"
   284  )
   285  
   286  // prop value enum
   287  func (m *SearchIndexPublicKey) validateFormatEnum(path, location string, value string) error {
   288  	if err := validate.EnumCase(path, location, value, searchIndexPublicKeyTypeFormatPropEnum, true); err != nil {
   289  		return err
   290  	}
   291  	return nil
   292  }
   293  
   294  func (m *SearchIndexPublicKey) validateFormat(formats strfmt.Registry) error {
   295  
   296  	if err := validate.Required("publicKey"+"."+"format", "body", m.Format); err != nil {
   297  		return err
   298  	}
   299  
   300  	// value enum
   301  	if err := m.validateFormatEnum("publicKey"+"."+"format", "body", *m.Format); err != nil {
   302  		return err
   303  	}
   304  
   305  	return nil
   306  }
   307  
   308  func (m *SearchIndexPublicKey) validateURL(formats strfmt.Registry) error {
   309  	if swag.IsZero(m.URL) { // not required
   310  		return nil
   311  	}
   312  
   313  	if err := validate.FormatOf("publicKey"+"."+"url", "body", "uri", m.URL.String(), formats); err != nil {
   314  		return err
   315  	}
   316  
   317  	return nil
   318  }
   319  
   320  // ContextValidate validates this search index public key based on context it is used
   321  func (m *SearchIndexPublicKey) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   322  	return nil
   323  }
   324  
   325  // MarshalBinary interface implementation
   326  func (m *SearchIndexPublicKey) MarshalBinary() ([]byte, error) {
   327  	if m == nil {
   328  		return nil, nil
   329  	}
   330  	return swag.WriteJSON(m)
   331  }
   332  
   333  // UnmarshalBinary interface implementation
   334  func (m *SearchIndexPublicKey) UnmarshalBinary(b []byte) error {
   335  	var res SearchIndexPublicKey
   336  	if err := swag.ReadJSON(b, &res); err != nil {
   337  		return err
   338  	}
   339  	*m = res
   340  	return nil
   341  }
   342  

View as plain text