github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/api/inventory/inventory_models/current_user.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package inventory_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  // CurrentUser current user
    18  //
    19  // swagger:model current_user
    20  type CurrentUser struct {
    21  
    22  	// email
    23  	Email string `json:"email,omitempty"`
    24  
    25  	// is activator
    26  	IsActivator bool `json:"is_activator,omitempty"`
    27  
    28  	// is anonymous
    29  	IsAnonymous bool `json:"is_anonymous,omitempty"`
    30  
    31  	// is superuser
    32  	IsSuperuser bool `json:"is_superuser,omitempty"`
    33  
    34  	// is superuser readonly
    35  	IsSuperuserReadonly bool `json:"is_superuser_readonly,omitempty"`
    36  
    37  	// name
    38  	Name string `json:"name,omitempty"`
    39  
    40  	// organizations
    41  	Organizations []*Organization `json:"organizations"`
    42  
    43  	// user id
    44  	UserID string `json:"user_id,omitempty"`
    45  }
    46  
    47  // Validate validates this current user
    48  func (m *CurrentUser) Validate(formats strfmt.Registry) error {
    49  	var res []error
    50  
    51  	if err := m.validateOrganizations(formats); err != nil {
    52  		res = append(res, err)
    53  	}
    54  
    55  	if len(res) > 0 {
    56  		return errors.CompositeValidationError(res...)
    57  	}
    58  	return nil
    59  }
    60  
    61  func (m *CurrentUser) validateOrganizations(formats strfmt.Registry) error {
    62  	if swag.IsZero(m.Organizations) { // not required
    63  		return nil
    64  	}
    65  
    66  	for i := 0; i < len(m.Organizations); i++ {
    67  		if swag.IsZero(m.Organizations[i]) { // not required
    68  			continue
    69  		}
    70  
    71  		if m.Organizations[i] != nil {
    72  			if err := m.Organizations[i].Validate(formats); err != nil {
    73  				if ve, ok := err.(*errors.Validation); ok {
    74  					return ve.ValidateName("organizations" + "." + strconv.Itoa(i))
    75  				}
    76  				return err
    77  			}
    78  		}
    79  
    80  	}
    81  
    82  	return nil
    83  }
    84  
    85  // ContextValidate validate this current user based on the context it is used
    86  func (m *CurrentUser) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    87  	var res []error
    88  
    89  	if err := m.contextValidateOrganizations(ctx, formats); err != nil {
    90  		res = append(res, err)
    91  	}
    92  
    93  	if len(res) > 0 {
    94  		return errors.CompositeValidationError(res...)
    95  	}
    96  	return nil
    97  }
    98  
    99  func (m *CurrentUser) contextValidateOrganizations(ctx context.Context, formats strfmt.Registry) error {
   100  
   101  	for i := 0; i < len(m.Organizations); i++ {
   102  
   103  		if m.Organizations[i] != nil {
   104  			if err := m.Organizations[i].ContextValidate(ctx, formats); err != nil {
   105  				if ve, ok := err.(*errors.Validation); ok {
   106  					return ve.ValidateName("organizations" + "." + strconv.Itoa(i))
   107  				}
   108  				return err
   109  			}
   110  		}
   111  
   112  	}
   113  
   114  	return nil
   115  }
   116  
   117  // MarshalBinary interface implementation
   118  func (m *CurrentUser) MarshalBinary() ([]byte, error) {
   119  	if m == nil {
   120  		return nil, nil
   121  	}
   122  	return swag.WriteJSON(m)
   123  }
   124  
   125  // UnmarshalBinary interface implementation
   126  func (m *CurrentUser) UnmarshalBinary(b []byte) error {
   127  	var res CurrentUser
   128  	if err := swag.ReadJSON(b, &res); err != nil {
   129  		return err
   130  	}
   131  	*m = res
   132  	return nil
   133  }