...

Source file src/github.com/prometheus/alertmanager/api/v2/models/alert_group.go

Documentation: github.com/prometheus/alertmanager/api/v2/models

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  // Copyright Prometheus Team
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  // http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package models
    18  
    19  // This file was generated by the swagger tool.
    20  // Editing this file might prove futile when you re-run the swagger generate command
    21  
    22  import (
    23  	"context"
    24  	"strconv"
    25  
    26  	"github.com/go-openapi/errors"
    27  	"github.com/go-openapi/strfmt"
    28  	"github.com/go-openapi/swag"
    29  	"github.com/go-openapi/validate"
    30  )
    31  
    32  // AlertGroup alert group
    33  //
    34  // swagger:model alertGroup
    35  type AlertGroup struct {
    36  
    37  	// alerts
    38  	// Required: true
    39  	Alerts []*GettableAlert `json:"alerts"`
    40  
    41  	// labels
    42  	// Required: true
    43  	Labels LabelSet `json:"labels"`
    44  
    45  	// receiver
    46  	// Required: true
    47  	Receiver *Receiver `json:"receiver"`
    48  }
    49  
    50  // Validate validates this alert group
    51  func (m *AlertGroup) Validate(formats strfmt.Registry) error {
    52  	var res []error
    53  
    54  	if err := m.validateAlerts(formats); err != nil {
    55  		res = append(res, err)
    56  	}
    57  
    58  	if err := m.validateLabels(formats); err != nil {
    59  		res = append(res, err)
    60  	}
    61  
    62  	if err := m.validateReceiver(formats); err != nil {
    63  		res = append(res, err)
    64  	}
    65  
    66  	if len(res) > 0 {
    67  		return errors.CompositeValidationError(res...)
    68  	}
    69  	return nil
    70  }
    71  
    72  func (m *AlertGroup) validateAlerts(formats strfmt.Registry) error {
    73  
    74  	if err := validate.Required("alerts", "body", m.Alerts); err != nil {
    75  		return err
    76  	}
    77  
    78  	for i := 0; i < len(m.Alerts); i++ {
    79  		if swag.IsZero(m.Alerts[i]) { // not required
    80  			continue
    81  		}
    82  
    83  		if m.Alerts[i] != nil {
    84  			if err := m.Alerts[i].Validate(formats); err != nil {
    85  				if ve, ok := err.(*errors.Validation); ok {
    86  					return ve.ValidateName("alerts" + "." + strconv.Itoa(i))
    87  				} else if ce, ok := err.(*errors.CompositeError); ok {
    88  					return ce.ValidateName("alerts" + "." + strconv.Itoa(i))
    89  				}
    90  				return err
    91  			}
    92  		}
    93  
    94  	}
    95  
    96  	return nil
    97  }
    98  
    99  func (m *AlertGroup) validateLabels(formats strfmt.Registry) error {
   100  
   101  	if err := validate.Required("labels", "body", m.Labels); err != nil {
   102  		return err
   103  	}
   104  
   105  	if m.Labels != nil {
   106  		if err := m.Labels.Validate(formats); err != nil {
   107  			if ve, ok := err.(*errors.Validation); ok {
   108  				return ve.ValidateName("labels")
   109  			} else if ce, ok := err.(*errors.CompositeError); ok {
   110  				return ce.ValidateName("labels")
   111  			}
   112  			return err
   113  		}
   114  	}
   115  
   116  	return nil
   117  }
   118  
   119  func (m *AlertGroup) validateReceiver(formats strfmt.Registry) error {
   120  
   121  	if err := validate.Required("receiver", "body", m.Receiver); err != nil {
   122  		return err
   123  	}
   124  
   125  	if m.Receiver != nil {
   126  		if err := m.Receiver.Validate(formats); err != nil {
   127  			if ve, ok := err.(*errors.Validation); ok {
   128  				return ve.ValidateName("receiver")
   129  			} else if ce, ok := err.(*errors.CompositeError); ok {
   130  				return ce.ValidateName("receiver")
   131  			}
   132  			return err
   133  		}
   134  	}
   135  
   136  	return nil
   137  }
   138  
   139  // ContextValidate validate this alert group based on the context it is used
   140  func (m *AlertGroup) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   141  	var res []error
   142  
   143  	if err := m.contextValidateAlerts(ctx, formats); err != nil {
   144  		res = append(res, err)
   145  	}
   146  
   147  	if err := m.contextValidateLabels(ctx, formats); err != nil {
   148  		res = append(res, err)
   149  	}
   150  
   151  	if err := m.contextValidateReceiver(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 *AlertGroup) contextValidateAlerts(ctx context.Context, formats strfmt.Registry) error {
   162  
   163  	for i := 0; i < len(m.Alerts); i++ {
   164  
   165  		if m.Alerts[i] != nil {
   166  			if err := m.Alerts[i].ContextValidate(ctx, formats); err != nil {
   167  				if ve, ok := err.(*errors.Validation); ok {
   168  					return ve.ValidateName("alerts" + "." + strconv.Itoa(i))
   169  				} else if ce, ok := err.(*errors.CompositeError); ok {
   170  					return ce.ValidateName("alerts" + "." + strconv.Itoa(i))
   171  				}
   172  				return err
   173  			}
   174  		}
   175  
   176  	}
   177  
   178  	return nil
   179  }
   180  
   181  func (m *AlertGroup) contextValidateLabels(ctx context.Context, formats strfmt.Registry) error {
   182  
   183  	if err := m.Labels.ContextValidate(ctx, formats); err != nil {
   184  		if ve, ok := err.(*errors.Validation); ok {
   185  			return ve.ValidateName("labels")
   186  		} else if ce, ok := err.(*errors.CompositeError); ok {
   187  			return ce.ValidateName("labels")
   188  		}
   189  		return err
   190  	}
   191  
   192  	return nil
   193  }
   194  
   195  func (m *AlertGroup) contextValidateReceiver(ctx context.Context, formats strfmt.Registry) error {
   196  
   197  	if m.Receiver != nil {
   198  		if err := m.Receiver.ContextValidate(ctx, formats); err != nil {
   199  			if ve, ok := err.(*errors.Validation); ok {
   200  				return ve.ValidateName("receiver")
   201  			} else if ce, ok := err.(*errors.CompositeError); ok {
   202  				return ce.ValidateName("receiver")
   203  			}
   204  			return err
   205  		}
   206  	}
   207  
   208  	return nil
   209  }
   210  
   211  // MarshalBinary interface implementation
   212  func (m *AlertGroup) MarshalBinary() ([]byte, error) {
   213  	if m == nil {
   214  		return nil, nil
   215  	}
   216  	return swag.WriteJSON(m)
   217  }
   218  
   219  // UnmarshalBinary interface implementation
   220  func (m *AlertGroup) UnmarshalBinary(b []byte) error {
   221  	var res AlertGroup
   222  	if err := swag.ReadJSON(b, &res); err != nil {
   223  		return err
   224  	}
   225  	*m = res
   226  	return nil
   227  }
   228  

View as plain text