-
Notifications
You must be signed in to change notification settings - Fork 467
/
decision.go
282 lines (268 loc) · 9.82 KB
/
decision.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// Code generated by entc, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent/dialect/sql"
"github.com/crowdsecurity/crowdsec/pkg/database/ent/alert"
"github.com/crowdsecurity/crowdsec/pkg/database/ent/decision"
)
// Decision is the model entity for the Decision schema.
type Decision struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt *time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt *time.Time `json:"updated_at,omitempty"`
// Until holds the value of the "until" field.
Until time.Time `json:"until,omitempty"`
// Scenario holds the value of the "scenario" field.
Scenario string `json:"scenario,omitempty"`
// Type holds the value of the "type" field.
Type string `json:"type,omitempty"`
// StartIP holds the value of the "start_ip" field.
StartIP int64 `json:"start_ip,omitempty"`
// EndIP holds the value of the "end_ip" field.
EndIP int64 `json:"end_ip,omitempty"`
// StartSuffix holds the value of the "start_suffix" field.
StartSuffix int64 `json:"start_suffix,omitempty"`
// EndSuffix holds the value of the "end_suffix" field.
EndSuffix int64 `json:"end_suffix,omitempty"`
// IPSize holds the value of the "ip_size" field.
IPSize int64 `json:"ip_size,omitempty"`
// Scope holds the value of the "scope" field.
Scope string `json:"scope,omitempty"`
// Value holds the value of the "value" field.
Value string `json:"value,omitempty"`
// Origin holds the value of the "origin" field.
Origin string `json:"origin,omitempty"`
// Simulated holds the value of the "simulated" field.
Simulated bool `json:"simulated,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the DecisionQuery when eager-loading is set.
Edges DecisionEdges `json:"edges"`
alert_decisions *int
}
// DecisionEdges holds the relations/edges for other nodes in the graph.
type DecisionEdges struct {
// Owner holds the value of the owner edge.
Owner *Alert `json:"owner,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// OwnerOrErr returns the Owner value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e DecisionEdges) OwnerOrErr() (*Alert, error) {
if e.loadedTypes[0] {
if e.Owner == nil {
// The edge owner was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: alert.Label}
}
return e.Owner, nil
}
return nil, &NotLoadedError{edge: "owner"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Decision) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
case decision.FieldSimulated:
values[i] = new(sql.NullBool)
case decision.FieldID, decision.FieldStartIP, decision.FieldEndIP, decision.FieldStartSuffix, decision.FieldEndSuffix, decision.FieldIPSize:
values[i] = new(sql.NullInt64)
case decision.FieldScenario, decision.FieldType, decision.FieldScope, decision.FieldValue, decision.FieldOrigin:
values[i] = new(sql.NullString)
case decision.FieldCreatedAt, decision.FieldUpdatedAt, decision.FieldUntil:
values[i] = new(sql.NullTime)
case decision.ForeignKeys[0]: // alert_decisions
values[i] = new(sql.NullInt64)
default:
return nil, fmt.Errorf("unexpected column %q for type Decision", columns[i])
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Decision fields.
func (d *Decision) assignValues(columns []string, values []interface{}) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case decision.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
d.ID = int(value.Int64)
case decision.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
d.CreatedAt = new(time.Time)
*d.CreatedAt = value.Time
}
case decision.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
d.UpdatedAt = new(time.Time)
*d.UpdatedAt = value.Time
}
case decision.FieldUntil:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field until", values[i])
} else if value.Valid {
d.Until = value.Time
}
case decision.FieldScenario:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field scenario", values[i])
} else if value.Valid {
d.Scenario = value.String
}
case decision.FieldType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field type", values[i])
} else if value.Valid {
d.Type = value.String
}
case decision.FieldStartIP:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field start_ip", values[i])
} else if value.Valid {
d.StartIP = value.Int64
}
case decision.FieldEndIP:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field end_ip", values[i])
} else if value.Valid {
d.EndIP = value.Int64
}
case decision.FieldStartSuffix:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field start_suffix", values[i])
} else if value.Valid {
d.StartSuffix = value.Int64
}
case decision.FieldEndSuffix:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field end_suffix", values[i])
} else if value.Valid {
d.EndSuffix = value.Int64
}
case decision.FieldIPSize:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field ip_size", values[i])
} else if value.Valid {
d.IPSize = value.Int64
}
case decision.FieldScope:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field scope", values[i])
} else if value.Valid {
d.Scope = value.String
}
case decision.FieldValue:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field value", values[i])
} else if value.Valid {
d.Value = value.String
}
case decision.FieldOrigin:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field origin", values[i])
} else if value.Valid {
d.Origin = value.String
}
case decision.FieldSimulated:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field simulated", values[i])
} else if value.Valid {
d.Simulated = value.Bool
}
case decision.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field alert_decisions", value)
} else if value.Valid {
d.alert_decisions = new(int)
*d.alert_decisions = int(value.Int64)
}
}
}
return nil
}
// QueryOwner queries the "owner" edge of the Decision entity.
func (d *Decision) QueryOwner() *AlertQuery {
return (&DecisionClient{config: d.config}).QueryOwner(d)
}
// Update returns a builder for updating this Decision.
// Note that you need to call Decision.Unwrap() before calling this method if this Decision
// was returned from a transaction, and the transaction was committed or rolled back.
func (d *Decision) Update() *DecisionUpdateOne {
return (&DecisionClient{config: d.config}).UpdateOne(d)
}
// Unwrap unwraps the Decision entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (d *Decision) Unwrap() *Decision {
tx, ok := d.config.driver.(*txDriver)
if !ok {
panic("ent: Decision is not a transactional entity")
}
d.config.driver = tx.drv
return d
}
// String implements the fmt.Stringer.
func (d *Decision) String() string {
var builder strings.Builder
builder.WriteString("Decision(")
builder.WriteString(fmt.Sprintf("id=%v", d.ID))
if v := d.CreatedAt; v != nil {
builder.WriteString(", created_at=")
builder.WriteString(v.Format(time.ANSIC))
}
if v := d.UpdatedAt; v != nil {
builder.WriteString(", updated_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", until=")
builder.WriteString(d.Until.Format(time.ANSIC))
builder.WriteString(", scenario=")
builder.WriteString(d.Scenario)
builder.WriteString(", type=")
builder.WriteString(d.Type)
builder.WriteString(", start_ip=")
builder.WriteString(fmt.Sprintf("%v", d.StartIP))
builder.WriteString(", end_ip=")
builder.WriteString(fmt.Sprintf("%v", d.EndIP))
builder.WriteString(", start_suffix=")
builder.WriteString(fmt.Sprintf("%v", d.StartSuffix))
builder.WriteString(", end_suffix=")
builder.WriteString(fmt.Sprintf("%v", d.EndSuffix))
builder.WriteString(", ip_size=")
builder.WriteString(fmt.Sprintf("%v", d.IPSize))
builder.WriteString(", scope=")
builder.WriteString(d.Scope)
builder.WriteString(", value=")
builder.WriteString(d.Value)
builder.WriteString(", origin=")
builder.WriteString(d.Origin)
builder.WriteString(", simulated=")
builder.WriteString(fmt.Sprintf("%v", d.Simulated))
builder.WriteByte(')')
return builder.String()
}
// Decisions is a parsable slice of Decision.
type Decisions []*Decision
func (d Decisions) config(cfg config) {
for _i := range d {
d[_i].config = cfg
}
}