github.com/minio/console@v1.4.1/models/notification_config.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  	"strconv"
    28  
    29  	"github.com/go-openapi/errors"
    30  	"github.com/go-openapi/strfmt"
    31  	"github.com/go-openapi/swag"
    32  	"github.com/go-openapi/validate"
    33  )
    34  
    35  // NotificationConfig notification config
    36  //
    37  // swagger:model notificationConfig
    38  type NotificationConfig struct {
    39  
    40  	// arn
    41  	// Required: true
    42  	Arn *string `json:"arn"`
    43  
    44  	// filter specific type of event. Defaults to all event (default: '[put,delete,get]')
    45  	Events []NotificationEventType `json:"events"`
    46  
    47  	// id
    48  	ID string `json:"id,omitempty"`
    49  
    50  	// filter event associated to the specified prefix
    51  	Prefix string `json:"prefix,omitempty"`
    52  
    53  	// filter event associated to the specified suffix
    54  	Suffix string `json:"suffix,omitempty"`
    55  }
    56  
    57  // Validate validates this notification config
    58  func (m *NotificationConfig) Validate(formats strfmt.Registry) error {
    59  	var res []error
    60  
    61  	if err := m.validateArn(formats); err != nil {
    62  		res = append(res, err)
    63  	}
    64  
    65  	if err := m.validateEvents(formats); err != nil {
    66  		res = append(res, err)
    67  	}
    68  
    69  	if len(res) > 0 {
    70  		return errors.CompositeValidationError(res...)
    71  	}
    72  	return nil
    73  }
    74  
    75  func (m *NotificationConfig) validateArn(formats strfmt.Registry) error {
    76  
    77  	if err := validate.Required("arn", "body", m.Arn); err != nil {
    78  		return err
    79  	}
    80  
    81  	return nil
    82  }
    83  
    84  func (m *NotificationConfig) validateEvents(formats strfmt.Registry) error {
    85  	if swag.IsZero(m.Events) { // not required
    86  		return nil
    87  	}
    88  
    89  	for i := 0; i < len(m.Events); i++ {
    90  
    91  		if err := m.Events[i].Validate(formats); err != nil {
    92  			if ve, ok := err.(*errors.Validation); ok {
    93  				return ve.ValidateName("events" + "." + strconv.Itoa(i))
    94  			} else if ce, ok := err.(*errors.CompositeError); ok {
    95  				return ce.ValidateName("events" + "." + strconv.Itoa(i))
    96  			}
    97  			return err
    98  		}
    99  
   100  	}
   101  
   102  	return nil
   103  }
   104  
   105  // ContextValidate validate this notification config based on the context it is used
   106  func (m *NotificationConfig) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   107  	var res []error
   108  
   109  	if err := m.contextValidateEvents(ctx, formats); err != nil {
   110  		res = append(res, err)
   111  	}
   112  
   113  	if len(res) > 0 {
   114  		return errors.CompositeValidationError(res...)
   115  	}
   116  	return nil
   117  }
   118  
   119  func (m *NotificationConfig) contextValidateEvents(ctx context.Context, formats strfmt.Registry) error {
   120  
   121  	for i := 0; i < len(m.Events); i++ {
   122  
   123  		if swag.IsZero(m.Events[i]) { // not required
   124  			return nil
   125  		}
   126  
   127  		if err := m.Events[i].ContextValidate(ctx, formats); err != nil {
   128  			if ve, ok := err.(*errors.Validation); ok {
   129  				return ve.ValidateName("events" + "." + strconv.Itoa(i))
   130  			} else if ce, ok := err.(*errors.CompositeError); ok {
   131  				return ce.ValidateName("events" + "." + strconv.Itoa(i))
   132  			}
   133  			return err
   134  		}
   135  
   136  	}
   137  
   138  	return nil
   139  }
   140  
   141  // MarshalBinary interface implementation
   142  func (m *NotificationConfig) MarshalBinary() ([]byte, error) {
   143  	if m == nil {
   144  		return nil, nil
   145  	}
   146  	return swag.WriteJSON(m)
   147  }
   148  
   149  // UnmarshalBinary interface implementation
   150  func (m *NotificationConfig) UnmarshalBinary(b []byte) error {
   151  	var res NotificationConfig
   152  	if err := swag.ReadJSON(b, &res); err != nil {
   153  		return err
   154  	}
   155  	*m = res
   156  	return nil
   157  }