github.com/goharbor/go-client@v0.210.0/pkg/sdk/v2.0/models/replication_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  // ReplicationPolicy replication policy
    19  //
    20  // swagger:model ReplicationPolicy
    21  type ReplicationPolicy struct {
    22  
    23  	// Whether to enable copy by chunk.
    24  	CopyByChunk *bool `json:"copy_by_chunk,omitempty"`
    25  
    26  	// The create time of the policy.
    27  	// Format: date-time
    28  	CreationTime strfmt.DateTime `json:"creation_time,omitempty"`
    29  
    30  	// Deprecated, use "replicate_deletion" instead. Whether to replicate the deletion operation.
    31  	Deletion bool `json:"deletion,omitempty"`
    32  
    33  	// The description of the policy.
    34  	Description string `json:"description,omitempty"`
    35  
    36  	// The destination namespace.
    37  	DestNamespace string `json:"dest_namespace,omitempty"`
    38  
    39  	// Specify how many path components will be replaced by the provided destination namespace.
    40  	// The default value is -1 in which case the legacy mode will be applied.
    41  	DestNamespaceReplaceCount *int8 `json:"dest_namespace_replace_count,omitempty"`
    42  
    43  	// The destination registry.
    44  	DestRegistry *Registry `json:"dest_registry,omitempty"`
    45  
    46  	// Whether the policy is enabled or not.
    47  	Enabled bool `json:"enabled,omitempty"`
    48  
    49  	// The replication policy filter array.
    50  	Filters []*ReplicationFilter `json:"filters"`
    51  
    52  	// The policy ID.
    53  	ID int64 `json:"id,omitempty"`
    54  
    55  	// The policy name.
    56  	Name string `json:"name,omitempty"`
    57  
    58  	// Whether to override the resources on the destination registry.
    59  	Override bool `json:"override,omitempty"`
    60  
    61  	// Whether to replicate the deletion operation.
    62  	ReplicateDeletion bool `json:"replicate_deletion,omitempty"`
    63  
    64  	// speed limit for each task
    65  	Speed *int32 `json:"speed,omitempty"`
    66  
    67  	// The source registry.
    68  	SrcRegistry *Registry `json:"src_registry,omitempty"`
    69  
    70  	// trigger
    71  	Trigger *ReplicationTrigger `json:"trigger,omitempty"`
    72  
    73  	// The update time of the policy.
    74  	// Format: date-time
    75  	UpdateTime strfmt.DateTime `json:"update_time,omitempty"`
    76  }
    77  
    78  // Validate validates this replication policy
    79  func (m *ReplicationPolicy) Validate(formats strfmt.Registry) error {
    80  	var res []error
    81  
    82  	if err := m.validateCreationTime(formats); err != nil {
    83  		res = append(res, err)
    84  	}
    85  
    86  	if err := m.validateDestRegistry(formats); err != nil {
    87  		res = append(res, err)
    88  	}
    89  
    90  	if err := m.validateFilters(formats); err != nil {
    91  		res = append(res, err)
    92  	}
    93  
    94  	if err := m.validateSrcRegistry(formats); err != nil {
    95  		res = append(res, err)
    96  	}
    97  
    98  	if err := m.validateTrigger(formats); err != nil {
    99  		res = append(res, err)
   100  	}
   101  
   102  	if err := m.validateUpdateTime(formats); err != nil {
   103  		res = append(res, err)
   104  	}
   105  
   106  	if len(res) > 0 {
   107  		return errors.CompositeValidationError(res...)
   108  	}
   109  	return nil
   110  }
   111  
   112  func (m *ReplicationPolicy) validateCreationTime(formats strfmt.Registry) error {
   113  	if swag.IsZero(m.CreationTime) { // not required
   114  		return nil
   115  	}
   116  
   117  	if err := validate.FormatOf("creation_time", "body", "date-time", m.CreationTime.String(), formats); err != nil {
   118  		return err
   119  	}
   120  
   121  	return nil
   122  }
   123  
   124  func (m *ReplicationPolicy) validateDestRegistry(formats strfmt.Registry) error {
   125  	if swag.IsZero(m.DestRegistry) { // not required
   126  		return nil
   127  	}
   128  
   129  	if m.DestRegistry != nil {
   130  		if err := m.DestRegistry.Validate(formats); err != nil {
   131  			if ve, ok := err.(*errors.Validation); ok {
   132  				return ve.ValidateName("dest_registry")
   133  			} else if ce, ok := err.(*errors.CompositeError); ok {
   134  				return ce.ValidateName("dest_registry")
   135  			}
   136  			return err
   137  		}
   138  	}
   139  
   140  	return nil
   141  }
   142  
   143  func (m *ReplicationPolicy) validateFilters(formats strfmt.Registry) error {
   144  	if swag.IsZero(m.Filters) { // not required
   145  		return nil
   146  	}
   147  
   148  	for i := 0; i < len(m.Filters); i++ {
   149  		if swag.IsZero(m.Filters[i]) { // not required
   150  			continue
   151  		}
   152  
   153  		if m.Filters[i] != nil {
   154  			if err := m.Filters[i].Validate(formats); err != nil {
   155  				if ve, ok := err.(*errors.Validation); ok {
   156  					return ve.ValidateName("filters" + "." + strconv.Itoa(i))
   157  				} else if ce, ok := err.(*errors.CompositeError); ok {
   158  					return ce.ValidateName("filters" + "." + strconv.Itoa(i))
   159  				}
   160  				return err
   161  			}
   162  		}
   163  
   164  	}
   165  
   166  	return nil
   167  }
   168  
   169  func (m *ReplicationPolicy) validateSrcRegistry(formats strfmt.Registry) error {
   170  	if swag.IsZero(m.SrcRegistry) { // not required
   171  		return nil
   172  	}
   173  
   174  	if m.SrcRegistry != nil {
   175  		if err := m.SrcRegistry.Validate(formats); err != nil {
   176  			if ve, ok := err.(*errors.Validation); ok {
   177  				return ve.ValidateName("src_registry")
   178  			} else if ce, ok := err.(*errors.CompositeError); ok {
   179  				return ce.ValidateName("src_registry")
   180  			}
   181  			return err
   182  		}
   183  	}
   184  
   185  	return nil
   186  }
   187  
   188  func (m *ReplicationPolicy) validateTrigger(formats strfmt.Registry) error {
   189  	if swag.IsZero(m.Trigger) { // not required
   190  		return nil
   191  	}
   192  
   193  	if m.Trigger != nil {
   194  		if err := m.Trigger.Validate(formats); err != nil {
   195  			if ve, ok := err.(*errors.Validation); ok {
   196  				return ve.ValidateName("trigger")
   197  			} else if ce, ok := err.(*errors.CompositeError); ok {
   198  				return ce.ValidateName("trigger")
   199  			}
   200  			return err
   201  		}
   202  	}
   203  
   204  	return nil
   205  }
   206  
   207  func (m *ReplicationPolicy) validateUpdateTime(formats strfmt.Registry) error {
   208  	if swag.IsZero(m.UpdateTime) { // not required
   209  		return nil
   210  	}
   211  
   212  	if err := validate.FormatOf("update_time", "body", "date-time", m.UpdateTime.String(), formats); err != nil {
   213  		return err
   214  	}
   215  
   216  	return nil
   217  }
   218  
   219  // ContextValidate validate this replication policy based on the context it is used
   220  func (m *ReplicationPolicy) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   221  	var res []error
   222  
   223  	if err := m.contextValidateDestRegistry(ctx, formats); err != nil {
   224  		res = append(res, err)
   225  	}
   226  
   227  	if err := m.contextValidateFilters(ctx, formats); err != nil {
   228  		res = append(res, err)
   229  	}
   230  
   231  	if err := m.contextValidateSrcRegistry(ctx, formats); err != nil {
   232  		res = append(res, err)
   233  	}
   234  
   235  	if err := m.contextValidateTrigger(ctx, formats); err != nil {
   236  		res = append(res, err)
   237  	}
   238  
   239  	if len(res) > 0 {
   240  		return errors.CompositeValidationError(res...)
   241  	}
   242  	return nil
   243  }
   244  
   245  func (m *ReplicationPolicy) contextValidateDestRegistry(ctx context.Context, formats strfmt.Registry) error {
   246  
   247  	if m.DestRegistry != nil {
   248  		if err := m.DestRegistry.ContextValidate(ctx, formats); err != nil {
   249  			if ve, ok := err.(*errors.Validation); ok {
   250  				return ve.ValidateName("dest_registry")
   251  			} else if ce, ok := err.(*errors.CompositeError); ok {
   252  				return ce.ValidateName("dest_registry")
   253  			}
   254  			return err
   255  		}
   256  	}
   257  
   258  	return nil
   259  }
   260  
   261  func (m *ReplicationPolicy) contextValidateFilters(ctx context.Context, formats strfmt.Registry) error {
   262  
   263  	for i := 0; i < len(m.Filters); i++ {
   264  
   265  		if m.Filters[i] != nil {
   266  			if err := m.Filters[i].ContextValidate(ctx, formats); err != nil {
   267  				if ve, ok := err.(*errors.Validation); ok {
   268  					return ve.ValidateName("filters" + "." + strconv.Itoa(i))
   269  				} else if ce, ok := err.(*errors.CompositeError); ok {
   270  					return ce.ValidateName("filters" + "." + strconv.Itoa(i))
   271  				}
   272  				return err
   273  			}
   274  		}
   275  
   276  	}
   277  
   278  	return nil
   279  }
   280  
   281  func (m *ReplicationPolicy) contextValidateSrcRegistry(ctx context.Context, formats strfmt.Registry) error {
   282  
   283  	if m.SrcRegistry != nil {
   284  		if err := m.SrcRegistry.ContextValidate(ctx, formats); err != nil {
   285  			if ve, ok := err.(*errors.Validation); ok {
   286  				return ve.ValidateName("src_registry")
   287  			} else if ce, ok := err.(*errors.CompositeError); ok {
   288  				return ce.ValidateName("src_registry")
   289  			}
   290  			return err
   291  		}
   292  	}
   293  
   294  	return nil
   295  }
   296  
   297  func (m *ReplicationPolicy) contextValidateTrigger(ctx context.Context, formats strfmt.Registry) error {
   298  
   299  	if m.Trigger != nil {
   300  		if err := m.Trigger.ContextValidate(ctx, formats); err != nil {
   301  			if ve, ok := err.(*errors.Validation); ok {
   302  				return ve.ValidateName("trigger")
   303  			} else if ce, ok := err.(*errors.CompositeError); ok {
   304  				return ce.ValidateName("trigger")
   305  			}
   306  			return err
   307  		}
   308  	}
   309  
   310  	return nil
   311  }
   312  
   313  // MarshalBinary interface implementation
   314  func (m *ReplicationPolicy) MarshalBinary() ([]byte, error) {
   315  	if m == nil {
   316  		return nil, nil
   317  	}
   318  	return swag.WriteJSON(m)
   319  }
   320  
   321  // UnmarshalBinary interface implementation
   322  func (m *ReplicationPolicy) UnmarshalBinary(b []byte) error {
   323  	var res ReplicationPolicy
   324  	if err := swag.ReadJSON(b, &res); err != nil {
   325  		return err
   326  	}
   327  	*m = res
   328  	return nil
   329  }