github.com/hashicorp/hcp-sdk-go@v0.94.0/clients/cloud-log-service/preview/2021-03-30/models/cloudiam_principal.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package 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  
    11  	"github.com/go-openapi/errors"
    12  	"github.com/go-openapi/strfmt"
    13  	"github.com/go-openapi/swag"
    14  )
    15  
    16  // CloudiamPrincipal Principal is the common wrapper for our different types of principals.
    17  //
    18  // swagger:model cloudiamPrincipal
    19  type CloudiamPrincipal struct {
    20  
    21  	// group is a group principal.
    22  	Group *IamGroup `json:"group,omitempty"`
    23  
    24  	// group_ids is a list of IDs of the HCP groups that this principal is a
    25  	// member of.
    26  	GroupIds []string `json:"group_ids"`
    27  
    28  	// id is the identifier for the principal.
    29  	ID string `json:"id,omitempty"`
    30  
    31  	// service is a service principal.
    32  	Service *CloudiamServicePrincipal `json:"service,omitempty"`
    33  
    34  	// type is the type of the principal.
    35  	Type *IamPrincipalType `json:"type,omitempty"`
    36  
    37  	// user is a user principal.
    38  	User *CloudiamUserPrincipal `json:"user,omitempty"`
    39  }
    40  
    41  // Validate validates this cloudiam principal
    42  func (m *CloudiamPrincipal) Validate(formats strfmt.Registry) error {
    43  	var res []error
    44  
    45  	if err := m.validateGroup(formats); err != nil {
    46  		res = append(res, err)
    47  	}
    48  
    49  	if err := m.validateService(formats); err != nil {
    50  		res = append(res, err)
    51  	}
    52  
    53  	if err := m.validateType(formats); err != nil {
    54  		res = append(res, err)
    55  	}
    56  
    57  	if err := m.validateUser(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 *CloudiamPrincipal) validateGroup(formats strfmt.Registry) error {
    68  	if swag.IsZero(m.Group) { // not required
    69  		return nil
    70  	}
    71  
    72  	if m.Group != nil {
    73  		if err := m.Group.Validate(formats); err != nil {
    74  			if ve, ok := err.(*errors.Validation); ok {
    75  				return ve.ValidateName("group")
    76  			} else if ce, ok := err.(*errors.CompositeError); ok {
    77  				return ce.ValidateName("group")
    78  			}
    79  			return err
    80  		}
    81  	}
    82  
    83  	return nil
    84  }
    85  
    86  func (m *CloudiamPrincipal) validateService(formats strfmt.Registry) error {
    87  	if swag.IsZero(m.Service) { // not required
    88  		return nil
    89  	}
    90  
    91  	if m.Service != nil {
    92  		if err := m.Service.Validate(formats); err != nil {
    93  			if ve, ok := err.(*errors.Validation); ok {
    94  				return ve.ValidateName("service")
    95  			} else if ce, ok := err.(*errors.CompositeError); ok {
    96  				return ce.ValidateName("service")
    97  			}
    98  			return err
    99  		}
   100  	}
   101  
   102  	return nil
   103  }
   104  
   105  func (m *CloudiamPrincipal) validateType(formats strfmt.Registry) error {
   106  	if swag.IsZero(m.Type) { // not required
   107  		return nil
   108  	}
   109  
   110  	if m.Type != nil {
   111  		if err := m.Type.Validate(formats); err != nil {
   112  			if ve, ok := err.(*errors.Validation); ok {
   113  				return ve.ValidateName("type")
   114  			} else if ce, ok := err.(*errors.CompositeError); ok {
   115  				return ce.ValidateName("type")
   116  			}
   117  			return err
   118  		}
   119  	}
   120  
   121  	return nil
   122  }
   123  
   124  func (m *CloudiamPrincipal) validateUser(formats strfmt.Registry) error {
   125  	if swag.IsZero(m.User) { // not required
   126  		return nil
   127  	}
   128  
   129  	if m.User != nil {
   130  		if err := m.User.Validate(formats); err != nil {
   131  			if ve, ok := err.(*errors.Validation); ok {
   132  				return ve.ValidateName("user")
   133  			} else if ce, ok := err.(*errors.CompositeError); ok {
   134  				return ce.ValidateName("user")
   135  			}
   136  			return err
   137  		}
   138  	}
   139  
   140  	return nil
   141  }
   142  
   143  // ContextValidate validate this cloudiam principal based on the context it is used
   144  func (m *CloudiamPrincipal) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   145  	var res []error
   146  
   147  	if err := m.contextValidateGroup(ctx, formats); err != nil {
   148  		res = append(res, err)
   149  	}
   150  
   151  	if err := m.contextValidateService(ctx, formats); err != nil {
   152  		res = append(res, err)
   153  	}
   154  
   155  	if err := m.contextValidateType(ctx, formats); err != nil {
   156  		res = append(res, err)
   157  	}
   158  
   159  	if err := m.contextValidateUser(ctx, formats); err != nil {
   160  		res = append(res, err)
   161  	}
   162  
   163  	if len(res) > 0 {
   164  		return errors.CompositeValidationError(res...)
   165  	}
   166  	return nil
   167  }
   168  
   169  func (m *CloudiamPrincipal) contextValidateGroup(ctx context.Context, formats strfmt.Registry) error {
   170  
   171  	if m.Group != nil {
   172  
   173  		if swag.IsZero(m.Group) { // not required
   174  			return nil
   175  		}
   176  
   177  		if err := m.Group.ContextValidate(ctx, formats); err != nil {
   178  			if ve, ok := err.(*errors.Validation); ok {
   179  				return ve.ValidateName("group")
   180  			} else if ce, ok := err.(*errors.CompositeError); ok {
   181  				return ce.ValidateName("group")
   182  			}
   183  			return err
   184  		}
   185  	}
   186  
   187  	return nil
   188  }
   189  
   190  func (m *CloudiamPrincipal) contextValidateService(ctx context.Context, formats strfmt.Registry) error {
   191  
   192  	if m.Service != nil {
   193  
   194  		if swag.IsZero(m.Service) { // not required
   195  			return nil
   196  		}
   197  
   198  		if err := m.Service.ContextValidate(ctx, formats); err != nil {
   199  			if ve, ok := err.(*errors.Validation); ok {
   200  				return ve.ValidateName("service")
   201  			} else if ce, ok := err.(*errors.CompositeError); ok {
   202  				return ce.ValidateName("service")
   203  			}
   204  			return err
   205  		}
   206  	}
   207  
   208  	return nil
   209  }
   210  
   211  func (m *CloudiamPrincipal) contextValidateType(ctx context.Context, formats strfmt.Registry) error {
   212  
   213  	if m.Type != nil {
   214  
   215  		if swag.IsZero(m.Type) { // not required
   216  			return nil
   217  		}
   218  
   219  		if err := m.Type.ContextValidate(ctx, formats); err != nil {
   220  			if ve, ok := err.(*errors.Validation); ok {
   221  				return ve.ValidateName("type")
   222  			} else if ce, ok := err.(*errors.CompositeError); ok {
   223  				return ce.ValidateName("type")
   224  			}
   225  			return err
   226  		}
   227  	}
   228  
   229  	return nil
   230  }
   231  
   232  func (m *CloudiamPrincipal) contextValidateUser(ctx context.Context, formats strfmt.Registry) error {
   233  
   234  	if m.User != nil {
   235  
   236  		if swag.IsZero(m.User) { // not required
   237  			return nil
   238  		}
   239  
   240  		if err := m.User.ContextValidate(ctx, formats); err != nil {
   241  			if ve, ok := err.(*errors.Validation); ok {
   242  				return ve.ValidateName("user")
   243  			} else if ce, ok := err.(*errors.CompositeError); ok {
   244  				return ce.ValidateName("user")
   245  			}
   246  			return err
   247  		}
   248  	}
   249  
   250  	return nil
   251  }
   252  
   253  // MarshalBinary interface implementation
   254  func (m *CloudiamPrincipal) MarshalBinary() ([]byte, error) {
   255  	if m == nil {
   256  		return nil, nil
   257  	}
   258  	return swag.WriteJSON(m)
   259  }
   260  
   261  // UnmarshalBinary interface implementation
   262  func (m *CloudiamPrincipal) UnmarshalBinary(b []byte) error {
   263  	var res CloudiamPrincipal
   264  	if err := swag.ReadJSON(b, &res); err != nil {
   265  		return err
   266  	}
   267  	*m = res
   268  	return nil
   269  }