github.com/minio/console@v1.3.0/models/set_policy_multiple_name_request.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  // This file is part of MinIO Console Server
     4  // Copyright (c) 2023 MinIO, Inc.
     5  //
     6  // This program is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU Affero General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // (at your option) any later version.
    10  //
    11  // This program is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU Affero General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU Affero General Public License
    17  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    18  //
    19  
    20  package models
    21  
    22  // This file was generated by the swagger tool.
    23  // Editing this file might prove futile when you re-run the swagger generate command
    24  
    25  import (
    26  	"context"
    27  	"strconv"
    28  
    29  	"github.com/go-openapi/errors"
    30  	"github.com/go-openapi/strfmt"
    31  	"github.com/go-openapi/swag"
    32  )
    33  
    34  // SetPolicyMultipleNameRequest set policy multiple name request
    35  //
    36  // swagger:model setPolicyMultipleNameRequest
    37  type SetPolicyMultipleNameRequest struct {
    38  
    39  	// groups
    40  	Groups []IamEntity `json:"groups"`
    41  
    42  	// name
    43  	Name []string `json:"name"`
    44  
    45  	// users
    46  	Users []IamEntity `json:"users"`
    47  }
    48  
    49  // Validate validates this set policy multiple name request
    50  func (m *SetPolicyMultipleNameRequest) Validate(formats strfmt.Registry) error {
    51  	var res []error
    52  
    53  	if err := m.validateGroups(formats); err != nil {
    54  		res = append(res, err)
    55  	}
    56  
    57  	if err := m.validateUsers(formats); err != nil {
    58  		res = append(res, err)
    59  	}
    60  
    61  	if len(res) > 0 {
    62  		return errors.CompositeValidationError(res...)
    63  	}
    64  	return nil
    65  }
    66  
    67  func (m *SetPolicyMultipleNameRequest) validateGroups(formats strfmt.Registry) error {
    68  	if swag.IsZero(m.Groups) { // not required
    69  		return nil
    70  	}
    71  
    72  	for i := 0; i < len(m.Groups); i++ {
    73  
    74  		if err := m.Groups[i].Validate(formats); err != nil {
    75  			if ve, ok := err.(*errors.Validation); ok {
    76  				return ve.ValidateName("groups" + "." + strconv.Itoa(i))
    77  			} else if ce, ok := err.(*errors.CompositeError); ok {
    78  				return ce.ValidateName("groups" + "." + strconv.Itoa(i))
    79  			}
    80  			return err
    81  		}
    82  
    83  	}
    84  
    85  	return nil
    86  }
    87  
    88  func (m *SetPolicyMultipleNameRequest) validateUsers(formats strfmt.Registry) error {
    89  	if swag.IsZero(m.Users) { // not required
    90  		return nil
    91  	}
    92  
    93  	for i := 0; i < len(m.Users); i++ {
    94  
    95  		if err := m.Users[i].Validate(formats); err != nil {
    96  			if ve, ok := err.(*errors.Validation); ok {
    97  				return ve.ValidateName("users" + "." + strconv.Itoa(i))
    98  			} else if ce, ok := err.(*errors.CompositeError); ok {
    99  				return ce.ValidateName("users" + "." + strconv.Itoa(i))
   100  			}
   101  			return err
   102  		}
   103  
   104  	}
   105  
   106  	return nil
   107  }
   108  
   109  // ContextValidate validate this set policy multiple name request based on the context it is used
   110  func (m *SetPolicyMultipleNameRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   111  	var res []error
   112  
   113  	if err := m.contextValidateGroups(ctx, formats); err != nil {
   114  		res = append(res, err)
   115  	}
   116  
   117  	if err := m.contextValidateUsers(ctx, formats); err != nil {
   118  		res = append(res, err)
   119  	}
   120  
   121  	if len(res) > 0 {
   122  		return errors.CompositeValidationError(res...)
   123  	}
   124  	return nil
   125  }
   126  
   127  func (m *SetPolicyMultipleNameRequest) contextValidateGroups(ctx context.Context, formats strfmt.Registry) error {
   128  
   129  	for i := 0; i < len(m.Groups); i++ {
   130  
   131  		if swag.IsZero(m.Groups[i]) { // not required
   132  			return nil
   133  		}
   134  
   135  		if err := m.Groups[i].ContextValidate(ctx, formats); err != nil {
   136  			if ve, ok := err.(*errors.Validation); ok {
   137  				return ve.ValidateName("groups" + "." + strconv.Itoa(i))
   138  			} else if ce, ok := err.(*errors.CompositeError); ok {
   139  				return ce.ValidateName("groups" + "." + strconv.Itoa(i))
   140  			}
   141  			return err
   142  		}
   143  
   144  	}
   145  
   146  	return nil
   147  }
   148  
   149  func (m *SetPolicyMultipleNameRequest) contextValidateUsers(ctx context.Context, formats strfmt.Registry) error {
   150  
   151  	for i := 0; i < len(m.Users); i++ {
   152  
   153  		if swag.IsZero(m.Users[i]) { // not required
   154  			return nil
   155  		}
   156  
   157  		if err := m.Users[i].ContextValidate(ctx, formats); err != nil {
   158  			if ve, ok := err.(*errors.Validation); ok {
   159  				return ve.ValidateName("users" + "." + strconv.Itoa(i))
   160  			} else if ce, ok := err.(*errors.CompositeError); ok {
   161  				return ce.ValidateName("users" + "." + strconv.Itoa(i))
   162  			}
   163  			return err
   164  		}
   165  
   166  	}
   167  
   168  	return nil
   169  }
   170  
   171  // MarshalBinary interface implementation
   172  func (m *SetPolicyMultipleNameRequest) MarshalBinary() ([]byte, error) {
   173  	if m == nil {
   174  		return nil, nil
   175  	}
   176  	return swag.WriteJSON(m)
   177  }
   178  
   179  // UnmarshalBinary interface implementation
   180  func (m *SetPolicyMultipleNameRequest) UnmarshalBinary(b []byte) error {
   181  	var res SetPolicyMultipleNameRequest
   182  	if err := swag.ReadJSON(b, &res); err != nil {
   183  		return err
   184  	}
   185  	*m = res
   186  	return nil
   187  }