github.com/goharbor/go-client@v0.210.0/pkg/sdk/v2.0/models/robot_create.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  // RobotCreate The request for robot account creation.
    18  //
    19  // swagger:model RobotCreate
    20  type RobotCreate struct {
    21  
    22  	// The description of the robot
    23  	Description string `json:"description,omitempty"`
    24  
    25  	// The disable status of the robot
    26  	Disable bool `json:"disable,omitempty"`
    27  
    28  	// The duration of the robot in days
    29  	Duration int64 `json:"duration,omitempty"`
    30  
    31  	// The level of the robot, project or system
    32  	Level string `json:"level,omitempty"`
    33  
    34  	// The name of the robot
    35  	Name string `json:"name,omitempty"`
    36  
    37  	// permissions
    38  	Permissions []*RobotPermission `json:"permissions"`
    39  
    40  	// The secret of the robot
    41  	Secret string `json:"secret,omitempty"`
    42  }
    43  
    44  // Validate validates this robot create
    45  func (m *RobotCreate) Validate(formats strfmt.Registry) error {
    46  	var res []error
    47  
    48  	if err := m.validatePermissions(formats); err != nil {
    49  		res = append(res, err)
    50  	}
    51  
    52  	if len(res) > 0 {
    53  		return errors.CompositeValidationError(res...)
    54  	}
    55  	return nil
    56  }
    57  
    58  func (m *RobotCreate) validatePermissions(formats strfmt.Registry) error {
    59  	if swag.IsZero(m.Permissions) { // not required
    60  		return nil
    61  	}
    62  
    63  	for i := 0; i < len(m.Permissions); i++ {
    64  		if swag.IsZero(m.Permissions[i]) { // not required
    65  			continue
    66  		}
    67  
    68  		if m.Permissions[i] != nil {
    69  			if err := m.Permissions[i].Validate(formats); err != nil {
    70  				if ve, ok := err.(*errors.Validation); ok {
    71  					return ve.ValidateName("permissions" + "." + strconv.Itoa(i))
    72  				} else if ce, ok := err.(*errors.CompositeError); ok {
    73  					return ce.ValidateName("permissions" + "." + strconv.Itoa(i))
    74  				}
    75  				return err
    76  			}
    77  		}
    78  
    79  	}
    80  
    81  	return nil
    82  }
    83  
    84  // ContextValidate validate this robot create based on the context it is used
    85  func (m *RobotCreate) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    86  	var res []error
    87  
    88  	if err := m.contextValidatePermissions(ctx, formats); err != nil {
    89  		res = append(res, err)
    90  	}
    91  
    92  	if len(res) > 0 {
    93  		return errors.CompositeValidationError(res...)
    94  	}
    95  	return nil
    96  }
    97  
    98  func (m *RobotCreate) contextValidatePermissions(ctx context.Context, formats strfmt.Registry) error {
    99  
   100  	for i := 0; i < len(m.Permissions); i++ {
   101  
   102  		if m.Permissions[i] != nil {
   103  			if err := m.Permissions[i].ContextValidate(ctx, formats); err != nil {
   104  				if ve, ok := err.(*errors.Validation); ok {
   105  					return ve.ValidateName("permissions" + "." + strconv.Itoa(i))
   106  				} else if ce, ok := err.(*errors.CompositeError); ok {
   107  					return ce.ValidateName("permissions" + "." + strconv.Itoa(i))
   108  				}
   109  				return err
   110  			}
   111  		}
   112  
   113  	}
   114  
   115  	return nil
   116  }
   117  
   118  // MarshalBinary interface implementation
   119  func (m *RobotCreate) MarshalBinary() ([]byte, error) {
   120  	if m == nil {
   121  		return nil, nil
   122  	}
   123  	return swag.WriteJSON(m)
   124  }
   125  
   126  // UnmarshalBinary interface implementation
   127  func (m *RobotCreate) UnmarshalBinary(b []byte) error {
   128  	var res RobotCreate
   129  	if err := swag.ReadJSON(b, &res); err != nil {
   130  		return err
   131  	}
   132  	*m = res
   133  	return nil
   134  }