...

Source file src/github.com/sigstore/rekor/pkg/generated/models/log_info.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  	"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  // LogInfo log info
    35  //
    36  // swagger:model LogInfo
    37  type LogInfo struct {
    38  
    39  	// inactive shards
    40  	InactiveShards []*InactiveShardLogInfo `json:"inactiveShards"`
    41  
    42  	// The current hash value stored at the root of the merkle tree
    43  	// Required: true
    44  	// Pattern: ^[0-9a-fA-F]{64}$
    45  	RootHash *string `json:"rootHash"`
    46  
    47  	// The current signed tree head
    48  	// Required: true
    49  	SignedTreeHead *string `json:"signedTreeHead"`
    50  
    51  	// The current treeID
    52  	// Required: true
    53  	// Pattern: ^[0-9]+$
    54  	TreeID *string `json:"treeID"`
    55  
    56  	// The current number of nodes in the merkle tree
    57  	// Required: true
    58  	// Minimum: 1
    59  	TreeSize *int64 `json:"treeSize"`
    60  }
    61  
    62  // Validate validates this log info
    63  func (m *LogInfo) Validate(formats strfmt.Registry) error {
    64  	var res []error
    65  
    66  	if err := m.validateInactiveShards(formats); err != nil {
    67  		res = append(res, err)
    68  	}
    69  
    70  	if err := m.validateRootHash(formats); err != nil {
    71  		res = append(res, err)
    72  	}
    73  
    74  	if err := m.validateSignedTreeHead(formats); err != nil {
    75  		res = append(res, err)
    76  	}
    77  
    78  	if err := m.validateTreeID(formats); err != nil {
    79  		res = append(res, err)
    80  	}
    81  
    82  	if err := m.validateTreeSize(formats); err != nil {
    83  		res = append(res, err)
    84  	}
    85  
    86  	if len(res) > 0 {
    87  		return errors.CompositeValidationError(res...)
    88  	}
    89  	return nil
    90  }
    91  
    92  func (m *LogInfo) validateInactiveShards(formats strfmt.Registry) error {
    93  	if swag.IsZero(m.InactiveShards) { // not required
    94  		return nil
    95  	}
    96  
    97  	for i := 0; i < len(m.InactiveShards); i++ {
    98  		if swag.IsZero(m.InactiveShards[i]) { // not required
    99  			continue
   100  		}
   101  
   102  		if m.InactiveShards[i] != nil {
   103  			if err := m.InactiveShards[i].Validate(formats); err != nil {
   104  				if ve, ok := err.(*errors.Validation); ok {
   105  					return ve.ValidateName("inactiveShards" + "." + strconv.Itoa(i))
   106  				} else if ce, ok := err.(*errors.CompositeError); ok {
   107  					return ce.ValidateName("inactiveShards" + "." + strconv.Itoa(i))
   108  				}
   109  				return err
   110  			}
   111  		}
   112  
   113  	}
   114  
   115  	return nil
   116  }
   117  
   118  func (m *LogInfo) validateRootHash(formats strfmt.Registry) error {
   119  
   120  	if err := validate.Required("rootHash", "body", m.RootHash); err != nil {
   121  		return err
   122  	}
   123  
   124  	if err := validate.Pattern("rootHash", "body", *m.RootHash, `^[0-9a-fA-F]{64}$`); err != nil {
   125  		return err
   126  	}
   127  
   128  	return nil
   129  }
   130  
   131  func (m *LogInfo) validateSignedTreeHead(formats strfmt.Registry) error {
   132  
   133  	if err := validate.Required("signedTreeHead", "body", m.SignedTreeHead); err != nil {
   134  		return err
   135  	}
   136  
   137  	return nil
   138  }
   139  
   140  func (m *LogInfo) validateTreeID(formats strfmt.Registry) error {
   141  
   142  	if err := validate.Required("treeID", "body", m.TreeID); err != nil {
   143  		return err
   144  	}
   145  
   146  	if err := validate.Pattern("treeID", "body", *m.TreeID, `^[0-9]+$`); err != nil {
   147  		return err
   148  	}
   149  
   150  	return nil
   151  }
   152  
   153  func (m *LogInfo) validateTreeSize(formats strfmt.Registry) error {
   154  
   155  	if err := validate.Required("treeSize", "body", m.TreeSize); err != nil {
   156  		return err
   157  	}
   158  
   159  	if err := validate.MinimumInt("treeSize", "body", *m.TreeSize, 1, false); err != nil {
   160  		return err
   161  	}
   162  
   163  	return nil
   164  }
   165  
   166  // ContextValidate validate this log info based on the context it is used
   167  func (m *LogInfo) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   168  	var res []error
   169  
   170  	if err := m.contextValidateInactiveShards(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 *LogInfo) contextValidateInactiveShards(ctx context.Context, formats strfmt.Registry) error {
   181  
   182  	for i := 0; i < len(m.InactiveShards); i++ {
   183  
   184  		if m.InactiveShards[i] != nil {
   185  
   186  			if swag.IsZero(m.InactiveShards[i]) { // not required
   187  				return nil
   188  			}
   189  
   190  			if err := m.InactiveShards[i].ContextValidate(ctx, formats); err != nil {
   191  				if ve, ok := err.(*errors.Validation); ok {
   192  					return ve.ValidateName("inactiveShards" + "." + strconv.Itoa(i))
   193  				} else if ce, ok := err.(*errors.CompositeError); ok {
   194  					return ce.ValidateName("inactiveShards" + "." + strconv.Itoa(i))
   195  				}
   196  				return err
   197  			}
   198  		}
   199  
   200  	}
   201  
   202  	return nil
   203  }
   204  
   205  // MarshalBinary interface implementation
   206  func (m *LogInfo) MarshalBinary() ([]byte, error) {
   207  	if m == nil {
   208  		return nil, nil
   209  	}
   210  	return swag.WriteJSON(m)
   211  }
   212  
   213  // UnmarshalBinary interface implementation
   214  func (m *LogInfo) UnmarshalBinary(b []byte) error {
   215  	var res LogInfo
   216  	if err := swag.ReadJSON(b, &res); err != nil {
   217  		return err
   218  	}
   219  	*m = res
   220  	return nil
   221  }
   222  

View as plain text