/
scope.go
106 lines (84 loc) · 2.47 KB
/
scope.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Code generated by go-swagger; DO NOT EDIT.
package dynatrace
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
"github.com/go-openapi/errors"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// Scope The scope of the maintenance window.
//
// The scope restricts the alert/problem detection suppression to certain Dynatrace entities. It can contain a list of entities and/or matching rules for dynamic formation of the scope.
//
// If no scope is specified, the alert/problem detection suppression applies to the entire environment.
// swagger:model Scope
type Scope struct {
// A list of Dynatrace entities (for example, hosts or services) to be included in the scope.
//
// Allowed values are Dynatrace entity IDs.
// Required: true
Entities []string `json:"entities"`
// A list of matching rules for dynamic scope formation.
//
// If several rules are set, the OR logic applies.
// Required: true
Matches []*MonitoredEntityFilter `json:"matches"`
}
// Validate validates this scope
func (m *Scope) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateEntities(formats); err != nil {
res = append(res, err)
}
if err := m.validateMatches(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *Scope) validateEntities(formats strfmt.Registry) error {
if err := validate.Required("entities", "body", m.Entities); err != nil {
return err
}
return nil
}
func (m *Scope) validateMatches(formats strfmt.Registry) error {
if err := validate.Required("matches", "body", m.Matches); err != nil {
return err
}
for i := 0; i < len(m.Matches); i++ {
if swag.IsZero(m.Matches[i]) { // not required
continue
}
if m.Matches[i] != nil {
if err := m.Matches[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("matches" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *Scope) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *Scope) UnmarshalBinary(b []byte) error {
var res Scope
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}