autogits/bots-common/gitea-generated/models/g_p_g_key.go

252 lines
5.4 KiB
Go
Raw Normal View History

2024-07-07 21:08:41 +02:00
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"strconv"
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// GPGKey GPGKey a user GPG key to sign commit and tag in repository
//
// swagger:model GPGKey
type GPGKey struct {
// can certify
CanCertify bool `json:"can_certify,omitempty"`
// can encrypt comms
CanEncryptComms bool `json:"can_encrypt_comms,omitempty"`
// can encrypt storage
CanEncryptStorage bool `json:"can_encrypt_storage,omitempty"`
// can sign
CanSign bool `json:"can_sign,omitempty"`
// created
// Format: date-time
Created strfmt.DateTime `json:"created_at,omitempty"`
// emails
Emails []*GPGKeyEmail `json:"emails"`
// expires
// Format: date-time
Expires strfmt.DateTime `json:"expires_at,omitempty"`
// ID
ID int64 `json:"id,omitempty"`
// key ID
KeyID string `json:"key_id,omitempty"`
// primary key ID
PrimaryKeyID string `json:"primary_key_id,omitempty"`
// public key
PublicKey string `json:"public_key,omitempty"`
// subs key
SubsKey []*GPGKey `json:"subkeys"`
// verified
Verified bool `json:"verified,omitempty"`
}
// Validate validates this g p g key
func (m *GPGKey) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCreated(formats); err != nil {
res = append(res, err)
}
if err := m.validateEmails(formats); err != nil {
res = append(res, err)
}
if err := m.validateExpires(formats); err != nil {
res = append(res, err)
}
if err := m.validateSubsKey(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *GPGKey) validateCreated(formats strfmt.Registry) error {
if swag.IsZero(m.Created) { // not required
return nil
}
if err := validate.FormatOf("created_at", "body", "date-time", m.Created.String(), formats); err != nil {
return err
}
return nil
}
func (m *GPGKey) validateEmails(formats strfmt.Registry) error {
if swag.IsZero(m.Emails) { // not required
return nil
}
for i := 0; i < len(m.Emails); i++ {
if swag.IsZero(m.Emails[i]) { // not required
continue
}
if m.Emails[i] != nil {
if err := m.Emails[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("emails" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("emails" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *GPGKey) validateExpires(formats strfmt.Registry) error {
if swag.IsZero(m.Expires) { // not required
return nil
}
if err := validate.FormatOf("expires_at", "body", "date-time", m.Expires.String(), formats); err != nil {
return err
}
return nil
}
func (m *GPGKey) validateSubsKey(formats strfmt.Registry) error {
if swag.IsZero(m.SubsKey) { // not required
return nil
}
for i := 0; i < len(m.SubsKey); i++ {
if swag.IsZero(m.SubsKey[i]) { // not required
continue
}
if m.SubsKey[i] != nil {
if err := m.SubsKey[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("subkeys" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("subkeys" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// ContextValidate validate this g p g key based on the context it is used
func (m *GPGKey) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
if err := m.contextValidateEmails(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateSubsKey(ctx, formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *GPGKey) contextValidateEmails(ctx context.Context, formats strfmt.Registry) error {
for i := 0; i < len(m.Emails); i++ {
if m.Emails[i] != nil {
if swag.IsZero(m.Emails[i]) { // not required
return nil
}
if err := m.Emails[i].ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("emails" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("emails" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *GPGKey) contextValidateSubsKey(ctx context.Context, formats strfmt.Registry) error {
for i := 0; i < len(m.SubsKey); i++ {
if m.SubsKey[i] != nil {
if swag.IsZero(m.SubsKey[i]) { // not required
return nil
}
if err := m.SubsKey[i].ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("subkeys" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("subkeys" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *GPGKey) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *GPGKey) UnmarshalBinary(b []byte) error {
var res GPGKey
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}