github.com/minio/console@v1.4.1/models/set_policy_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  
    28  	"github.com/go-openapi/errors"
    29  	"github.com/go-openapi/strfmt"
    30  	"github.com/go-openapi/swag"
    31  	"github.com/go-openapi/validate"
    32  )
    33  
    34  // SetPolicyRequest set policy request
    35  //
    36  // swagger:model setPolicyRequest
    37  type SetPolicyRequest struct {
    38  
    39  	// entity name
    40  	// Required: true
    41  	EntityName *string `json:"entityName"`
    42  
    43  	// entity type
    44  	// Required: true
    45  	EntityType *PolicyEntity `json:"entityType"`
    46  }
    47  
    48  // Validate validates this set policy request
    49  func (m *SetPolicyRequest) Validate(formats strfmt.Registry) error {
    50  	var res []error
    51  
    52  	if err := m.validateEntityName(formats); err != nil {
    53  		res = append(res, err)
    54  	}
    55  
    56  	if err := m.validateEntityType(formats); err != nil {
    57  		res = append(res, err)
    58  	}
    59  
    60  	if len(res) > 0 {
    61  		return errors.CompositeValidationError(res...)
    62  	}
    63  	return nil
    64  }
    65  
    66  func (m *SetPolicyRequest) validateEntityName(formats strfmt.Registry) error {
    67  
    68  	if err := validate.Required("entityName", "body", m.EntityName); err != nil {
    69  		return err
    70  	}
    71  
    72  	return nil
    73  }
    74  
    75  func (m *SetPolicyRequest) validateEntityType(formats strfmt.Registry) error {
    76  
    77  	if err := validate.Required("entityType", "body", m.EntityType); err != nil {
    78  		return err
    79  	}
    80  
    81  	if err := validate.Required("entityType", "body", m.EntityType); err != nil {
    82  		return err
    83  	}
    84  
    85  	if m.EntityType != nil {
    86  		if err := m.EntityType.Validate(formats); err != nil {
    87  			if ve, ok := err.(*errors.Validation); ok {
    88  				return ve.ValidateName("entityType")
    89  			} else if ce, ok := err.(*errors.CompositeError); ok {
    90  				return ce.ValidateName("entityType")
    91  			}
    92  			return err
    93  		}
    94  	}
    95  
    96  	return nil
    97  }
    98  
    99  // ContextValidate validate this set policy request based on the context it is used
   100  func (m *SetPolicyRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   101  	var res []error
   102  
   103  	if err := m.contextValidateEntityType(ctx, formats); err != nil {
   104  		res = append(res, err)
   105  	}
   106  
   107  	if len(res) > 0 {
   108  		return errors.CompositeValidationError(res...)
   109  	}
   110  	return nil
   111  }
   112  
   113  func (m *SetPolicyRequest) contextValidateEntityType(ctx context.Context, formats strfmt.Registry) error {
   114  
   115  	if m.EntityType != nil {
   116  
   117  		if err := m.EntityType.ContextValidate(ctx, formats); err != nil {
   118  			if ve, ok := err.(*errors.Validation); ok {
   119  				return ve.ValidateName("entityType")
   120  			} else if ce, ok := err.(*errors.CompositeError); ok {
   121  				return ce.ValidateName("entityType")
   122  			}
   123  			return err
   124  		}
   125  	}
   126  
   127  	return nil
   128  }
   129  
   130  // MarshalBinary interface implementation
   131  func (m *SetPolicyRequest) MarshalBinary() ([]byte, error) {
   132  	if m == nil {
   133  		return nil, nil
   134  	}
   135  	return swag.WriteJSON(m)
   136  }
   137  
   138  // UnmarshalBinary interface implementation
   139  func (m *SetPolicyRequest) UnmarshalBinary(b []byte) error {
   140  	var res SetPolicyRequest
   141  	if err := swag.ReadJSON(b, &res); err != nil {
   142  		return err
   143  	}
   144  	*m = res
   145  	return nil
   146  }