github.com/digitalocean/go-netbox@v0.0.2/netbox/models/webhook.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  // Copyright 2020 The go-netbox Authors.
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //   http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  //
    17  
    18  package models
    19  
    20  // This file was generated by the swagger tool.
    21  // Editing this file might prove futile when you re-run the swagger generate command
    22  
    23  import (
    24  	"context"
    25  	"encoding/json"
    26  
    27  	"github.com/go-openapi/errors"
    28  	"github.com/go-openapi/strfmt"
    29  	"github.com/go-openapi/swag"
    30  	"github.com/go-openapi/validate"
    31  )
    32  
    33  // Webhook webhook
    34  //
    35  // swagger:model Webhook
    36  type Webhook struct {
    37  
    38  	// Additional headers
    39  	//
    40  	// User-supplied HTTP headers to be sent with the request in addition to the HTTP content type. Headers should be defined in the format <code>Name: Value</code>. Jinja2 template processing is support with the same context as the request body (below).
    41  	AdditionalHeaders string `json:"additional_headers,omitempty"`
    42  
    43  	// Body template
    44  	//
    45  	// Jinja2 template for a custom request body. If blank, a JSON object representing the change will be included. Available context data includes: <code>event</code>, <code>model</code>, <code>timestamp</code>, <code>username</code>, <code>request_id</code>, and <code>data</code>.
    46  	BodyTemplate string `json:"body_template,omitempty"`
    47  
    48  	// CA File Path
    49  	//
    50  	// The specific CA certificate file to use for SSL verification. Leave blank to use the system defaults.
    51  	// Max Length: 4096
    52  	CaFilePath *string `json:"ca_file_path,omitempty"`
    53  
    54  	// content types
    55  	// Required: true
    56  	// Unique: true
    57  	ContentTypes []string `json:"content_types"`
    58  
    59  	// Display
    60  	// Read Only: true
    61  	Display string `json:"display,omitempty"`
    62  
    63  	// Enabled
    64  	Enabled bool `json:"enabled,omitempty"`
    65  
    66  	// HTTP content type
    67  	//
    68  	// The complete list of official content types is available <a href="https://www.iana.org/assignments/media-types/media-types.xhtml">here</a>.
    69  	// Max Length: 100
    70  	// Min Length: 1
    71  	HTTPContentType string `json:"http_content_type,omitempty"`
    72  
    73  	// HTTP method
    74  	// Enum: [GET POST PUT PATCH DELETE]
    75  	HTTPMethod string `json:"http_method,omitempty"`
    76  
    77  	// Id
    78  	// Read Only: true
    79  	ID int64 `json:"id,omitempty"`
    80  
    81  	// Name
    82  	// Required: true
    83  	// Max Length: 150
    84  	// Min Length: 1
    85  	Name *string `json:"name"`
    86  
    87  	// URL
    88  	//
    89  	// A POST will be sent to this URL when the webhook is called.
    90  	// Required: true
    91  	// Max Length: 500
    92  	// Min Length: 1
    93  	PayloadURL *string `json:"payload_url"`
    94  
    95  	// Secret
    96  	//
    97  	// When provided, the request will include a 'X-Hook-Signature' header containing a HMAC hex digest of the payload body using the secret as the key. The secret is not transmitted in the request.
    98  	// Max Length: 255
    99  	Secret string `json:"secret,omitempty"`
   100  
   101  	// SSL verification
   102  	//
   103  	// Enable SSL certificate verification. Disable with caution!
   104  	SslVerification bool `json:"ssl_verification,omitempty"`
   105  
   106  	// Type create
   107  	//
   108  	// Call this webhook when a matching object is created.
   109  	TypeCreate *bool `json:"type_create,omitempty"`
   110  
   111  	// Type delete
   112  	//
   113  	// Call this webhook when a matching object is deleted.
   114  	TypeDelete *bool `json:"type_delete,omitempty"`
   115  
   116  	// Type update
   117  	//
   118  	// Call this webhook when a matching object is updated.
   119  	TypeUpdate *bool `json:"type_update,omitempty"`
   120  
   121  	// Url
   122  	// Read Only: true
   123  	// Format: uri
   124  	URL strfmt.URI `json:"url,omitempty"`
   125  }
   126  
   127  // Validate validates this webhook
   128  func (m *Webhook) Validate(formats strfmt.Registry) error {
   129  	var res []error
   130  
   131  	if err := m.validateCaFilePath(formats); err != nil {
   132  		res = append(res, err)
   133  	}
   134  
   135  	if err := m.validateContentTypes(formats); err != nil {
   136  		res = append(res, err)
   137  	}
   138  
   139  	if err := m.validateHTTPContentType(formats); err != nil {
   140  		res = append(res, err)
   141  	}
   142  
   143  	if err := m.validateHTTPMethod(formats); err != nil {
   144  		res = append(res, err)
   145  	}
   146  
   147  	if err := m.validateName(formats); err != nil {
   148  		res = append(res, err)
   149  	}
   150  
   151  	if err := m.validatePayloadURL(formats); err != nil {
   152  		res = append(res, err)
   153  	}
   154  
   155  	if err := m.validateSecret(formats); err != nil {
   156  		res = append(res, err)
   157  	}
   158  
   159  	if err := m.validateURL(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 *Webhook) validateCaFilePath(formats strfmt.Registry) error {
   170  	if swag.IsZero(m.CaFilePath) { // not required
   171  		return nil
   172  	}
   173  
   174  	if err := validate.MaxLength("ca_file_path", "body", *m.CaFilePath, 4096); err != nil {
   175  		return err
   176  	}
   177  
   178  	return nil
   179  }
   180  
   181  func (m *Webhook) validateContentTypes(formats strfmt.Registry) error {
   182  
   183  	if err := validate.Required("content_types", "body", m.ContentTypes); err != nil {
   184  		return err
   185  	}
   186  
   187  	if err := validate.UniqueItems("content_types", "body", m.ContentTypes); err != nil {
   188  		return err
   189  	}
   190  
   191  	return nil
   192  }
   193  
   194  func (m *Webhook) validateHTTPContentType(formats strfmt.Registry) error {
   195  	if swag.IsZero(m.HTTPContentType) { // not required
   196  		return nil
   197  	}
   198  
   199  	if err := validate.MinLength("http_content_type", "body", m.HTTPContentType, 1); err != nil {
   200  		return err
   201  	}
   202  
   203  	if err := validate.MaxLength("http_content_type", "body", m.HTTPContentType, 100); err != nil {
   204  		return err
   205  	}
   206  
   207  	return nil
   208  }
   209  
   210  var webhookTypeHTTPMethodPropEnum []interface{}
   211  
   212  func init() {
   213  	var res []string
   214  	if err := json.Unmarshal([]byte(`["GET","POST","PUT","PATCH","DELETE"]`), &res); err != nil {
   215  		panic(err)
   216  	}
   217  	for _, v := range res {
   218  		webhookTypeHTTPMethodPropEnum = append(webhookTypeHTTPMethodPropEnum, v)
   219  	}
   220  }
   221  
   222  const (
   223  
   224  	// WebhookHTTPMethodGET captures enum value "GET"
   225  	WebhookHTTPMethodGET string = "GET"
   226  
   227  	// WebhookHTTPMethodPOST captures enum value "POST"
   228  	WebhookHTTPMethodPOST string = "POST"
   229  
   230  	// WebhookHTTPMethodPUT captures enum value "PUT"
   231  	WebhookHTTPMethodPUT string = "PUT"
   232  
   233  	// WebhookHTTPMethodPATCH captures enum value "PATCH"
   234  	WebhookHTTPMethodPATCH string = "PATCH"
   235  
   236  	// WebhookHTTPMethodDELETE captures enum value "DELETE"
   237  	WebhookHTTPMethodDELETE string = "DELETE"
   238  )
   239  
   240  // prop value enum
   241  func (m *Webhook) validateHTTPMethodEnum(path, location string, value string) error {
   242  	if err := validate.EnumCase(path, location, value, webhookTypeHTTPMethodPropEnum, true); err != nil {
   243  		return err
   244  	}
   245  	return nil
   246  }
   247  
   248  func (m *Webhook) validateHTTPMethod(formats strfmt.Registry) error {
   249  	if swag.IsZero(m.HTTPMethod) { // not required
   250  		return nil
   251  	}
   252  
   253  	// value enum
   254  	if err := m.validateHTTPMethodEnum("http_method", "body", m.HTTPMethod); err != nil {
   255  		return err
   256  	}
   257  
   258  	return nil
   259  }
   260  
   261  func (m *Webhook) validateName(formats strfmt.Registry) error {
   262  
   263  	if err := validate.Required("name", "body", m.Name); err != nil {
   264  		return err
   265  	}
   266  
   267  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   268  		return err
   269  	}
   270  
   271  	if err := validate.MaxLength("name", "body", *m.Name, 150); err != nil {
   272  		return err
   273  	}
   274  
   275  	return nil
   276  }
   277  
   278  func (m *Webhook) validatePayloadURL(formats strfmt.Registry) error {
   279  
   280  	if err := validate.Required("payload_url", "body", m.PayloadURL); err != nil {
   281  		return err
   282  	}
   283  
   284  	if err := validate.MinLength("payload_url", "body", *m.PayloadURL, 1); err != nil {
   285  		return err
   286  	}
   287  
   288  	if err := validate.MaxLength("payload_url", "body", *m.PayloadURL, 500); err != nil {
   289  		return err
   290  	}
   291  
   292  	return nil
   293  }
   294  
   295  func (m *Webhook) validateSecret(formats strfmt.Registry) error {
   296  	if swag.IsZero(m.Secret) { // not required
   297  		return nil
   298  	}
   299  
   300  	if err := validate.MaxLength("secret", "body", m.Secret, 255); err != nil {
   301  		return err
   302  	}
   303  
   304  	return nil
   305  }
   306  
   307  func (m *Webhook) validateURL(formats strfmt.Registry) error {
   308  	if swag.IsZero(m.URL) { // not required
   309  		return nil
   310  	}
   311  
   312  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   313  		return err
   314  	}
   315  
   316  	return nil
   317  }
   318  
   319  // ContextValidate validate this webhook based on the context it is used
   320  func (m *Webhook) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   321  	var res []error
   322  
   323  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   324  		res = append(res, err)
   325  	}
   326  
   327  	if err := m.contextValidateID(ctx, formats); err != nil {
   328  		res = append(res, err)
   329  	}
   330  
   331  	if err := m.contextValidateURL(ctx, formats); err != nil {
   332  		res = append(res, err)
   333  	}
   334  
   335  	if len(res) > 0 {
   336  		return errors.CompositeValidationError(res...)
   337  	}
   338  	return nil
   339  }
   340  
   341  func (m *Webhook) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   342  
   343  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   344  		return err
   345  	}
   346  
   347  	return nil
   348  }
   349  
   350  func (m *Webhook) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   351  
   352  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   353  		return err
   354  	}
   355  
   356  	return nil
   357  }
   358  
   359  func (m *Webhook) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   360  
   361  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   362  		return err
   363  	}
   364  
   365  	return nil
   366  }
   367  
   368  // MarshalBinary interface implementation
   369  func (m *Webhook) MarshalBinary() ([]byte, error) {
   370  	if m == nil {
   371  		return nil, nil
   372  	}
   373  	return swag.WriteJSON(m)
   374  }
   375  
   376  // UnmarshalBinary interface implementation
   377  func (m *Webhook) UnmarshalBinary(b []byte) error {
   378  	var res Webhook
   379  	if err := swag.ReadJSON(b, &res); err != nil {
   380  		return err
   381  	}
   382  	*m = res
   383  	return nil
   384  }