github.com/minio/console@v1.4.1/models/session_response.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  	"encoding/json"
    28  	"strconv"
    29  
    30  	"github.com/go-openapi/errors"
    31  	"github.com/go-openapi/strfmt"
    32  	"github.com/go-openapi/swag"
    33  	"github.com/go-openapi/validate"
    34  )
    35  
    36  // SessionResponse session response
    37  //
    38  // swagger:model sessionResponse
    39  type SessionResponse struct {
    40  
    41  	// allow resources
    42  	AllowResources []*PermissionResource `json:"allowResources"`
    43  
    44  	// custom styles
    45  	CustomStyles string `json:"customStyles,omitempty"`
    46  
    47  	// distributed mode
    48  	DistributedMode bool `json:"distributedMode,omitempty"`
    49  
    50  	// env constants
    51  	EnvConstants *EnvironmentConstants `json:"envConstants,omitempty"`
    52  
    53  	// features
    54  	Features []string `json:"features"`
    55  
    56  	// operator
    57  	Operator bool `json:"operator,omitempty"`
    58  
    59  	// permissions
    60  	Permissions map[string][]string `json:"permissions,omitempty"`
    61  
    62  	// server end point
    63  	ServerEndPoint string `json:"serverEndPoint,omitempty"`
    64  
    65  	// status
    66  	// Enum: [ok]
    67  	Status string `json:"status,omitempty"`
    68  }
    69  
    70  // Validate validates this session response
    71  func (m *SessionResponse) Validate(formats strfmt.Registry) error {
    72  	var res []error
    73  
    74  	if err := m.validateAllowResources(formats); err != nil {
    75  		res = append(res, err)
    76  	}
    77  
    78  	if err := m.validateEnvConstants(formats); err != nil {
    79  		res = append(res, err)
    80  	}
    81  
    82  	if err := m.validateStatus(formats); err != nil {
    83  		res = append(res, err)
    84  	}
    85  
    86  	if len(res) > 0 {
    87  		return errors.CompositeValidationError(res...)
    88  	}
    89  	return nil
    90  }
    91  
    92  func (m *SessionResponse) validateAllowResources(formats strfmt.Registry) error {
    93  	if swag.IsZero(m.AllowResources) { // not required
    94  		return nil
    95  	}
    96  
    97  	for i := 0; i < len(m.AllowResources); i++ {
    98  		if swag.IsZero(m.AllowResources[i]) { // not required
    99  			continue
   100  		}
   101  
   102  		if m.AllowResources[i] != nil {
   103  			if err := m.AllowResources[i].Validate(formats); err != nil {
   104  				if ve, ok := err.(*errors.Validation); ok {
   105  					return ve.ValidateName("allowResources" + "." + strconv.Itoa(i))
   106  				} else if ce, ok := err.(*errors.CompositeError); ok {
   107  					return ce.ValidateName("allowResources" + "." + strconv.Itoa(i))
   108  				}
   109  				return err
   110  			}
   111  		}
   112  
   113  	}
   114  
   115  	return nil
   116  }
   117  
   118  func (m *SessionResponse) validateEnvConstants(formats strfmt.Registry) error {
   119  	if swag.IsZero(m.EnvConstants) { // not required
   120  		return nil
   121  	}
   122  
   123  	if m.EnvConstants != nil {
   124  		if err := m.EnvConstants.Validate(formats); err != nil {
   125  			if ve, ok := err.(*errors.Validation); ok {
   126  				return ve.ValidateName("envConstants")
   127  			} else if ce, ok := err.(*errors.CompositeError); ok {
   128  				return ce.ValidateName("envConstants")
   129  			}
   130  			return err
   131  		}
   132  	}
   133  
   134  	return nil
   135  }
   136  
   137  var sessionResponseTypeStatusPropEnum []interface{}
   138  
   139  func init() {
   140  	var res []string
   141  	if err := json.Unmarshal([]byte(`["ok"]`), &res); err != nil {
   142  		panic(err)
   143  	}
   144  	for _, v := range res {
   145  		sessionResponseTypeStatusPropEnum = append(sessionResponseTypeStatusPropEnum, v)
   146  	}
   147  }
   148  
   149  const (
   150  
   151  	// SessionResponseStatusOk captures enum value "ok"
   152  	SessionResponseStatusOk string = "ok"
   153  )
   154  
   155  // prop value enum
   156  func (m *SessionResponse) validateStatusEnum(path, location string, value string) error {
   157  	if err := validate.EnumCase(path, location, value, sessionResponseTypeStatusPropEnum, true); err != nil {
   158  		return err
   159  	}
   160  	return nil
   161  }
   162  
   163  func (m *SessionResponse) validateStatus(formats strfmt.Registry) error {
   164  	if swag.IsZero(m.Status) { // not required
   165  		return nil
   166  	}
   167  
   168  	// value enum
   169  	if err := m.validateStatusEnum("status", "body", m.Status); err != nil {
   170  		return err
   171  	}
   172  
   173  	return nil
   174  }
   175  
   176  // ContextValidate validate this session response based on the context it is used
   177  func (m *SessionResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   178  	var res []error
   179  
   180  	if err := m.contextValidateAllowResources(ctx, formats); err != nil {
   181  		res = append(res, err)
   182  	}
   183  
   184  	if err := m.contextValidateEnvConstants(ctx, formats); err != nil {
   185  		res = append(res, err)
   186  	}
   187  
   188  	if len(res) > 0 {
   189  		return errors.CompositeValidationError(res...)
   190  	}
   191  	return nil
   192  }
   193  
   194  func (m *SessionResponse) contextValidateAllowResources(ctx context.Context, formats strfmt.Registry) error {
   195  
   196  	for i := 0; i < len(m.AllowResources); i++ {
   197  
   198  		if m.AllowResources[i] != nil {
   199  
   200  			if swag.IsZero(m.AllowResources[i]) { // not required
   201  				return nil
   202  			}
   203  
   204  			if err := m.AllowResources[i].ContextValidate(ctx, formats); err != nil {
   205  				if ve, ok := err.(*errors.Validation); ok {
   206  					return ve.ValidateName("allowResources" + "." + strconv.Itoa(i))
   207  				} else if ce, ok := err.(*errors.CompositeError); ok {
   208  					return ce.ValidateName("allowResources" + "." + strconv.Itoa(i))
   209  				}
   210  				return err
   211  			}
   212  		}
   213  
   214  	}
   215  
   216  	return nil
   217  }
   218  
   219  func (m *SessionResponse) contextValidateEnvConstants(ctx context.Context, formats strfmt.Registry) error {
   220  
   221  	if m.EnvConstants != nil {
   222  
   223  		if swag.IsZero(m.EnvConstants) { // not required
   224  			return nil
   225  		}
   226  
   227  		if err := m.EnvConstants.ContextValidate(ctx, formats); err != nil {
   228  			if ve, ok := err.(*errors.Validation); ok {
   229  				return ve.ValidateName("envConstants")
   230  			} else if ce, ok := err.(*errors.CompositeError); ok {
   231  				return ce.ValidateName("envConstants")
   232  			}
   233  			return err
   234  		}
   235  	}
   236  
   237  	return nil
   238  }
   239  
   240  // MarshalBinary interface implementation
   241  func (m *SessionResponse) MarshalBinary() ([]byte, error) {
   242  	if m == nil {
   243  		return nil, nil
   244  	}
   245  	return swag.WriteJSON(m)
   246  }
   247  
   248  // UnmarshalBinary interface implementation
   249  func (m *SessionResponse) UnmarshalBinary(b []byte) error {
   250  	var res SessionResponse
   251  	if err := swag.ReadJSON(b, &res); err != nil {
   252  		return err
   253  	}
   254  	*m = res
   255  	return nil
   256  }