github.com/goharbor/go-client@v0.210.0/pkg/sdk/v2.0/models/robot.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  // Robot robot
    19  //
    20  // swagger:model Robot
    21  type Robot struct {
    22  
    23  	// The creation time of the robot.
    24  	// Format: date-time
    25  	CreationTime strfmt.DateTime `json:"creation_time,omitempty"`
    26  
    27  	// The description of the robot
    28  	Description string `json:"description,omitempty"`
    29  
    30  	// The disable status of the robot
    31  	Disable bool `json:"disable"`
    32  
    33  	// The duration of the robot in days
    34  	Duration int64 `json:"duration,omitempty"`
    35  
    36  	// The editable status of the robot
    37  	Editable bool `json:"editable"`
    38  
    39  	// The expiration date of the robot
    40  	ExpiresAt int64 `json:"expires_at,omitempty"`
    41  
    42  	// The ID of the robot
    43  	ID int64 `json:"id,omitempty"`
    44  
    45  	// The level of the robot, project or system
    46  	Level string `json:"level,omitempty"`
    47  
    48  	// The name of the robot
    49  	Name string `json:"name,omitempty"`
    50  
    51  	// permissions
    52  	Permissions []*RobotPermission `json:"permissions"`
    53  
    54  	// The secret of the robot
    55  	Secret string `json:"secret,omitempty"`
    56  
    57  	// The update time of the robot.
    58  	// Format: date-time
    59  	UpdateTime strfmt.DateTime `json:"update_time,omitempty"`
    60  }
    61  
    62  // Validate validates this robot
    63  func (m *Robot) Validate(formats strfmt.Registry) error {
    64  	var res []error
    65  
    66  	if err := m.validateCreationTime(formats); err != nil {
    67  		res = append(res, err)
    68  	}
    69  
    70  	if err := m.validatePermissions(formats); err != nil {
    71  		res = append(res, err)
    72  	}
    73  
    74  	if err := m.validateUpdateTime(formats); err != nil {
    75  		res = append(res, err)
    76  	}
    77  
    78  	if len(res) > 0 {
    79  		return errors.CompositeValidationError(res...)
    80  	}
    81  	return nil
    82  }
    83  
    84  func (m *Robot) validateCreationTime(formats strfmt.Registry) error {
    85  	if swag.IsZero(m.CreationTime) { // not required
    86  		return nil
    87  	}
    88  
    89  	if err := validate.FormatOf("creation_time", "body", "date-time", m.CreationTime.String(), formats); err != nil {
    90  		return err
    91  	}
    92  
    93  	return nil
    94  }
    95  
    96  func (m *Robot) validatePermissions(formats strfmt.Registry) error {
    97  	if swag.IsZero(m.Permissions) { // not required
    98  		return nil
    99  	}
   100  
   101  	for i := 0; i < len(m.Permissions); i++ {
   102  		if swag.IsZero(m.Permissions[i]) { // not required
   103  			continue
   104  		}
   105  
   106  		if m.Permissions[i] != nil {
   107  			if err := m.Permissions[i].Validate(formats); err != nil {
   108  				if ve, ok := err.(*errors.Validation); ok {
   109  					return ve.ValidateName("permissions" + "." + strconv.Itoa(i))
   110  				} else if ce, ok := err.(*errors.CompositeError); ok {
   111  					return ce.ValidateName("permissions" + "." + strconv.Itoa(i))
   112  				}
   113  				return err
   114  			}
   115  		}
   116  
   117  	}
   118  
   119  	return nil
   120  }
   121  
   122  func (m *Robot) validateUpdateTime(formats strfmt.Registry) error {
   123  	if swag.IsZero(m.UpdateTime) { // not required
   124  		return nil
   125  	}
   126  
   127  	if err := validate.FormatOf("update_time", "body", "date-time", m.UpdateTime.String(), formats); err != nil {
   128  		return err
   129  	}
   130  
   131  	return nil
   132  }
   133  
   134  // ContextValidate validate this robot based on the context it is used
   135  func (m *Robot) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   136  	var res []error
   137  
   138  	if err := m.contextValidatePermissions(ctx, formats); err != nil {
   139  		res = append(res, err)
   140  	}
   141  
   142  	if len(res) > 0 {
   143  		return errors.CompositeValidationError(res...)
   144  	}
   145  	return nil
   146  }
   147  
   148  func (m *Robot) contextValidatePermissions(ctx context.Context, formats strfmt.Registry) error {
   149  
   150  	for i := 0; i < len(m.Permissions); i++ {
   151  
   152  		if m.Permissions[i] != nil {
   153  			if err := m.Permissions[i].ContextValidate(ctx, formats); err != nil {
   154  				if ve, ok := err.(*errors.Validation); ok {
   155  					return ve.ValidateName("permissions" + "." + strconv.Itoa(i))
   156  				} else if ce, ok := err.(*errors.CompositeError); ok {
   157  					return ce.ValidateName("permissions" + "." + strconv.Itoa(i))
   158  				}
   159  				return err
   160  			}
   161  		}
   162  
   163  	}
   164  
   165  	return nil
   166  }
   167  
   168  // MarshalBinary interface implementation
   169  func (m *Robot) MarshalBinary() ([]byte, error) {
   170  	if m == nil {
   171  		return nil, nil
   172  	}
   173  	return swag.WriteJSON(m)
   174  }
   175  
   176  // UnmarshalBinary interface implementation
   177  func (m *Robot) UnmarshalBinary(b []byte) error {
   178  	var res Robot
   179  	if err := swag.ReadJSON(b, &res); err != nil {
   180  		return err
   181  	}
   182  	*m = res
   183  	return nil
   184  }