2022-10-06 12:55:42 +00:00
|
|
|
// Code generated by ent, DO NOT EDIT.
|
2020-11-30 09:37:17 +00:00
|
|
|
|
|
|
|
package ent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2021-03-15 17:46:52 +00:00
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
|
|
"entgo.io/ent/schema/field"
|
2020-11-30 09:37:17 +00:00
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/database/ent/alert"
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/database/ent/decision"
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/database/ent/event"
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/database/ent/machine"
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/database/ent/meta"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AlertCreate is the builder for creating a Alert entity.
|
|
|
|
type AlertCreate struct {
|
|
|
|
config
|
|
|
|
mutation *AlertMutation
|
|
|
|
hooks []Hook
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetCreatedAt sets the "created_at" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetCreatedAt(t time.Time) *AlertCreate {
|
|
|
|
ac.mutation.SetCreatedAt(t)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableCreatedAt(t *time.Time) *AlertCreate {
|
|
|
|
if t != nil {
|
|
|
|
ac.SetCreatedAt(*t)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetUpdatedAt(t time.Time) *AlertCreate {
|
|
|
|
ac.mutation.SetUpdatedAt(t)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableUpdatedAt(t *time.Time) *AlertCreate {
|
|
|
|
if t != nil {
|
|
|
|
ac.SetUpdatedAt(*t)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetScenario sets the "scenario" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetScenario(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetScenario(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetBucketId sets the "bucketId" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetBucketId(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetBucketId(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableBucketId sets the "bucketId" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableBucketId(s *string) *AlertCreate {
|
|
|
|
if s != nil {
|
|
|
|
ac.SetBucketId(*s)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetMessage sets the "message" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetMessage(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetMessage(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableMessage sets the "message" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableMessage(s *string) *AlertCreate {
|
|
|
|
if s != nil {
|
|
|
|
ac.SetMessage(*s)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetEventsCount sets the "eventsCount" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetEventsCount(i int32) *AlertCreate {
|
|
|
|
ac.mutation.SetEventsCount(i)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableEventsCount sets the "eventsCount" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableEventsCount(i *int32) *AlertCreate {
|
|
|
|
if i != nil {
|
|
|
|
ac.SetEventsCount(*i)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetStartedAt sets the "startedAt" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetStartedAt(t time.Time) *AlertCreate {
|
|
|
|
ac.mutation.SetStartedAt(t)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableStartedAt sets the "startedAt" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableStartedAt(t *time.Time) *AlertCreate {
|
|
|
|
if t != nil {
|
|
|
|
ac.SetStartedAt(*t)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetStoppedAt sets the "stoppedAt" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetStoppedAt(t time.Time) *AlertCreate {
|
|
|
|
ac.mutation.SetStoppedAt(t)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableStoppedAt sets the "stoppedAt" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableStoppedAt(t *time.Time) *AlertCreate {
|
|
|
|
if t != nil {
|
|
|
|
ac.SetStoppedAt(*t)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetSourceIp sets the "sourceIp" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetSourceIp(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetSourceIp(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableSourceIp sets the "sourceIp" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableSourceIp(s *string) *AlertCreate {
|
|
|
|
if s != nil {
|
|
|
|
ac.SetSourceIp(*s)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetSourceRange sets the "sourceRange" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetSourceRange(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetSourceRange(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableSourceRange sets the "sourceRange" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableSourceRange(s *string) *AlertCreate {
|
|
|
|
if s != nil {
|
|
|
|
ac.SetSourceRange(*s)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetSourceAsNumber sets the "sourceAsNumber" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetSourceAsNumber(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetSourceAsNumber(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableSourceAsNumber sets the "sourceAsNumber" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableSourceAsNumber(s *string) *AlertCreate {
|
|
|
|
if s != nil {
|
|
|
|
ac.SetSourceAsNumber(*s)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetSourceAsName sets the "sourceAsName" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetSourceAsName(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetSourceAsName(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableSourceAsName sets the "sourceAsName" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableSourceAsName(s *string) *AlertCreate {
|
|
|
|
if s != nil {
|
|
|
|
ac.SetSourceAsName(*s)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetSourceCountry sets the "sourceCountry" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetSourceCountry(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetSourceCountry(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableSourceCountry sets the "sourceCountry" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableSourceCountry(s *string) *AlertCreate {
|
|
|
|
if s != nil {
|
|
|
|
ac.SetSourceCountry(*s)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetSourceLatitude sets the "sourceLatitude" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetSourceLatitude(f float32) *AlertCreate {
|
|
|
|
ac.mutation.SetSourceLatitude(f)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableSourceLatitude sets the "sourceLatitude" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableSourceLatitude(f *float32) *AlertCreate {
|
|
|
|
if f != nil {
|
|
|
|
ac.SetSourceLatitude(*f)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetSourceLongitude sets the "sourceLongitude" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetSourceLongitude(f float32) *AlertCreate {
|
|
|
|
ac.mutation.SetSourceLongitude(f)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableSourceLongitude sets the "sourceLongitude" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableSourceLongitude(f *float32) *AlertCreate {
|
|
|
|
if f != nil {
|
|
|
|
ac.SetSourceLongitude(*f)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetSourceScope sets the "sourceScope" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetSourceScope(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetSourceScope(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableSourceScope sets the "sourceScope" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableSourceScope(s *string) *AlertCreate {
|
|
|
|
if s != nil {
|
|
|
|
ac.SetSourceScope(*s)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetSourceValue sets the "sourceValue" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetSourceValue(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetSourceValue(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableSourceValue sets the "sourceValue" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableSourceValue(s *string) *AlertCreate {
|
|
|
|
if s != nil {
|
|
|
|
ac.SetSourceValue(*s)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetCapacity sets the "capacity" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetCapacity(i int32) *AlertCreate {
|
|
|
|
ac.mutation.SetCapacity(i)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableCapacity sets the "capacity" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableCapacity(i *int32) *AlertCreate {
|
|
|
|
if i != nil {
|
|
|
|
ac.SetCapacity(*i)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetLeakSpeed sets the "leakSpeed" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetLeakSpeed(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetLeakSpeed(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableLeakSpeed sets the "leakSpeed" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableLeakSpeed(s *string) *AlertCreate {
|
|
|
|
if s != nil {
|
|
|
|
ac.SetLeakSpeed(*s)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetScenarioVersion sets the "scenarioVersion" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetScenarioVersion(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetScenarioVersion(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableScenarioVersion sets the "scenarioVersion" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableScenarioVersion(s *string) *AlertCreate {
|
|
|
|
if s != nil {
|
|
|
|
ac.SetScenarioVersion(*s)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetScenarioHash sets the "scenarioHash" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetScenarioHash(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetScenarioHash(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableScenarioHash sets the "scenarioHash" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableScenarioHash(s *string) *AlertCreate {
|
|
|
|
if s != nil {
|
|
|
|
ac.SetScenarioHash(*s)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetSimulated sets the "simulated" field.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetSimulated(b bool) *AlertCreate {
|
|
|
|
ac.mutation.SetSimulated(b)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableSimulated sets the "simulated" field if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableSimulated(b *bool) *AlertCreate {
|
|
|
|
if b != nil {
|
|
|
|
ac.SetSimulated(*b)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2023-01-31 13:47:44 +00:00
|
|
|
// SetUUID sets the "uuid" field.
|
|
|
|
func (ac *AlertCreate) SetUUID(s string) *AlertCreate {
|
|
|
|
ac.mutation.SetUUID(s)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNillableUUID sets the "uuid" field if the given value is not nil.
|
|
|
|
func (ac *AlertCreate) SetNillableUUID(s *string) *AlertCreate {
|
|
|
|
if s != nil {
|
|
|
|
ac.SetUUID(*s)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetOwnerID sets the "owner" edge to the Machine entity by ID.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetOwnerID(id int) *AlertCreate {
|
|
|
|
ac.mutation.SetOwnerID(id)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetNillableOwnerID sets the "owner" edge to the Machine entity by ID if the given value is not nil.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetNillableOwnerID(id *int) *AlertCreate {
|
|
|
|
if id != nil {
|
|
|
|
ac = ac.SetOwnerID(*id)
|
|
|
|
}
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SetOwner sets the "owner" edge to the Machine entity.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) SetOwner(m *Machine) *AlertCreate {
|
|
|
|
return ac.SetOwnerID(m.ID)
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// AddDecisionIDs adds the "decisions" edge to the Decision entity by IDs.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) AddDecisionIDs(ids ...int) *AlertCreate {
|
|
|
|
ac.mutation.AddDecisionIDs(ids...)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// AddDecisions adds the "decisions" edges to the Decision entity.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) AddDecisions(d ...*Decision) *AlertCreate {
|
|
|
|
ids := make([]int, len(d))
|
|
|
|
for i := range d {
|
|
|
|
ids[i] = d[i].ID
|
|
|
|
}
|
|
|
|
return ac.AddDecisionIDs(ids...)
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// AddEventIDs adds the "events" edge to the Event entity by IDs.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) AddEventIDs(ids ...int) *AlertCreate {
|
|
|
|
ac.mutation.AddEventIDs(ids...)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// AddEvents adds the "events" edges to the Event entity.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) AddEvents(e ...*Event) *AlertCreate {
|
|
|
|
ids := make([]int, len(e))
|
|
|
|
for i := range e {
|
|
|
|
ids[i] = e[i].ID
|
|
|
|
}
|
|
|
|
return ac.AddEventIDs(ids...)
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// AddMetaIDs adds the "metas" edge to the Meta entity by IDs.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) AddMetaIDs(ids ...int) *AlertCreate {
|
|
|
|
ac.mutation.AddMetaIDs(ids...)
|
|
|
|
return ac
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// AddMetas adds the "metas" edges to the Meta entity.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (ac *AlertCreate) AddMetas(m ...*Meta) *AlertCreate {
|
|
|
|
ids := make([]int, len(m))
|
|
|
|
for i := range m {
|
|
|
|
ids[i] = m[i].ID
|
|
|
|
}
|
|
|
|
return ac.AddMetaIDs(ids...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mutation returns the AlertMutation object of the builder.
|
|
|
|
func (ac *AlertCreate) Mutation() *AlertMutation {
|
|
|
|
return ac.mutation
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save creates the Alert in the database.
|
|
|
|
func (ac *AlertCreate) Save(ctx context.Context) (*Alert, error) {
|
|
|
|
ac.defaults()
|
2024-02-14 10:19:13 +00:00
|
|
|
return withHooks(ctx, ac.sqlSave, ac.mutation, ac.hooks)
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
|
|
func (ac *AlertCreate) SaveX(ctx context.Context) *Alert {
|
|
|
|
v, err := ac.Save(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2021-10-22 14:15:57 +00:00
|
|
|
// Exec executes the query.
|
|
|
|
func (ac *AlertCreate) Exec(ctx context.Context) error {
|
|
|
|
_, err := ac.Save(ctx)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
func (ac *AlertCreate) ExecX(ctx context.Context) {
|
|
|
|
if err := ac.Exec(ctx); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
// defaults sets the default values of the builder before save.
|
|
|
|
func (ac *AlertCreate) defaults() {
|
|
|
|
if _, ok := ac.mutation.CreatedAt(); !ok {
|
|
|
|
v := alert.DefaultCreatedAt()
|
|
|
|
ac.mutation.SetCreatedAt(v)
|
|
|
|
}
|
|
|
|
if _, ok := ac.mutation.UpdatedAt(); !ok {
|
|
|
|
v := alert.DefaultUpdatedAt()
|
|
|
|
ac.mutation.SetUpdatedAt(v)
|
|
|
|
}
|
|
|
|
if _, ok := ac.mutation.BucketId(); !ok {
|
|
|
|
v := alert.DefaultBucketId
|
|
|
|
ac.mutation.SetBucketId(v)
|
|
|
|
}
|
|
|
|
if _, ok := ac.mutation.Message(); !ok {
|
|
|
|
v := alert.DefaultMessage
|
|
|
|
ac.mutation.SetMessage(v)
|
|
|
|
}
|
|
|
|
if _, ok := ac.mutation.EventsCount(); !ok {
|
|
|
|
v := alert.DefaultEventsCount
|
|
|
|
ac.mutation.SetEventsCount(v)
|
|
|
|
}
|
|
|
|
if _, ok := ac.mutation.StartedAt(); !ok {
|
|
|
|
v := alert.DefaultStartedAt()
|
|
|
|
ac.mutation.SetStartedAt(v)
|
|
|
|
}
|
|
|
|
if _, ok := ac.mutation.StoppedAt(); !ok {
|
|
|
|
v := alert.DefaultStoppedAt()
|
|
|
|
ac.mutation.SetStoppedAt(v)
|
|
|
|
}
|
|
|
|
if _, ok := ac.mutation.Simulated(); !ok {
|
|
|
|
v := alert.DefaultSimulated
|
|
|
|
ac.mutation.SetSimulated(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
|
|
func (ac *AlertCreate) check() error {
|
|
|
|
if _, ok := ac.mutation.Scenario(); !ok {
|
2022-03-17 13:12:13 +00:00
|
|
|
return &ValidationError{Name: "scenario", err: errors.New(`ent: missing required field "Alert.scenario"`)}
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
if _, ok := ac.mutation.Simulated(); !ok {
|
2022-03-17 13:12:13 +00:00
|
|
|
return &ValidationError{Name: "simulated", err: errors.New(`ent: missing required field "Alert.simulated"`)}
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ac *AlertCreate) sqlSave(ctx context.Context) (*Alert, error) {
|
2024-02-14 10:19:13 +00:00
|
|
|
if err := ac.check(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-11-30 09:37:17 +00:00
|
|
|
_node, _spec := ac.createSpec()
|
|
|
|
if err := sqlgraph.CreateNode(ctx, ac.driver, _spec); err != nil {
|
2021-10-22 14:15:57 +00:00
|
|
|
if sqlgraph.IsConstraintError(err) {
|
2022-10-06 12:55:42 +00:00
|
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
id := _spec.ID.Value.(int64)
|
|
|
|
_node.ID = int(id)
|
2024-02-14 10:19:13 +00:00
|
|
|
ac.mutation.id = &_node.ID
|
|
|
|
ac.mutation.done = true
|
2020-11-30 09:37:17 +00:00
|
|
|
return _node, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ac *AlertCreate) createSpec() (*Alert, *sqlgraph.CreateSpec) {
|
|
|
|
var (
|
|
|
|
_node = &Alert{config: ac.config}
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec = sqlgraph.NewCreateSpec(alert.Table, sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt))
|
2020-11-30 09:37:17 +00:00
|
|
|
)
|
|
|
|
if value, ok := ac.mutation.CreatedAt(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldCreatedAt, field.TypeTime, value)
|
2022-01-19 13:56:05 +00:00
|
|
|
_node.CreatedAt = &value
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.UpdatedAt(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldUpdatedAt, field.TypeTime, value)
|
2022-01-19 13:56:05 +00:00
|
|
|
_node.UpdatedAt = &value
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.Scenario(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldScenario, field.TypeString, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.Scenario = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.BucketId(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldBucketId, field.TypeString, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.BucketId = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.Message(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldMessage, field.TypeString, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.Message = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.EventsCount(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldEventsCount, field.TypeInt32, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.EventsCount = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.StartedAt(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldStartedAt, field.TypeTime, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.StartedAt = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.StoppedAt(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldStoppedAt, field.TypeTime, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.StoppedAt = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.SourceIp(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldSourceIp, field.TypeString, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.SourceIp = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.SourceRange(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldSourceRange, field.TypeString, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.SourceRange = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.SourceAsNumber(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldSourceAsNumber, field.TypeString, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.SourceAsNumber = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.SourceAsName(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldSourceAsName, field.TypeString, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.SourceAsName = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.SourceCountry(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldSourceCountry, field.TypeString, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.SourceCountry = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.SourceLatitude(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldSourceLatitude, field.TypeFloat32, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.SourceLatitude = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.SourceLongitude(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldSourceLongitude, field.TypeFloat32, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.SourceLongitude = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.SourceScope(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldSourceScope, field.TypeString, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.SourceScope = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.SourceValue(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldSourceValue, field.TypeString, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.SourceValue = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.Capacity(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldCapacity, field.TypeInt32, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.Capacity = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.LeakSpeed(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldLeakSpeed, field.TypeString, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.LeakSpeed = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.ScenarioVersion(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldScenarioVersion, field.TypeString, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.ScenarioVersion = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.ScenarioHash(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldScenarioHash, field.TypeString, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.ScenarioHash = value
|
|
|
|
}
|
|
|
|
if value, ok := ac.mutation.Simulated(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldSimulated, field.TypeBool, value)
|
2020-11-30 09:37:17 +00:00
|
|
|
_node.Simulated = value
|
|
|
|
}
|
2023-01-31 13:47:44 +00:00
|
|
|
if value, ok := ac.mutation.UUID(); ok {
|
2024-02-14 10:19:13 +00:00
|
|
|
_spec.SetField(alert.FieldUUID, field.TypeString, value)
|
2023-01-31 13:47:44 +00:00
|
|
|
_node.UUID = value
|
|
|
|
}
|
2020-11-30 09:37:17 +00:00
|
|
|
if nodes := ac.mutation.OwnerIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.M2O,
|
|
|
|
Inverse: true,
|
|
|
|
Table: alert.OwnerTable,
|
|
|
|
Columns: []string{alert.OwnerColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
2024-02-14 10:19:13 +00:00
|
|
|
IDSpec: sqlgraph.NewFieldSpec(machine.FieldID, field.TypeInt),
|
2020-11-30 09:37:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
2021-03-15 17:46:52 +00:00
|
|
|
_node.machine_alerts = &nodes[0]
|
2020-11-30 09:37:17 +00:00
|
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
|
|
}
|
|
|
|
if nodes := ac.mutation.DecisionsIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: alert.DecisionsTable,
|
|
|
|
Columns: []string{alert.DecisionsColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
2024-02-14 10:19:13 +00:00
|
|
|
IDSpec: sqlgraph.NewFieldSpec(decision.FieldID, field.TypeInt),
|
2020-11-30 09:37:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
|
|
}
|
|
|
|
if nodes := ac.mutation.EventsIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: alert.EventsTable,
|
|
|
|
Columns: []string{alert.EventsColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
2024-02-14 10:19:13 +00:00
|
|
|
IDSpec: sqlgraph.NewFieldSpec(event.FieldID, field.TypeInt),
|
2020-11-30 09:37:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
|
|
}
|
|
|
|
if nodes := ac.mutation.MetasIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: alert.MetasTable,
|
|
|
|
Columns: []string{alert.MetasColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
2024-02-14 10:19:13 +00:00
|
|
|
IDSpec: sqlgraph.NewFieldSpec(meta.FieldID, field.TypeInt),
|
2020-11-30 09:37:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
|
|
}
|
|
|
|
return _node, _spec
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// AlertCreateBulk is the builder for creating many Alert entities in bulk.
|
2020-11-30 09:37:17 +00:00
|
|
|
type AlertCreateBulk struct {
|
|
|
|
config
|
2024-02-14 10:19:13 +00:00
|
|
|
err error
|
2020-11-30 09:37:17 +00:00
|
|
|
builders []*AlertCreate
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save creates the Alert entities in the database.
|
|
|
|
func (acb *AlertCreateBulk) Save(ctx context.Context) ([]*Alert, error) {
|
2024-02-14 10:19:13 +00:00
|
|
|
if acb.err != nil {
|
|
|
|
return nil, acb.err
|
|
|
|
}
|
2020-11-30 09:37:17 +00:00
|
|
|
specs := make([]*sqlgraph.CreateSpec, len(acb.builders))
|
|
|
|
nodes := make([]*Alert, len(acb.builders))
|
|
|
|
mutators := make([]Mutator, len(acb.builders))
|
|
|
|
for i := range acb.builders {
|
|
|
|
func(i int, root context.Context) {
|
|
|
|
builder := acb.builders[i]
|
|
|
|
builder.defaults()
|
|
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
|
|
mutation, ok := m.(*AlertMutation)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
|
|
}
|
|
|
|
if err := builder.check(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
builder.mutation = mutation
|
|
|
|
var err error
|
2024-02-14 10:19:13 +00:00
|
|
|
nodes[i], specs[i] = builder.createSpec()
|
2020-11-30 09:37:17 +00:00
|
|
|
if i < len(mutators)-1 {
|
|
|
|
_, err = mutators[i+1].Mutate(root, acb.builders[i+1].mutation)
|
|
|
|
} else {
|
2021-10-22 14:15:57 +00:00
|
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
2020-11-30 09:37:17 +00:00
|
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
2021-10-22 14:15:57 +00:00
|
|
|
if err = sqlgraph.BatchCreate(ctx, acb.driver, spec); err != nil {
|
|
|
|
if sqlgraph.IsConstraintError(err) {
|
2022-10-06 12:55:42 +00:00
|
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-10-22 14:15:57 +00:00
|
|
|
mutation.id = &nodes[i].ID
|
|
|
|
if specs[i].ID.Value != nil {
|
|
|
|
id := specs[i].ID.Value.(int64)
|
|
|
|
nodes[i].ID = int(id)
|
|
|
|
}
|
2022-10-06 12:55:42 +00:00
|
|
|
mutation.done = true
|
2020-11-30 09:37:17 +00:00
|
|
|
return nodes[i], nil
|
|
|
|
})
|
|
|
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
|
|
|
mut = builder.hooks[i](mut)
|
|
|
|
}
|
|
|
|
mutators[i] = mut
|
|
|
|
}(i, ctx)
|
|
|
|
}
|
|
|
|
if len(mutators) > 0 {
|
|
|
|
if _, err := mutators[0].Mutate(ctx, acb.builders[0].mutation); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nodes, nil
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (acb *AlertCreateBulk) SaveX(ctx context.Context) []*Alert {
|
|
|
|
v, err := acb.Save(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
2021-10-22 14:15:57 +00:00
|
|
|
|
|
|
|
// Exec executes the query.
|
|
|
|
func (acb *AlertCreateBulk) Exec(ctx context.Context) error {
|
|
|
|
_, err := acb.Save(ctx)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
func (acb *AlertCreateBulk) ExecX(ctx context.Context) {
|
|
|
|
if err := acb.Exec(ctx); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|