github.com/goharbor/go-client@v0.210.0/pkg/sdk/v2.0/models/robot_permission.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  )
    16  
    17  // RobotPermission robot permission
    18  //
    19  // swagger:model RobotPermission
    20  type RobotPermission struct {
    21  
    22  	// access
    23  	Access []*Access `json:"access"`
    24  
    25  	// The kind of the permission
    26  	Kind string `json:"kind,omitempty"`
    27  
    28  	// The namespace of the permission
    29  	Namespace string `json:"namespace,omitempty"`
    30  }
    31  
    32  // Validate validates this robot permission
    33  func (m *RobotPermission) Validate(formats strfmt.Registry) error {
    34  	var res []error
    35  
    36  	if err := m.validateAccess(formats); err != nil {
    37  		res = append(res, err)
    38  	}
    39  
    40  	if len(res) > 0 {
    41  		return errors.CompositeValidationError(res...)
    42  	}
    43  	return nil
    44  }
    45  
    46  func (m *RobotPermission) validateAccess(formats strfmt.Registry) error {
    47  	if swag.IsZero(m.Access) { // not required
    48  		return nil
    49  	}
    50  
    51  	for i := 0; i < len(m.Access); i++ {
    52  		if swag.IsZero(m.Access[i]) { // not required
    53  			continue
    54  		}
    55  
    56  		if m.Access[i] != nil {
    57  			if err := m.Access[i].Validate(formats); err != nil {
    58  				if ve, ok := err.(*errors.Validation); ok {
    59  					return ve.ValidateName("access" + "." + strconv.Itoa(i))
    60  				} else if ce, ok := err.(*errors.CompositeError); ok {
    61  					return ce.ValidateName("access" + "." + strconv.Itoa(i))
    62  				}
    63  				return err
    64  			}
    65  		}
    66  
    67  	}
    68  
    69  	return nil
    70  }
    71  
    72  // ContextValidate validate this robot permission based on the context it is used
    73  func (m *RobotPermission) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    74  	var res []error
    75  
    76  	if err := m.contextValidateAccess(ctx, formats); err != nil {
    77  		res = append(res, err)
    78  	}
    79  
    80  	if len(res) > 0 {
    81  		return errors.CompositeValidationError(res...)
    82  	}
    83  	return nil
    84  }
    85  
    86  func (m *RobotPermission) contextValidateAccess(ctx context.Context, formats strfmt.Registry) error {
    87  
    88  	for i := 0; i < len(m.Access); i++ {
    89  
    90  		if m.Access[i] != nil {
    91  			if err := m.Access[i].ContextValidate(ctx, formats); err != nil {
    92  				if ve, ok := err.(*errors.Validation); ok {
    93  					return ve.ValidateName("access" + "." + strconv.Itoa(i))
    94  				} else if ce, ok := err.(*errors.CompositeError); ok {
    95  					return ce.ValidateName("access" + "." + strconv.Itoa(i))
    96  				}
    97  				return err
    98  			}
    99  		}
   100  
   101  	}
   102  
   103  	return nil
   104  }
   105  
   106  // MarshalBinary interface implementation
   107  func (m *RobotPermission) MarshalBinary() ([]byte, error) {
   108  	if m == nil {
   109  		return nil, nil
   110  	}
   111  	return swag.WriteJSON(m)
   112  }
   113  
   114  // UnmarshalBinary interface implementation
   115  func (m *RobotPermission) UnmarshalBinary(b []byte) error {
   116  	var res RobotPermission
   117  	if err := swag.ReadJSON(b, &res); err != nil {
   118  		return err
   119  	}
   120  	*m = res
   121  	return nil
   122  }