github.com/minio/console@v1.4.1/models/login_details.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  // LoginDetails login details
    37  //
    38  // swagger:model loginDetails
    39  type LoginDetails struct {
    40  
    41  	// animated login
    42  	AnimatedLogin bool `json:"animatedLogin,omitempty"`
    43  
    44  	// is k8 s
    45  	IsK8S bool `json:"isK8S,omitempty"`
    46  
    47  	// login strategy
    48  	// Enum: [form redirect service-account redirect-service-account]
    49  	LoginStrategy string `json:"loginStrategy,omitempty"`
    50  
    51  	// redirect rules
    52  	RedirectRules []*RedirectRule `json:"redirectRules"`
    53  }
    54  
    55  // Validate validates this login details
    56  func (m *LoginDetails) Validate(formats strfmt.Registry) error {
    57  	var res []error
    58  
    59  	if err := m.validateLoginStrategy(formats); err != nil {
    60  		res = append(res, err)
    61  	}
    62  
    63  	if err := m.validateRedirectRules(formats); err != nil {
    64  		res = append(res, err)
    65  	}
    66  
    67  	if len(res) > 0 {
    68  		return errors.CompositeValidationError(res...)
    69  	}
    70  	return nil
    71  }
    72  
    73  var loginDetailsTypeLoginStrategyPropEnum []interface{}
    74  
    75  func init() {
    76  	var res []string
    77  	if err := json.Unmarshal([]byte(`["form","redirect","service-account","redirect-service-account"]`), &res); err != nil {
    78  		panic(err)
    79  	}
    80  	for _, v := range res {
    81  		loginDetailsTypeLoginStrategyPropEnum = append(loginDetailsTypeLoginStrategyPropEnum, v)
    82  	}
    83  }
    84  
    85  const (
    86  
    87  	// LoginDetailsLoginStrategyForm captures enum value "form"
    88  	LoginDetailsLoginStrategyForm string = "form"
    89  
    90  	// LoginDetailsLoginStrategyRedirect captures enum value "redirect"
    91  	LoginDetailsLoginStrategyRedirect string = "redirect"
    92  
    93  	// LoginDetailsLoginStrategyServiceDashAccount captures enum value "service-account"
    94  	LoginDetailsLoginStrategyServiceDashAccount string = "service-account"
    95  
    96  	// LoginDetailsLoginStrategyRedirectDashServiceDashAccount captures enum value "redirect-service-account"
    97  	LoginDetailsLoginStrategyRedirectDashServiceDashAccount string = "redirect-service-account"
    98  )
    99  
   100  // prop value enum
   101  func (m *LoginDetails) validateLoginStrategyEnum(path, location string, value string) error {
   102  	if err := validate.EnumCase(path, location, value, loginDetailsTypeLoginStrategyPropEnum, true); err != nil {
   103  		return err
   104  	}
   105  	return nil
   106  }
   107  
   108  func (m *LoginDetails) validateLoginStrategy(formats strfmt.Registry) error {
   109  	if swag.IsZero(m.LoginStrategy) { // not required
   110  		return nil
   111  	}
   112  
   113  	// value enum
   114  	if err := m.validateLoginStrategyEnum("loginStrategy", "body", m.LoginStrategy); err != nil {
   115  		return err
   116  	}
   117  
   118  	return nil
   119  }
   120  
   121  func (m *LoginDetails) validateRedirectRules(formats strfmt.Registry) error {
   122  	if swag.IsZero(m.RedirectRules) { // not required
   123  		return nil
   124  	}
   125  
   126  	for i := 0; i < len(m.RedirectRules); i++ {
   127  		if swag.IsZero(m.RedirectRules[i]) { // not required
   128  			continue
   129  		}
   130  
   131  		if m.RedirectRules[i] != nil {
   132  			if err := m.RedirectRules[i].Validate(formats); err != nil {
   133  				if ve, ok := err.(*errors.Validation); ok {
   134  					return ve.ValidateName("redirectRules" + "." + strconv.Itoa(i))
   135  				} else if ce, ok := err.(*errors.CompositeError); ok {
   136  					return ce.ValidateName("redirectRules" + "." + strconv.Itoa(i))
   137  				}
   138  				return err
   139  			}
   140  		}
   141  
   142  	}
   143  
   144  	return nil
   145  }
   146  
   147  // ContextValidate validate this login details based on the context it is used
   148  func (m *LoginDetails) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   149  	var res []error
   150  
   151  	if err := m.contextValidateRedirectRules(ctx, formats); err != nil {
   152  		res = append(res, err)
   153  	}
   154  
   155  	if len(res) > 0 {
   156  		return errors.CompositeValidationError(res...)
   157  	}
   158  	return nil
   159  }
   160  
   161  func (m *LoginDetails) contextValidateRedirectRules(ctx context.Context, formats strfmt.Registry) error {
   162  
   163  	for i := 0; i < len(m.RedirectRules); i++ {
   164  
   165  		if m.RedirectRules[i] != nil {
   166  
   167  			if swag.IsZero(m.RedirectRules[i]) { // not required
   168  				return nil
   169  			}
   170  
   171  			if err := m.RedirectRules[i].ContextValidate(ctx, formats); err != nil {
   172  				if ve, ok := err.(*errors.Validation); ok {
   173  					return ve.ValidateName("redirectRules" + "." + strconv.Itoa(i))
   174  				} else if ce, ok := err.(*errors.CompositeError); ok {
   175  					return ce.ValidateName("redirectRules" + "." + strconv.Itoa(i))
   176  				}
   177  				return err
   178  			}
   179  		}
   180  
   181  	}
   182  
   183  	return nil
   184  }
   185  
   186  // MarshalBinary interface implementation
   187  func (m *LoginDetails) MarshalBinary() ([]byte, error) {
   188  	if m == nil {
   189  		return nil, nil
   190  	}
   191  	return swag.WriteJSON(m)
   192  }
   193  
   194  // UnmarshalBinary interface implementation
   195  func (m *LoginDetails) UnmarshalBinary(b []byte) error {
   196  	var res LoginDetails
   197  	if err := swag.ReadJSON(b, &res); err != nil {
   198  		return err
   199  	}
   200  	*m = res
   201  	return nil
   202  }