diff --git a/Makefile b/Makefile index 5d656165f..3f271c54c 100644 --- a/Makefile +++ b/Makefile @@ -202,6 +202,10 @@ cscli: goversion ## Build cscli crowdsec: goversion ## Build crowdsec @$(MAKE) -C $(CROWDSEC_FOLDER) build $(MAKE_FLAGS) +.PHONY: generate +generate: ## Generate code for the database and APIs + $(GO) generate ./pkg/database/ent + $(GO) generate ./pkg/models .PHONY: testclean testclean: bats-clean ## Remove test artifacts diff --git a/go.mod b/go.mod index c2d6ca2c1..06e0275c8 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ go 1.21 // toolchain go1.21.3 require ( - entgo.io/ent v0.12.4 + entgo.io/ent v0.12.5 github.com/AlecAivazis/survey/v2 v2.3.7 github.com/Masterminds/semver/v3 v3.2.1 github.com/Masterminds/sprig/v3 v3.2.3 diff --git a/go.sum b/go.sum index 7e8603000..35ab5813f 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ ariga.io/atlas v0.14.1-0.20230918065911-83ad451a4935 h1:JnYs/y8RJ3+MiIUp+3RgyyeO ariga.io/atlas v0.14.1-0.20230918065911-83ad451a4935/go.mod h1:isZrlzJ5cpoCoKFoY9knZug7Lq4pP1cm8g3XciLZ0Pw= bitbucket.org/creachadair/stringset v0.0.9 h1:L4vld9nzPt90UZNrXjNelTshD74ps4P5NGs3Iq6yN3o= bitbucket.org/creachadair/stringset v0.0.9/go.mod h1:t+4WcQ4+PXTa8aQdNKe40ZP6iwesoMFWAxPGd3UGjyY= -entgo.io/ent v0.12.4 h1:LddPnAyxls/O7DTXZvUGDj0NZIdGSu317+aoNLJWbD8= -entgo.io/ent v0.12.4/go.mod h1:Y3JVAjtlIk8xVZYSn3t3mf8xlZIn5SAOXZQxD6kKI+Q= +entgo.io/ent v0.12.5 h1:KREM5E4CSoej4zeGa88Ou/gfturAnpUv0mzAjch1sj4= +entgo.io/ent v0.12.5/go.mod h1:Y3JVAjtlIk8xVZYSn3t3mf8xlZIn5SAOXZQxD6kKI+Q= github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ= github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= @@ -540,8 +540,6 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= -github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 h1:rc3tiVYb5z54aKaDfakKn0dDjIyPpTtszkjuMzyt7ec= diff --git a/pkg/database/ent/alert_update.go b/pkg/database/ent/alert_update.go index 0e41ba181..f8a4d1085 100644 --- a/pkg/database/ent/alert_update.go +++ b/pkg/database/ent/alert_update.go @@ -62,6 +62,14 @@ func (au *AlertUpdate) SetScenario(s string) *AlertUpdate { return au } +// SetNillableScenario sets the "scenario" field if the given value is not nil. +func (au *AlertUpdate) SetNillableScenario(s *string) *AlertUpdate { + if s != nil { + au.SetScenario(*s) + } + return au +} + // SetBucketId sets the "bucketId" field. func (au *AlertUpdate) SetBucketId(s string) *AlertUpdate { au.mutation.SetBucketId(s) @@ -1029,6 +1037,14 @@ func (auo *AlertUpdateOne) SetScenario(s string) *AlertUpdateOne { return auo } +// SetNillableScenario sets the "scenario" field if the given value is not nil. +func (auo *AlertUpdateOne) SetNillableScenario(s *string) *AlertUpdateOne { + if s != nil { + auo.SetScenario(*s) + } + return auo +} + // SetBucketId sets the "bucketId" field. func (auo *AlertUpdateOne) SetBucketId(s string) *AlertUpdateOne { auo.mutation.SetBucketId(s) diff --git a/pkg/database/ent/bouncer_update.go b/pkg/database/ent/bouncer_update.go index f7e71eb31..b3f5e1a55 100644 --- a/pkg/database/ent/bouncer_update.go +++ b/pkg/database/ent/bouncer_update.go @@ -58,18 +58,42 @@ func (bu *BouncerUpdate) SetName(s string) *BouncerUpdate { return bu } +// SetNillableName sets the "name" field if the given value is not nil. +func (bu *BouncerUpdate) SetNillableName(s *string) *BouncerUpdate { + if s != nil { + bu.SetName(*s) + } + return bu +} + // SetAPIKey sets the "api_key" field. func (bu *BouncerUpdate) SetAPIKey(s string) *BouncerUpdate { bu.mutation.SetAPIKey(s) return bu } +// SetNillableAPIKey sets the "api_key" field if the given value is not nil. +func (bu *BouncerUpdate) SetNillableAPIKey(s *string) *BouncerUpdate { + if s != nil { + bu.SetAPIKey(*s) + } + return bu +} + // SetRevoked sets the "revoked" field. func (bu *BouncerUpdate) SetRevoked(b bool) *BouncerUpdate { bu.mutation.SetRevoked(b) return bu } +// SetNillableRevoked sets the "revoked" field if the given value is not nil. +func (bu *BouncerUpdate) SetNillableRevoked(b *bool) *BouncerUpdate { + if b != nil { + bu.SetRevoked(*b) + } + return bu +} + // SetIPAddress sets the "ip_address" field. func (bu *BouncerUpdate) SetIPAddress(s string) *BouncerUpdate { bu.mutation.SetIPAddress(s) @@ -333,18 +357,42 @@ func (buo *BouncerUpdateOne) SetName(s string) *BouncerUpdateOne { return buo } +// SetNillableName sets the "name" field if the given value is not nil. +func (buo *BouncerUpdateOne) SetNillableName(s *string) *BouncerUpdateOne { + if s != nil { + buo.SetName(*s) + } + return buo +} + // SetAPIKey sets the "api_key" field. func (buo *BouncerUpdateOne) SetAPIKey(s string) *BouncerUpdateOne { buo.mutation.SetAPIKey(s) return buo } +// SetNillableAPIKey sets the "api_key" field if the given value is not nil. +func (buo *BouncerUpdateOne) SetNillableAPIKey(s *string) *BouncerUpdateOne { + if s != nil { + buo.SetAPIKey(*s) + } + return buo +} + // SetRevoked sets the "revoked" field. func (buo *BouncerUpdateOne) SetRevoked(b bool) *BouncerUpdateOne { buo.mutation.SetRevoked(b) return buo } +// SetNillableRevoked sets the "revoked" field if the given value is not nil. +func (buo *BouncerUpdateOne) SetNillableRevoked(b *bool) *BouncerUpdateOne { + if b != nil { + buo.SetRevoked(*b) + } + return buo +} + // SetIPAddress sets the "ip_address" field. func (buo *BouncerUpdateOne) SetIPAddress(s string) *BouncerUpdateOne { buo.mutation.SetIPAddress(s) diff --git a/pkg/database/ent/client.go b/pkg/database/ent/client.go index 006d52ef9..5318109ed 100644 --- a/pkg/database/ent/client.go +++ b/pkg/database/ent/client.go @@ -50,9 +50,7 @@ type Client struct { // NewClient creates a new client configured with the given options. func NewClient(opts ...Option) *Client { - cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} - cfg.options(opts...) - client := &Client{config: cfg} + client := &Client{config: newConfig(opts...)} client.init() return client } @@ -87,6 +85,13 @@ type ( Option func(*config) ) +// newConfig creates a new config for the client. +func newConfig(opts ...Option) config { + cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} + cfg.options(opts...) + return cfg +} + // options applies the options on the config object. func (c *config) options(opts ...Option) { for _, opt := range opts { diff --git a/pkg/database/ent/configitem_update.go b/pkg/database/ent/configitem_update.go index 0db3a0b52..11fb07551 100644 --- a/pkg/database/ent/configitem_update.go +++ b/pkg/database/ent/configitem_update.go @@ -58,12 +58,28 @@ func (ciu *ConfigItemUpdate) SetName(s string) *ConfigItemUpdate { return ciu } +// SetNillableName sets the "name" field if the given value is not nil. +func (ciu *ConfigItemUpdate) SetNillableName(s *string) *ConfigItemUpdate { + if s != nil { + ciu.SetName(*s) + } + return ciu +} + // SetValue sets the "value" field. func (ciu *ConfigItemUpdate) SetValue(s string) *ConfigItemUpdate { ciu.mutation.SetValue(s) return ciu } +// SetNillableValue sets the "value" field if the given value is not nil. +func (ciu *ConfigItemUpdate) SetNillableValue(s *string) *ConfigItemUpdate { + if s != nil { + ciu.SetValue(*s) + } + return ciu +} + // Mutation returns the ConfigItemMutation object of the builder. func (ciu *ConfigItemUpdate) Mutation() *ConfigItemMutation { return ciu.mutation @@ -186,12 +202,28 @@ func (ciuo *ConfigItemUpdateOne) SetName(s string) *ConfigItemUpdateOne { return ciuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (ciuo *ConfigItemUpdateOne) SetNillableName(s *string) *ConfigItemUpdateOne { + if s != nil { + ciuo.SetName(*s) + } + return ciuo +} + // SetValue sets the "value" field. func (ciuo *ConfigItemUpdateOne) SetValue(s string) *ConfigItemUpdateOne { ciuo.mutation.SetValue(s) return ciuo } +// SetNillableValue sets the "value" field if the given value is not nil. +func (ciuo *ConfigItemUpdateOne) SetNillableValue(s *string) *ConfigItemUpdateOne { + if s != nil { + ciuo.SetValue(*s) + } + return ciuo +} + // Mutation returns the ConfigItemMutation object of the builder. func (ciuo *ConfigItemUpdateOne) Mutation() *ConfigItemMutation { return ciuo.mutation diff --git a/pkg/database/ent/decision_update.go b/pkg/database/ent/decision_update.go index 1b62cc54c..182457e9f 100644 --- a/pkg/database/ent/decision_update.go +++ b/pkg/database/ent/decision_update.go @@ -79,12 +79,28 @@ func (du *DecisionUpdate) SetScenario(s string) *DecisionUpdate { return du } +// SetNillableScenario sets the "scenario" field if the given value is not nil. +func (du *DecisionUpdate) SetNillableScenario(s *string) *DecisionUpdate { + if s != nil { + du.SetScenario(*s) + } + return du +} + // SetType sets the "type" field. func (du *DecisionUpdate) SetType(s string) *DecisionUpdate { du.mutation.SetType(s) return du } +// SetNillableType sets the "type" field if the given value is not nil. +func (du *DecisionUpdate) SetNillableType(s *string) *DecisionUpdate { + if s != nil { + du.SetType(*s) + } + return du +} + // SetStartIP sets the "start_ip" field. func (du *DecisionUpdate) SetStartIP(i int64) *DecisionUpdate { du.mutation.ResetStartIP() @@ -226,18 +242,42 @@ func (du *DecisionUpdate) SetScope(s string) *DecisionUpdate { return du } +// SetNillableScope sets the "scope" field if the given value is not nil. +func (du *DecisionUpdate) SetNillableScope(s *string) *DecisionUpdate { + if s != nil { + du.SetScope(*s) + } + return du +} + // SetValue sets the "value" field. func (du *DecisionUpdate) SetValue(s string) *DecisionUpdate { du.mutation.SetValue(s) return du } +// SetNillableValue sets the "value" field if the given value is not nil. +func (du *DecisionUpdate) SetNillableValue(s *string) *DecisionUpdate { + if s != nil { + du.SetValue(*s) + } + return du +} + // SetOrigin sets the "origin" field. func (du *DecisionUpdate) SetOrigin(s string) *DecisionUpdate { du.mutation.SetOrigin(s) return du } +// SetNillableOrigin sets the "origin" field if the given value is not nil. +func (du *DecisionUpdate) SetNillableOrigin(s *string) *DecisionUpdate { + if s != nil { + du.SetOrigin(*s) + } + return du +} + // SetSimulated sets the "simulated" field. func (du *DecisionUpdate) SetSimulated(b bool) *DecisionUpdate { du.mutation.SetSimulated(b) @@ -557,12 +597,28 @@ func (duo *DecisionUpdateOne) SetScenario(s string) *DecisionUpdateOne { return duo } +// SetNillableScenario sets the "scenario" field if the given value is not nil. +func (duo *DecisionUpdateOne) SetNillableScenario(s *string) *DecisionUpdateOne { + if s != nil { + duo.SetScenario(*s) + } + return duo +} + // SetType sets the "type" field. func (duo *DecisionUpdateOne) SetType(s string) *DecisionUpdateOne { duo.mutation.SetType(s) return duo } +// SetNillableType sets the "type" field if the given value is not nil. +func (duo *DecisionUpdateOne) SetNillableType(s *string) *DecisionUpdateOne { + if s != nil { + duo.SetType(*s) + } + return duo +} + // SetStartIP sets the "start_ip" field. func (duo *DecisionUpdateOne) SetStartIP(i int64) *DecisionUpdateOne { duo.mutation.ResetStartIP() @@ -704,18 +760,42 @@ func (duo *DecisionUpdateOne) SetScope(s string) *DecisionUpdateOne { return duo } +// SetNillableScope sets the "scope" field if the given value is not nil. +func (duo *DecisionUpdateOne) SetNillableScope(s *string) *DecisionUpdateOne { + if s != nil { + duo.SetScope(*s) + } + return duo +} + // SetValue sets the "value" field. func (duo *DecisionUpdateOne) SetValue(s string) *DecisionUpdateOne { duo.mutation.SetValue(s) return duo } +// SetNillableValue sets the "value" field if the given value is not nil. +func (duo *DecisionUpdateOne) SetNillableValue(s *string) *DecisionUpdateOne { + if s != nil { + duo.SetValue(*s) + } + return duo +} + // SetOrigin sets the "origin" field. func (duo *DecisionUpdateOne) SetOrigin(s string) *DecisionUpdateOne { duo.mutation.SetOrigin(s) return duo } +// SetNillableOrigin sets the "origin" field if the given value is not nil. +func (duo *DecisionUpdateOne) SetNillableOrigin(s *string) *DecisionUpdateOne { + if s != nil { + duo.SetOrigin(*s) + } + return duo +} + // SetSimulated sets the "simulated" field. func (duo *DecisionUpdateOne) SetSimulated(b bool) *DecisionUpdateOne { duo.mutation.SetSimulated(b) diff --git a/pkg/database/ent/event_update.go b/pkg/database/ent/event_update.go index db7481015..a06178f79 100644 --- a/pkg/database/ent/event_update.go +++ b/pkg/database/ent/event_update.go @@ -59,12 +59,28 @@ func (eu *EventUpdate) SetTime(t time.Time) *EventUpdate { return eu } +// SetNillableTime sets the "time" field if the given value is not nil. +func (eu *EventUpdate) SetNillableTime(t *time.Time) *EventUpdate { + if t != nil { + eu.SetTime(*t) + } + return eu +} + // SetSerialized sets the "serialized" field. func (eu *EventUpdate) SetSerialized(s string) *EventUpdate { eu.mutation.SetSerialized(s) return eu } +// SetNillableSerialized sets the "serialized" field if the given value is not nil. +func (eu *EventUpdate) SetNillableSerialized(s *string) *EventUpdate { + if s != nil { + eu.SetSerialized(*s) + } + return eu +} + // SetAlertEvents sets the "alert_events" field. func (eu *EventUpdate) SetAlertEvents(i int) *EventUpdate { eu.mutation.SetAlertEvents(i) @@ -274,12 +290,28 @@ func (euo *EventUpdateOne) SetTime(t time.Time) *EventUpdateOne { return euo } +// SetNillableTime sets the "time" field if the given value is not nil. +func (euo *EventUpdateOne) SetNillableTime(t *time.Time) *EventUpdateOne { + if t != nil { + euo.SetTime(*t) + } + return euo +} + // SetSerialized sets the "serialized" field. func (euo *EventUpdateOne) SetSerialized(s string) *EventUpdateOne { euo.mutation.SetSerialized(s) return euo } +// SetNillableSerialized sets the "serialized" field if the given value is not nil. +func (euo *EventUpdateOne) SetNillableSerialized(s *string) *EventUpdateOne { + if s != nil { + euo.SetSerialized(*s) + } + return euo +} + // SetAlertEvents sets the "alert_events" field. func (euo *EventUpdateOne) SetAlertEvents(i int) *EventUpdateOne { euo.mutation.SetAlertEvents(i) diff --git a/pkg/database/ent/generate.go b/pkg/database/ent/generate.go index 9f3a916c7..5f4b39eec 100644 --- a/pkg/database/ent/generate.go +++ b/pkg/database/ent/generate.go @@ -1,4 +1,4 @@ package ent -//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate ./schema +//go:generate go run -mod=mod entgo.io/ent/cmd/ent@v0.12.5 generate ./schema diff --git a/pkg/database/ent/lock_update.go b/pkg/database/ent/lock_update.go index f4deda6e3..dc61dfdfd 100644 --- a/pkg/database/ent/lock_update.go +++ b/pkg/database/ent/lock_update.go @@ -34,6 +34,14 @@ func (lu *LockUpdate) SetName(s string) *LockUpdate { return lu } +// SetNillableName sets the "name" field if the given value is not nil. +func (lu *LockUpdate) SetNillableName(s *string) *LockUpdate { + if s != nil { + lu.SetName(*s) + } + return lu +} + // SetCreatedAt sets the "created_at" field. func (lu *LockUpdate) SetCreatedAt(t time.Time) *LockUpdate { lu.mutation.SetCreatedAt(t) @@ -121,6 +129,14 @@ func (luo *LockUpdateOne) SetName(s string) *LockUpdateOne { return luo } +// SetNillableName sets the "name" field if the given value is not nil. +func (luo *LockUpdateOne) SetNillableName(s *string) *LockUpdateOne { + if s != nil { + luo.SetName(*s) + } + return luo +} + // SetCreatedAt sets the "created_at" field. func (luo *LockUpdateOne) SetCreatedAt(t time.Time) *LockUpdateOne { luo.mutation.SetCreatedAt(t) diff --git a/pkg/database/ent/machine_update.go b/pkg/database/ent/machine_update.go index eb5170811..1f87ac04d 100644 --- a/pkg/database/ent/machine_update.go +++ b/pkg/database/ent/machine_update.go @@ -83,18 +83,42 @@ func (mu *MachineUpdate) SetMachineId(s string) *MachineUpdate { return mu } +// SetNillableMachineId sets the "machineId" field if the given value is not nil. +func (mu *MachineUpdate) SetNillableMachineId(s *string) *MachineUpdate { + if s != nil { + mu.SetMachineId(*s) + } + return mu +} + // SetPassword sets the "password" field. func (mu *MachineUpdate) SetPassword(s string) *MachineUpdate { mu.mutation.SetPassword(s) return mu } +// SetNillablePassword sets the "password" field if the given value is not nil. +func (mu *MachineUpdate) SetNillablePassword(s *string) *MachineUpdate { + if s != nil { + mu.SetPassword(*s) + } + return mu +} + // SetIpAddress sets the "ipAddress" field. func (mu *MachineUpdate) SetIpAddress(s string) *MachineUpdate { mu.mutation.SetIpAddress(s) return mu } +// SetNillableIpAddress sets the "ipAddress" field if the given value is not nil. +func (mu *MachineUpdate) SetNillableIpAddress(s *string) *MachineUpdate { + if s != nil { + mu.SetIpAddress(*s) + } + return mu +} + // SetScenarios sets the "scenarios" field. func (mu *MachineUpdate) SetScenarios(s string) *MachineUpdate { mu.mutation.SetScenarios(s) @@ -470,18 +494,42 @@ func (muo *MachineUpdateOne) SetMachineId(s string) *MachineUpdateOne { return muo } +// SetNillableMachineId sets the "machineId" field if the given value is not nil. +func (muo *MachineUpdateOne) SetNillableMachineId(s *string) *MachineUpdateOne { + if s != nil { + muo.SetMachineId(*s) + } + return muo +} + // SetPassword sets the "password" field. func (muo *MachineUpdateOne) SetPassword(s string) *MachineUpdateOne { muo.mutation.SetPassword(s) return muo } +// SetNillablePassword sets the "password" field if the given value is not nil. +func (muo *MachineUpdateOne) SetNillablePassword(s *string) *MachineUpdateOne { + if s != nil { + muo.SetPassword(*s) + } + return muo +} + // SetIpAddress sets the "ipAddress" field. func (muo *MachineUpdateOne) SetIpAddress(s string) *MachineUpdateOne { muo.mutation.SetIpAddress(s) return muo } +// SetNillableIpAddress sets the "ipAddress" field if the given value is not nil. +func (muo *MachineUpdateOne) SetNillableIpAddress(s *string) *MachineUpdateOne { + if s != nil { + muo.SetIpAddress(*s) + } + return muo +} + // SetScenarios sets the "scenarios" field. func (muo *MachineUpdateOne) SetScenarios(s string) *MachineUpdateOne { muo.mutation.SetScenarios(s) diff --git a/pkg/database/ent/meta_update.go b/pkg/database/ent/meta_update.go index 8071c4f0d..a1379faa1 100644 --- a/pkg/database/ent/meta_update.go +++ b/pkg/database/ent/meta_update.go @@ -59,12 +59,28 @@ func (mu *MetaUpdate) SetKey(s string) *MetaUpdate { return mu } +// SetNillableKey sets the "key" field if the given value is not nil. +func (mu *MetaUpdate) SetNillableKey(s *string) *MetaUpdate { + if s != nil { + mu.SetKey(*s) + } + return mu +} + // SetValue sets the "value" field. func (mu *MetaUpdate) SetValue(s string) *MetaUpdate { mu.mutation.SetValue(s) return mu } +// SetNillableValue sets the "value" field if the given value is not nil. +func (mu *MetaUpdate) SetNillableValue(s *string) *MetaUpdate { + if s != nil { + mu.SetValue(*s) + } + return mu +} + // SetAlertMetas sets the "alert_metas" field. func (mu *MetaUpdate) SetAlertMetas(i int) *MetaUpdate { mu.mutation.SetAlertMetas(i) @@ -274,12 +290,28 @@ func (muo *MetaUpdateOne) SetKey(s string) *MetaUpdateOne { return muo } +// SetNillableKey sets the "key" field if the given value is not nil. +func (muo *MetaUpdateOne) SetNillableKey(s *string) *MetaUpdateOne { + if s != nil { + muo.SetKey(*s) + } + return muo +} + // SetValue sets the "value" field. func (muo *MetaUpdateOne) SetValue(s string) *MetaUpdateOne { muo.mutation.SetValue(s) return muo } +// SetNillableValue sets the "value" field if the given value is not nil. +func (muo *MetaUpdateOne) SetNillableValue(s *string) *MetaUpdateOne { + if s != nil { + muo.SetValue(*s) + } + return muo +} + // SetAlertMetas sets the "alert_metas" field. func (muo *MetaUpdateOne) SetAlertMetas(i int) *MetaUpdateOne { muo.mutation.SetAlertMetas(i) diff --git a/pkg/database/ent/runtime/runtime.go b/pkg/database/ent/runtime/runtime.go index 2a645f624..d10a2fb54 100644 --- a/pkg/database/ent/runtime/runtime.go +++ b/pkg/database/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in github.com/crowdsecurity/crowdsec/pkg/database/ent/runtime.go const ( - Version = "v0.12.4" // Version of ent codegen. - Sum = "h1:LddPnAyxls/O7DTXZvUGDj0NZIdGSu317+aoNLJWbD8=" // Sum of ent codegen. + Version = "v0.12.5" // Version of ent codegen. + Sum = "h1:KREM5E4CSoej4zeGa88Ou/gfturAnpUv0mzAjch1sj4=" // Sum of ent codegen. ) diff --git a/pkg/models/add_alerts_request.go b/pkg/models/add_alerts_request.go index fd7246be0..a69934ef7 100644 --- a/pkg/models/add_alerts_request.go +++ b/pkg/models/add_alerts_request.go @@ -54,6 +54,11 @@ func (m AddAlertsRequest) ContextValidate(ctx context.Context, formats strfmt.Re for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/pkg/models/alert.go b/pkg/models/alert.go index ec769a1fb..895f5ad76 100644 --- a/pkg/models/alert.go +++ b/pkg/models/alert.go @@ -399,6 +399,11 @@ func (m *Alert) contextValidateDecisions(ctx context.Context, formats strfmt.Reg for i := 0; i < len(m.Decisions); i++ { if m.Decisions[i] != nil { + + if swag.IsZero(m.Decisions[i]) { // not required + return nil + } + if err := m.Decisions[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("decisions" + "." + strconv.Itoa(i)) @@ -419,6 +424,11 @@ func (m *Alert) contextValidateEvents(ctx context.Context, formats strfmt.Regist for i := 0; i < len(m.Events); i++ { if m.Events[i] != nil { + + if swag.IsZero(m.Events[i]) { // not required + return nil + } + if err := m.Events[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("events" + "." + strconv.Itoa(i)) @@ -469,6 +479,7 @@ func (m *Alert) contextValidateMeta(ctx context.Context, formats strfmt.Registry func (m *Alert) contextValidateSource(ctx context.Context, formats strfmt.Registry) error { if m.Source != nil { + if err := m.Source.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("source") diff --git a/pkg/models/generate.go b/pkg/models/generate.go new file mode 100644 index 000000000..ccacc409a --- /dev/null +++ b/pkg/models/generate.go @@ -0,0 +1,4 @@ +package models + +//go:generate go run -mod=mod github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5 generate model --spec=./localapi_swagger.yaml --target=../ + diff --git a/pkg/models/get_alerts_response.go b/pkg/models/get_alerts_response.go index 41b9d5afd..d4ea36e02 100644 --- a/pkg/models/get_alerts_response.go +++ b/pkg/models/get_alerts_response.go @@ -54,6 +54,11 @@ func (m GetAlertsResponse) ContextValidate(ctx context.Context, formats strfmt.R for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/pkg/models/get_decisions_response.go b/pkg/models/get_decisions_response.go index b65b950fc..19437dc9b 100644 --- a/pkg/models/get_decisions_response.go +++ b/pkg/models/get_decisions_response.go @@ -54,6 +54,11 @@ func (m GetDecisionsResponse) ContextValidate(ctx context.Context, formats strfm for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/pkg/models/meta.go b/pkg/models/meta.go index 6ad20856d..df5ae3c62 100644 --- a/pkg/models/meta.go +++ b/pkg/models/meta.go @@ -56,6 +56,11 @@ func (m Meta) ContextValidate(ctx context.Context, formats strfmt.Registry) erro for i := 0; i < len(m); i++ { if m[i] != nil { + + if swag.IsZero(m[i]) { // not required + return nil + } + if err := m[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName(strconv.Itoa(i)) diff --git a/pkg/models/metrics.go b/pkg/models/metrics.go index 573678d1f..7fbb91c63 100644 --- a/pkg/models/metrics.go +++ b/pkg/models/metrics.go @@ -141,6 +141,11 @@ func (m *Metrics) contextValidateBouncers(ctx context.Context, formats strfmt.Re for i := 0; i < len(m.Bouncers); i++ { if m.Bouncers[i] != nil { + + if swag.IsZero(m.Bouncers[i]) { // not required + return nil + } + if err := m.Bouncers[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("bouncers" + "." + strconv.Itoa(i)) @@ -161,6 +166,11 @@ func (m *Metrics) contextValidateMachines(ctx context.Context, formats strfmt.Re for i := 0; i < len(m.Machines); i++ { if m.Machines[i] != nil { + + if swag.IsZero(m.Machines[i]) { // not required + return nil + } + if err := m.Machines[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("machines" + "." + strconv.Itoa(i))