github.com/goharbor/go-client@v0.210.0/pkg/sdk/v2.0/models/permissions.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 // Permissions permissions 18 // 19 // swagger:model Permissions 20 type Permissions struct { 21 22 // The project level permissions 23 Project []*Permission `json:"project"` 24 25 // The system level permissions 26 System []*Permission `json:"system"` 27 } 28 29 // Validate validates this permissions 30 func (m *Permissions) Validate(formats strfmt.Registry) error { 31 var res []error 32 33 if err := m.validateProject(formats); err != nil { 34 res = append(res, err) 35 } 36 37 if err := m.validateSystem(formats); err != nil { 38 res = append(res, err) 39 } 40 41 if len(res) > 0 { 42 return errors.CompositeValidationError(res...) 43 } 44 return nil 45 } 46 47 func (m *Permissions) validateProject(formats strfmt.Registry) error { 48 if swag.IsZero(m.Project) { // not required 49 return nil 50 } 51 52 for i := 0; i < len(m.Project); i++ { 53 if swag.IsZero(m.Project[i]) { // not required 54 continue 55 } 56 57 if m.Project[i] != nil { 58 if err := m.Project[i].Validate(formats); err != nil { 59 if ve, ok := err.(*errors.Validation); ok { 60 return ve.ValidateName("project" + "." + strconv.Itoa(i)) 61 } else if ce, ok := err.(*errors.CompositeError); ok { 62 return ce.ValidateName("project" + "." + strconv.Itoa(i)) 63 } 64 return err 65 } 66 } 67 68 } 69 70 return nil 71 } 72 73 func (m *Permissions) validateSystem(formats strfmt.Registry) error { 74 if swag.IsZero(m.System) { // not required 75 return nil 76 } 77 78 for i := 0; i < len(m.System); i++ { 79 if swag.IsZero(m.System[i]) { // not required 80 continue 81 } 82 83 if m.System[i] != nil { 84 if err := m.System[i].Validate(formats); err != nil { 85 if ve, ok := err.(*errors.Validation); ok { 86 return ve.ValidateName("system" + "." + strconv.Itoa(i)) 87 } else if ce, ok := err.(*errors.CompositeError); ok { 88 return ce.ValidateName("system" + "." + strconv.Itoa(i)) 89 } 90 return err 91 } 92 } 93 94 } 95 96 return nil 97 } 98 99 // ContextValidate validate this permissions based on the context it is used 100 func (m *Permissions) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 101 var res []error 102 103 if err := m.contextValidateProject(ctx, formats); err != nil { 104 res = append(res, err) 105 } 106 107 if err := m.contextValidateSystem(ctx, formats); err != nil { 108 res = append(res, err) 109 } 110 111 if len(res) > 0 { 112 return errors.CompositeValidationError(res...) 113 } 114 return nil 115 } 116 117 func (m *Permissions) contextValidateProject(ctx context.Context, formats strfmt.Registry) error { 118 119 for i := 0; i < len(m.Project); i++ { 120 121 if m.Project[i] != nil { 122 if err := m.Project[i].ContextValidate(ctx, formats); err != nil { 123 if ve, ok := err.(*errors.Validation); ok { 124 return ve.ValidateName("project" + "." + strconv.Itoa(i)) 125 } else if ce, ok := err.(*errors.CompositeError); ok { 126 return ce.ValidateName("project" + "." + strconv.Itoa(i)) 127 } 128 return err 129 } 130 } 131 132 } 133 134 return nil 135 } 136 137 func (m *Permissions) contextValidateSystem(ctx context.Context, formats strfmt.Registry) error { 138 139 for i := 0; i < len(m.System); i++ { 140 141 if m.System[i] != nil { 142 if err := m.System[i].ContextValidate(ctx, formats); err != nil { 143 if ve, ok := err.(*errors.Validation); ok { 144 return ve.ValidateName("system" + "." + strconv.Itoa(i)) 145 } else if ce, ok := err.(*errors.CompositeError); ok { 146 return ce.ValidateName("system" + "." + strconv.Itoa(i)) 147 } 148 return err 149 } 150 } 151 152 } 153 154 return nil 155 } 156 157 // MarshalBinary interface implementation 158 func (m *Permissions) MarshalBinary() ([]byte, error) { 159 if m == nil { 160 return nil, nil 161 } 162 return swag.WriteJSON(m) 163 } 164 165 // UnmarshalBinary interface implementation 166 func (m *Permissions) UnmarshalBinary(b []byte) error { 167 var res Permissions 168 if err := swag.ReadJSON(b, &res); err != nil { 169 return err 170 } 171 *m = res 172 return nil 173 }