...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package silence
18
19
20
21
22 import (
23 "io"
24 "net/http"
25
26 "github.com/go-openapi/errors"
27 "github.com/go-openapi/runtime"
28 "github.com/go-openapi/runtime/middleware"
29 "github.com/go-openapi/validate"
30
31 "github.com/prometheus/alertmanager/api/v2/models"
32 )
33
34
35
36
37 func NewPostSilencesParams() PostSilencesParams {
38
39 return PostSilencesParams{}
40 }
41
42
43
44
45
46 type PostSilencesParams struct {
47
48
49 HTTPRequest *http.Request `json:"-"`
50
51
55 Silence *models.PostableSilence
56 }
57
58
59
60
61
62 func (o *PostSilencesParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
63 var res []error
64
65 o.HTTPRequest = r
66
67 if runtime.HasBody(r) {
68 defer r.Body.Close()
69 var body models.PostableSilence
70 if err := route.Consumer.Consume(r.Body, &body); err != nil {
71 if err == io.EOF {
72 res = append(res, errors.Required("silence", "body", ""))
73 } else {
74 res = append(res, errors.NewParseError("silence", "body", "", err))
75 }
76 } else {
77
78 if err := body.Validate(route.Formats); err != nil {
79 res = append(res, err)
80 }
81
82 ctx := validate.WithOperationRequest(r.Context())
83 if err := body.ContextValidate(ctx, route.Formats); err != nil {
84 res = append(res, err)
85 }
86
87 if len(res) == 0 {
88 o.Silence = &body
89 }
90 }
91 } else {
92 res = append(res, errors.Required("silence", "body", ""))
93 }
94 if len(res) > 0 {
95 return errors.CompositeValidationError(res...)
96 }
97 return nil
98 }
99
View as plain text