github.com/goharbor/go-client@v0.210.0/pkg/sdk/v2.0/models/webhook_policy.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package models
     4  
     5  // This file was generated by the swagger tool.
     6  // Editing this file might prove futile when you re-run the swagger generate command
     7  
     8  import (
     9  	"context"
    10  	"strconv"
    11  
    12  	"github.com/go-openapi/errors"
    13  	"github.com/go-openapi/strfmt"
    14  	"github.com/go-openapi/swag"
    15  	"github.com/go-openapi/validate"
    16  )
    17  
    18  // WebhookPolicy The webhook policy object
    19  //
    20  // swagger:model WebhookPolicy
    21  type WebhookPolicy struct {
    22  
    23  	// The create time of the webhook policy.
    24  	// Format: date-time
    25  	CreationTime strfmt.DateTime `json:"creation_time,omitempty"`
    26  
    27  	// The creator of the webhook policy.
    28  	Creator string `json:"creator,omitempty"`
    29  
    30  	// The description of webhook policy.
    31  	Description string `json:"description,omitempty"`
    32  
    33  	// Whether the webhook policy is enabled or not.
    34  	Enabled bool `json:"enabled"`
    35  
    36  	// event types
    37  	EventTypes []string `json:"event_types"`
    38  
    39  	// The webhook policy ID.
    40  	ID int64 `json:"id,omitempty"`
    41  
    42  	// The name of webhook policy.
    43  	Name string `json:"name,omitempty"`
    44  
    45  	// The project ID of webhook policy.
    46  	ProjectID int64 `json:"project_id,omitempty"`
    47  
    48  	// targets
    49  	Targets []*WebhookTargetObject `json:"targets"`
    50  
    51  	// The update time of the webhook policy.
    52  	// Format: date-time
    53  	UpdateTime strfmt.DateTime `json:"update_time,omitempty"`
    54  }
    55  
    56  // Validate validates this webhook policy
    57  func (m *WebhookPolicy) Validate(formats strfmt.Registry) error {
    58  	var res []error
    59  
    60  	if err := m.validateCreationTime(formats); err != nil {
    61  		res = append(res, err)
    62  	}
    63  
    64  	if err := m.validateTargets(formats); err != nil {
    65  		res = append(res, err)
    66  	}
    67  
    68  	if err := m.validateUpdateTime(formats); err != nil {
    69  		res = append(res, err)
    70  	}
    71  
    72  	if len(res) > 0 {
    73  		return errors.CompositeValidationError(res...)
    74  	}
    75  	return nil
    76  }
    77  
    78  func (m *WebhookPolicy) validateCreationTime(formats strfmt.Registry) error {
    79  	if swag.IsZero(m.CreationTime) { // not required
    80  		return nil
    81  	}
    82  
    83  	if err := validate.FormatOf("creation_time", "body", "date-time", m.CreationTime.String(), formats); err != nil {
    84  		return err
    85  	}
    86  
    87  	return nil
    88  }
    89  
    90  func (m *WebhookPolicy) validateTargets(formats strfmt.Registry) error {
    91  	if swag.IsZero(m.Targets) { // not required
    92  		return nil
    93  	}
    94  
    95  	for i := 0; i < len(m.Targets); i++ {
    96  		if swag.IsZero(m.Targets[i]) { // not required
    97  			continue
    98  		}
    99  
   100  		if m.Targets[i] != nil {
   101  			if err := m.Targets[i].Validate(formats); err != nil {
   102  				if ve, ok := err.(*errors.Validation); ok {
   103  					return ve.ValidateName("targets" + "." + strconv.Itoa(i))
   104  				} else if ce, ok := err.(*errors.CompositeError); ok {
   105  					return ce.ValidateName("targets" + "." + strconv.Itoa(i))
   106  				}
   107  				return err
   108  			}
   109  		}
   110  
   111  	}
   112  
   113  	return nil
   114  }
   115  
   116  func (m *WebhookPolicy) validateUpdateTime(formats strfmt.Registry) error {
   117  	if swag.IsZero(m.UpdateTime) { // not required
   118  		return nil
   119  	}
   120  
   121  	if err := validate.FormatOf("update_time", "body", "date-time", m.UpdateTime.String(), formats); err != nil {
   122  		return err
   123  	}
   124  
   125  	return nil
   126  }
   127  
   128  // ContextValidate validate this webhook policy based on the context it is used
   129  func (m *WebhookPolicy) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   130  	var res []error
   131  
   132  	if err := m.contextValidateTargets(ctx, formats); err != nil {
   133  		res = append(res, err)
   134  	}
   135  
   136  	if len(res) > 0 {
   137  		return errors.CompositeValidationError(res...)
   138  	}
   139  	return nil
   140  }
   141  
   142  func (m *WebhookPolicy) contextValidateTargets(ctx context.Context, formats strfmt.Registry) error {
   143  
   144  	for i := 0; i < len(m.Targets); i++ {
   145  
   146  		if m.Targets[i] != nil {
   147  			if err := m.Targets[i].ContextValidate(ctx, formats); err != nil {
   148  				if ve, ok := err.(*errors.Validation); ok {
   149  					return ve.ValidateName("targets" + "." + strconv.Itoa(i))
   150  				} else if ce, ok := err.(*errors.CompositeError); ok {
   151  					return ce.ValidateName("targets" + "." + strconv.Itoa(i))
   152  				}
   153  				return err
   154  			}
   155  		}
   156  
   157  	}
   158  
   159  	return nil
   160  }
   161  
   162  // MarshalBinary interface implementation
   163  func (m *WebhookPolicy) MarshalBinary() ([]byte, error) {
   164  	if m == nil {
   165  		return nil, nil
   166  	}
   167  	return swag.WriteJSON(m)
   168  }
   169  
   170  // UnmarshalBinary interface implementation
   171  func (m *WebhookPolicy) UnmarshalBinary(b []byte) error {
   172  	var res WebhookPolicy
   173  	if err := swag.ReadJSON(b, &res); err != nil {
   174  		return err
   175  	}
   176  	*m = res
   177  	return nil
   178  }