From 5544000d38b5d10d26725c9e68498091d4f4895b Mon Sep 17 00:00:00 2001 From: AlteredCoder <64792091+AlteredCoder@users.noreply.github.com> Date: Thu, 14 Jan 2021 16:27:45 +0100 Subject: [PATCH] lapi: fix ipv6 operations (#567) --- .github/workflows/ci_functests-install.yml | 2 +- .github/workflows/ci_functests-ip_mgmt.yml | 31 + cmd/crowdsec-cli/alerts.go | 7 + cmd/crowdsec-cli/decisions.go | 27 +- go.mod | 8 +- go.sum | 30 +- pkg/apiclient/alerts_service.go | 2 + pkg/apiclient/alerts_service_test.go | 6 - pkg/apiclient/decisions_service.go | 3 + pkg/apiclient/decisions_service_test.go | 8 +- pkg/apiserver/alerts_test.go | 30 +- pkg/apiserver/apic.go | 27 +- pkg/apiserver/controllers/utils.go | 65 - pkg/apiserver/controllers/v1/alerts.go | 12 +- pkg/apiserver/controllers/v1/decisions.go | 2 - pkg/apiserver/decisions_test.go | 28 +- .../alertWithInvalidMachineID_sample.json | 2 - pkg/apiserver/tests/alert_sample.json | 2 - pkg/apiserver/tests/invalidAlert_sample.json | 2 - pkg/apiserver/utils_test.go | 54 - pkg/csprofiles/csprofiles.go | 33 - pkg/database/alerts.go | 116 +- pkg/database/decisions.go | 323 ++- pkg/database/ent/alert.go | 340 +-- pkg/database/ent/alert/alert.go | 16 +- pkg/database/ent/alert/where.go | 6 +- pkg/database/ent/alert_create.go | 108 +- pkg/database/ent/alert_delete.go | 11 +- pkg/database/ent/alert_query.go | 177 +- pkg/database/ent/alert_update.go | 353 ++- pkg/database/ent/bouncer.go | 163 +- pkg/database/ent/bouncer/bouncer.go | 10 +- pkg/database/ent/bouncer/where.go | 6 +- pkg/database/ent/bouncer_create.go | 38 +- pkg/database/ent/bouncer_delete.go | 11 +- pkg/database/ent/bouncer_query.go | 133 +- pkg/database/ent/bouncer_update.go | 101 +- pkg/database/ent/client.go | 14 +- pkg/database/ent/context.go | 6 +- pkg/database/ent/decision.go | 230 +- pkg/database/ent/decision/decision.go | 15 +- pkg/database/ent/decision/where.go | 297 ++- pkg/database/ent/decision_create.go | 108 +- pkg/database/ent/decision_delete.go | 11 +- pkg/database/ent/decision_query.go | 143 +- pkg/database/ent/decision_update.go | 395 +++- pkg/database/ent/ent.go | 6 +- pkg/database/ent/event.go | 114 +- pkg/database/ent/event/event.go | 4 +- pkg/database/ent/event/where.go | 6 +- pkg/database/ent/event_create.go | 22 +- pkg/database/ent/event_delete.go | 11 +- pkg/database/ent/event_query.go | 143 +- pkg/database/ent/event_update.go | 57 +- pkg/database/ent/hook/hook.go | 15 +- pkg/database/ent/machine.go | 153 +- pkg/database/ent/machine/machine.go | 6 +- pkg/database/ent/machine/where.go | 6 +- pkg/database/ent/machine_create.go | 38 +- pkg/database/ent/machine_delete.go | 11 +- pkg/database/ent/machine_query.go | 141 +- pkg/database/ent/machine_update.go | 109 +- pkg/database/ent/meta.go | 114 +- pkg/database/ent/meta/meta.go | 4 +- pkg/database/ent/meta/where.go | 6 +- pkg/database/ent/meta_create.go | 22 +- pkg/database/ent/meta_delete.go | 11 +- pkg/database/ent/meta_query.go | 143 +- pkg/database/ent/meta_update.go | 57 +- pkg/database/ent/migrate/migrate.go | 2 + pkg/database/ent/migrate/schema.go | 5 +- pkg/database/ent/mutation.go | 2092 +++++++++-------- pkg/database/ent/privacy/privacy.go | 355 --- pkg/database/ent/runtime.go | 6 +- pkg/database/ent/runtime/runtime.go | 4 +- pkg/database/ent/schema/decision.go | 3 + pkg/models/decision.go | 6 - pkg/models/localapi_swagger.yaml | 6 - pkg/types/ip.go | 106 + pkg/types/ip_test.go | 220 ++ pkg/types/utils.go | 37 - scripts/test_ip_management.sh | 434 ++++ scripts/test_wizard_upgrade.sh | 2 +- 83 files changed, 4749 insertions(+), 3240 deletions(-) create mode 100644 .github/workflows/ci_functests-ip_mgmt.yml delete mode 100644 pkg/apiserver/controllers/utils.go delete mode 100644 pkg/apiserver/utils_test.go delete mode 100644 pkg/database/ent/privacy/privacy.go create mode 100644 pkg/types/ip.go create mode 100644 pkg/types/ip_test.go create mode 100755 scripts/test_ip_management.sh diff --git a/.github/workflows/ci_functests-install.yml b/.github/workflows/ci_functests-install.yml index 3a99f7d80..841720c0b 100644 --- a/.github/workflows/ci_functests-install.yml +++ b/.github/workflows/ci_functests-install.yml @@ -53,7 +53,7 @@ jobs: run: | sudo cscli decisions list sudo cscli decisions list -o=json | jq -e '.[].decisions[0].value == "1.1.1.172"' - sudo cscli decisions list -r 1.1.1.0/24 -o=json | jq -e '.[].decisions[0].value == "1.1.1.172"' + sudo cscli decisions list -r 1.1.1.0/24 -o=json --contained | jq -e '.[].decisions[0].value == "1.1.1.172"' sudo cscli decisions list -r 1.1.2.0/24 -o=json | jq -e '. == null' sudo cscli decisions list -i 1.1.1.172 -o=json | jq -e '.[].decisions[0].value == "1.1.1.172"' sudo cscli decisions list -i 1.1.1.173 -o=json | jq -e '. == null' diff --git a/.github/workflows/ci_functests-ip_mgmt.yml b/.github/workflows/ci_functests-ip_mgmt.yml new file mode 100644 index 000000000..098ac3376 --- /dev/null +++ b/.github/workflows/ci_functests-ip_mgmt.yml @@ -0,0 +1,31 @@ +name: Functionnal tests for IP management + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + build: + name: Install generated release and perform basic tests + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.13 + uses: actions/setup-go@v1 + with: + go-version: 1.13 + id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: install ipset for bouncer + run: | + sudo apt update + sudo apt install jq + - name: run tests + run: | + cd scripts/ + sudo ./test_ip_management.sh + diff --git a/cmd/crowdsec-cli/alerts.go b/cmd/crowdsec-cli/alerts.go index 13adafad3..aba316085 100644 --- a/cmd/crowdsec-cli/alerts.go +++ b/cmd/crowdsec-cli/alerts.go @@ -21,6 +21,7 @@ import ( ) var printMachine bool +var contained bool var limit *int func DecisionsFromAlert(alert *models.Alert) string { @@ -232,6 +233,7 @@ func NewAlertsCmd() *cobra.Command { Since: new(string), Until: new(string), TypeEquals: new(string), + Contains: new(bool), } limit = new(int) var cmdAlertsList = &cobra.Command{ @@ -300,6 +302,7 @@ cscli alerts list --type ban`, if *alertListFilter.RangeEquals == "" { alertListFilter.RangeEquals = nil } + *alertListFilter.Contains = !contained alerts, _, err := Client.Alerts.List(context.Background(), alertListFilter) if err != nil { log.Fatalf("Unable to list alerts : %v", err.Error()) @@ -320,6 +323,7 @@ cscli alerts list --type ban`, cmdAlertsList.Flags().StringVar(alertListFilter.TypeEquals, "type", "", "restrict to alerts with given decision type (ie. ban, captcha)") cmdAlertsList.Flags().StringVar(alertListFilter.ScopeEquals, "scope", "", "restrict to alerts of this scope (ie. ip,range)") cmdAlertsList.Flags().StringVarP(alertListFilter.ValueEquals, "value", "v", "", "the value to match for in the specified scope") + cmdAlertsList.Flags().BoolVar(&contained, "contained", false, "query decisions contained by range") cmdAlertsList.Flags().BoolVarP(&printMachine, "machine", "m", false, "print machines that sended alerts") cmdAlertsList.Flags().IntVarP(limit, "limit", "l", 50, "limit size of alerts list table (0 to view all alerts)") cmdAlerts.AddCommand(cmdAlertsList) @@ -332,6 +336,7 @@ cscli alerts list --type ban`, ScenarioEquals: new(string), IPEquals: new(string), RangeEquals: new(string), + Contains: new(bool), } var cmdAlertsDelete = &cobra.Command{ Use: "delete [filters] [--all]", @@ -380,6 +385,7 @@ cscli alerts delete -s crowdsecurity/ssh-bf"`, if *alertDeleteFilter.RangeEquals == "" { alertDeleteFilter.RangeEquals = nil } + *alertDeleteFilter.Contains = !contained } else { alertDeleteFilter = apiclient.AlertsDeleteOpts{} } @@ -398,6 +404,7 @@ cscli alerts delete -s crowdsecurity/ssh-bf"`, cmdAlertsDelete.Flags().StringVarP(alertDeleteFilter.IPEquals, "ip", "i", "", "Source ip (shorthand for --scope ip --value )") cmdAlertsDelete.Flags().StringVarP(alertDeleteFilter.RangeEquals, "range", "r", "", "Range source ip (shorthand for --scope range --value )") cmdAlertsDelete.Flags().BoolVarP(&AlertDeleteAll, "all", "a", false, "delete all alerts") + cmdAlertsDelete.Flags().BoolVar(&contained, "contained", false, "query decisions contained by range") cmdAlerts.AddCommand(cmdAlertsDelete) diff --git a/cmd/crowdsec-cli/decisions.go b/cmd/crowdsec-cli/decisions.go index 8a7a9788f..2b3799133 100644 --- a/cmd/crowdsec-cli/decisions.go +++ b/cmd/crowdsec-cli/decisions.go @@ -12,7 +12,6 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/apiclient" "github.com/crowdsecurity/crowdsec/pkg/cwversion" - "github.com/crowdsecurity/crowdsec/pkg/database" "github.com/crowdsecurity/crowdsec/pkg/models" "github.com/crowdsecurity/crowdsec/pkg/types" "github.com/go-openapi/strfmt" @@ -140,6 +139,7 @@ func NewDecisionsCmd() *cobra.Command { Until: new(string), TypeEquals: new(string), IncludeCAPI: new(bool), + Contains: new(bool), } NoSimu := new(bool) var cmdDecisionsList = &cobra.Command{ @@ -209,6 +209,7 @@ cscli decisions list -t ban if *filter.RangeEquals == "" { filter.RangeEquals = nil } + *filter.Contains = !contained alerts, _, err := Client.Alerts.List(context.Background(), filter) if err != nil { log.Fatalf("Unable to list decisions : %v", err.Error()) @@ -231,6 +232,8 @@ cscli decisions list -t ban cmdDecisionsList.Flags().StringVarP(filter.IPEquals, "ip", "i", "", "restrict to alerts from this source ip (shorthand for --scope ip --value )") cmdDecisionsList.Flags().StringVarP(filter.RangeEquals, "range", "r", "", "restrict to alerts from this source range (shorthand for --scope range --value )") cmdDecisionsList.Flags().BoolVar(NoSimu, "no-simu", false, "exclude decisions in simulation mode") + cmdDecisionsList.Flags().BoolVar(&contained, "contained", false, "query decisions contained by range") + cmdDecisions.AddCommand(cmdDecisionsList) var ( @@ -254,7 +257,6 @@ cscli decisions add --scope username --value foobar /*TBD : fix long and example*/ Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { - var startIP, endIP int64 var err error var ip, ipRange string alerts := models.AddAlertsRequest{} @@ -285,20 +287,6 @@ cscli decisions add --scope username --value foobar return } - if addScope == types.Ip { - startIP, endIP, err = database.GetIpsFromIpRange(addValue + "/32") - if err != nil { - log.Fatalf("unable to parse IP : '%s'", addValue) - } - } - if addScope == types.Range { - startIP, endIP, err = database.GetIpsFromIpRange(addValue) - if err != nil { - log.Fatalf("unable to parse Range : '%s'", addValue) - } - ipRange = addValue - } - if addReason == "" { addReason = fmt.Sprintf("manual '%s' from '%s'", addType, csConfig.API.Client.Credentials.Login) } @@ -310,8 +298,6 @@ cscli decisions add --scope username --value foobar Type: &addType, Scenario: &addReason, Origin: &origin, - StartIP: startIP, - EndIP: endIP, } alert := models.Alert{ Capacity: &capacity, @@ -364,6 +350,7 @@ cscli decisions add --scope username --value foobar TypeEquals: new(string), IPEquals: new(string), RangeEquals: new(string), + Contains: new(bool), } var delDecisionId string var delDecisionAll bool @@ -414,7 +401,7 @@ cscli decisions delete --type captcha if *delFilter.RangeEquals == "" { delFilter.RangeEquals = nil } - + *delFilter.Contains = !contained if delDecisionId == "" { decisions, _, err = Client.Decisions.Delete(context.Background(), delFilter) if err != nil { @@ -437,6 +424,8 @@ cscli decisions delete --type captcha cmdDecisionsDelete.Flags().StringVarP(delFilter.TypeEquals, "type", "t", "", "the decision type (ie. ban,captcha)") cmdDecisionsDelete.Flags().StringVarP(delFilter.ValueEquals, "value", "v", "", "the value to match for in the specified scope") cmdDecisionsDelete.Flags().BoolVar(&delDecisionAll, "all", false, "delete all decisions") + cmdDecisionsDelete.Flags().BoolVar(&contained, "contained", false, "query decisions contained by range") + cmdDecisions.AddCommand(cmdDecisionsDelete) return cmdDecisions diff --git a/go.mod b/go.mod index 61bfef76c..e5d44c17e 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/docker/docker v20.10.2+incompatible github.com/docker/go-connections v0.4.0 github.com/enescakir/emoji v1.0.0 - github.com/facebook/ent v0.5.0 + github.com/facebook/ent v0.5.4 github.com/gin-gonic/gin v1.6.3 github.com/go-co-op/gocron v0.3.3 github.com/go-openapi/analysis v0.19.12 // indirect @@ -35,7 +35,7 @@ require ( github.com/google/go-querystring v1.0.0 github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e github.com/hashicorp/go-version v1.2.1 - github.com/lib/pq v1.8.0 + github.com/lib/pq v1.9.0 github.com/logrusorgru/grokky v0.0.0-20180829062225-47edf017d42c github.com/mailru/easyjson v0.7.6 // indirect github.com/mattn/go-sqlite3 v2.0.3+incompatible @@ -56,11 +56,11 @@ require ( github.com/sirupsen/logrus v1.7.0 github.com/spf13/cobra v1.1.1 github.com/stretchr/testify v1.6.1 - github.com/ugorji/go/codec v1.2.0 // indirect + github.com/ugorji/go v1.2.0 // indirect github.com/vjeantet/grok v1.0.1 // indirect go.mongodb.org/mongo-driver v1.4.3 // indirect golang.org/x/crypto v0.0.0-20201116153603-4be66e5b6582 - golang.org/x/mod v0.3.0 + golang.org/x/mod v0.4.0 golang.org/x/net v0.0.0-20201110031124-69a78807bb2b // indirect golang.org/x/sys v0.0.0-20201116161645-c061ba923fbb golang.org/x/text v0.3.4 // indirect diff --git a/go.sum b/go.sum index 2412df0dd..23dd2f14d 100644 --- a/go.sum +++ b/go.sum @@ -135,8 +135,8 @@ github.com/enescakir/emoji v1.0.0/go.mod h1:Bt1EKuLnKDTYpLALApstIkAjdDrS/8IAgTkK github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/facebook/ent v0.5.0 h1:NlDQDxJi1X6+20CCjRQgu8UqvRhQNm5ocPBCQYdxC/8= -github.com/facebook/ent v0.5.0/go.mod h1:HrrMNGsvgZoGQ74PGBQJ9r9WNOVMqKQefcOJFXuOUlw= +github.com/facebook/ent v0.5.4 h1:kIf2BQUdRJ7XrlTXzCyJCg69ar1K1FjFR2UQWRo/M8M= +github.com/facebook/ent v0.5.4/go.mod h1:ZioHzZjDTB/uPABl7pff/v2+cdsEBca8roSTWW3/UaE= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= @@ -151,6 +151,7 @@ github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= +github.com/go-bindata/go-bindata v1.0.1-0.20190711162640-ee3c2418e368 h1:WNHfSP1q2vuAa9vF54RrhCl4nqxCjVcXhlbsRXbGOSY= github.com/go-bindata/go-bindata v1.0.1-0.20190711162640-ee3c2418e368/go.mod h1:7xCgX1lzlrXPHkfvn3EhumqHkmSlzt8at9q7v0ax19c= github.com/go-co-op/gocron v0.3.3 h1:QnarcMZWWKrEP25uCbtDiLsnnGw+PhCjL3wNITdWJOs= github.com/go-co-op/gocron v0.3.3/go.mod h1:Y9PWlYqDChf2Nbgg7kfS+ZsXHDTZbMZYPEQ0MILqH+M= @@ -180,6 +181,7 @@ github.com/go-openapi/errors v0.19.7 h1:Lcq+o0mSwCLKACMxZhreVHigB9ebghJ/lrmeaqAS github.com/go-openapi/errors v0.19.7/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= github.com/go-openapi/errors v0.19.8 h1:doM+tQdZbUm9gydV9yR+iQNmztbjj7I3sW4sIcAwIzc= github.com/go-openapi/errors v0.19.8/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= +github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4= github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4= github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= github.com/go-openapi/jsonpointer v0.18.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= @@ -336,8 +338,8 @@ github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OI github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.4 h1:0ecGp3skIrHWPNGPJDaBIghfA6Sp7Ruo2Io8eLKzWm0= +github.com/google/uuid v1.1.4/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e h1:XmA6L9IPRdUr28a+SK/oMchGgQy159wvzXA5tJ7l+40= @@ -429,8 +431,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/lib/pq v1.8.0 h1:9xohqzkUwzR4Ga4ivdTcawVS89YSDVxXMa3xJX3cGzg= -github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/lib/pq v1.9.0 h1:L8nSXQQzAYByakOFMTwpjRoHsMJklur4Gi59b6VivR8= +github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= github.com/logrusorgru/grokky v0.0.0-20180829062225-47edf017d42c h1:S3P1IbG7Z7V2p9juEttr1oRwozZd2kxw+RQiYBYB1wQ= @@ -464,7 +466,7 @@ github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuuj github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-sqlite3 v1.14.4/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI= +github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U= github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= @@ -482,8 +484,8 @@ github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:F github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.3.2 h1:mRS76wmkOn3KkKAyXDu42V+6ebnXWIztFSYGN7GeoRg= github.com/mitchellh/mapstructure v1.3.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/mapstructure v1.3.3 h1:SzB1nHZ2Xi+17FP0zVQBHIZqvwRN9408fJO8h+eeNA8= -github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.4.0 h1:7ks8ZkOP5/ujthUsT07rNv+nkLXCQWKNHuwzOAesEks= +github.com/mitchellh/mapstructure v1.4.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 h1:rzf0wL0CHVc8CEsgyygG0Mn9CNCCPZqOPaz8RiiHYQk= github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -737,6 +739,8 @@ golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.0 h1:8pl+sMODzuvGJkmj2W4kZihvVb5mKm8pB/X44PIQHv8= +golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -765,8 +769,7 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM= golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -779,7 +782,7 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -871,7 +874,8 @@ golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= +golang.org/x/tools v0.0.0-20210105164027-a548c3f4af2d h1:v9TQ4+tS+0r4R+9E6svkcl6ocSxeHONeVkK2y6YhzmA= +golang.org/x/tools v0.0.0-20210105164027-a548c3f4af2d/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= diff --git a/pkg/apiclient/alerts_service.go b/pkg/apiclient/alerts_service.go index 41fca4973..1ad3e9e71 100644 --- a/pkg/apiclient/alerts_service.go +++ b/pkg/apiclient/alerts_service.go @@ -26,6 +26,7 @@ type AlertsListOpts struct { ActiveDecisionEquals *bool `url:"has_active_decision,omitempty"` IncludeCAPI *bool `url:"include_capi,omitempty"` Limit *int `url:"limit,omitempty"` + Contains *bool `url:"contains,omitempty"` ListOpts } @@ -39,6 +40,7 @@ type AlertsDeleteOpts struct { Until *string `url:"until,omitempty"` ActiveDecisionEquals *bool `url:"has_active_decision,omitempty"` SourceEquals *string `url:"alert_source,omitempty"` + Contains *bool `url:"contains,omitempty"` ListOpts } diff --git a/pkg/apiclient/alerts_service_test.go b/pkg/apiclient/alerts_service_test.go index 93cf17c01..53b84e75b 100644 --- a/pkg/apiclient/alerts_service_test.go +++ b/pkg/apiclient/alerts_service_test.go @@ -56,13 +56,11 @@ func TestAlertsListAsMachine(t *testing.T) { {"capacity":5,"created_at":"2020-11-28T10:20:47+01:00", "decisions":[ {"duration":"59m49.264032632s", - "end_ip":16843180, "id":1, "origin":"crowdsec", "scenario":"crowdsecurity/ssh-bf", "scope":"Ip", "simulated":false, - "start_ip":16843180, "type":"ban", "value":"1.1.1.172"} ], @@ -127,14 +125,12 @@ func TestAlertsListAsMachine(t *testing.T) { Decisions: []*models.Decision{ &models.Decision{ Duration: &tduration, - EndIP: 16843180, ID: 1, Origin: &torigin, Scenario: &tscenario, Scope: &tscope, Simulated: new(bool), //false, - StartIP: 16843180, Type: &ttype, Value: &tvalue, }, @@ -328,14 +324,12 @@ func TestAlertsGetAsMachine(t *testing.T) { Decisions: []*models.Decision{ &models.Decision{ Duration: &tduration, - EndIP: 16843180, ID: 1, Origin: &torigin, Scenario: &tscenario, Scope: &tscope, Simulated: new(bool), //false, - StartIP: 16843180, Type: &ttype, Value: &tvalue, }, diff --git a/pkg/apiclient/decisions_service.go b/pkg/apiclient/decisions_service.go index 10d15192e..ab516e357 100644 --- a/pkg/apiclient/decisions_service.go +++ b/pkg/apiclient/decisions_service.go @@ -16,6 +16,8 @@ type DecisionsListOpts struct { TypeEquals *string `url:"type,omitempty"` IPEquals *string `url:"ip,omitempty"` RangeEquals *string `url:"range,omitempty"` + Contains *bool `url:"contains,omitempty"` + ListOpts } @@ -25,6 +27,7 @@ type DecisionsDeleteOpts struct { TypeEquals *string `url:"type,omitempty"` IPEquals *string `url:"ip,omitempty"` RangeEquals *string `url:"range,omitempty"` + Contains *bool `url:"contains,omitempty"` ListOpts } diff --git a/pkg/apiclient/decisions_service_test.go b/pkg/apiclient/decisions_service_test.go index 07cb0180e..7e1dd02d3 100644 --- a/pkg/apiclient/decisions_service_test.go +++ b/pkg/apiclient/decisions_service_test.go @@ -26,7 +26,7 @@ func TestDecisionsList(t *testing.T) { assert.Equal(t, r.URL.RawQuery, "ip=1.2.3.4") assert.Equal(t, r.Header.Get("X-Api-Key"), "ixu") w.WriteHeader(http.StatusOK) - w.Write([]byte(`[{"duration":"3h59m55.756182786s","end_ip":16909060,"id":4,"origin":"cscli","scenario":"manual 'ban' from '82929df7ee394b73b81252fe3b4e50203yaT2u6nXiaN7Ix9'","scope":"Ip","start_ip":16909060,"type":"ban","value":"1.2.3.4"}]`)) + w.Write([]byte(`[{"duration":"3h59m55.756182786s","id":4,"origin":"cscli","scenario":"manual 'ban' from '82929df7ee394b73b81252fe3b4e50203yaT2u6nXiaN7Ix9'","scope":"Ip","type":"ban","value":"1.2.3.4"}]`)) } else { w.WriteHeader(http.StatusOK) w.Write([]byte(`null`)) @@ -57,12 +57,10 @@ func TestDecisionsList(t *testing.T) { expected := &models.GetDecisionsResponse{ &models.Decision{ Duration: &tduration, - EndIP: 16909060, ID: 4, Origin: &torigin, Scenario: &tscenario, Scope: &tscope, - StartIP: 16909060, Type: &ttype, Value: &tvalue, }, @@ -110,7 +108,7 @@ func TestDecisionsStream(t *testing.T) { if r.URL.RawQuery == "startup=true" { w.WriteHeader(http.StatusOK) - w.Write([]byte(`{"deleted":null,"new":[{"duration":"3h59m55.756182786s","end_ip":16909060,"id":4,"origin":"cscli","scenario":"manual 'ban' from '82929df7ee394b73b81252fe3b4e50203yaT2u6nXiaN7Ix9'","scope":"Ip","start_ip":16909060,"type":"ban","value":"1.2.3.4"}]}`)) + w.Write([]byte(`{"deleted":null,"new":[{"duration":"3h59m55.756182786s","id":4,"origin":"cscli","scenario":"manual 'ban' from '82929df7ee394b73b81252fe3b4e50203yaT2u6nXiaN7Ix9'","scope":"Ip","type":"ban","value":"1.2.3.4"}]}`)) } else { w.WriteHeader(http.StatusOK) w.Write([]byte(`{"deleted":null,"new":null}`)) @@ -150,12 +148,10 @@ func TestDecisionsStream(t *testing.T) { New: models.GetDecisionsResponse{ &models.Decision{ Duration: &tduration, - EndIP: 16909060, ID: 4, Origin: &torigin, Scenario: &tscenario, Scope: &tscope, - StartIP: 16909060, Type: &ttype, Value: &tvalue, }, diff --git a/pkg/apiserver/alerts_test.go b/pkg/apiserver/alerts_test.go index 92eeacc68..8522b128a 100644 --- a/pkg/apiserver/alerts_test.go +++ b/pkg/apiserver/alerts_test.go @@ -185,7 +185,7 @@ func TestAlertListFilters(t *testing.T) { assert.Equal(t, 200, w.Code) //check alert and decision assert.Contains(t, w.Body.String(), "Ip 91.121.79.195 performed 'crowdsecurity/ssh-bf' (6 events over ") - assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"start_ip":1534676931,"type":"ban","value":"91.121.79.195"`) + assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"type":"ban","value":"91.121.79.195"`) //test decision_type filter (ok) w = httptest.NewRecorder() @@ -195,7 +195,7 @@ func TestAlertListFilters(t *testing.T) { router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) assert.Contains(t, w.Body.String(), "Ip 91.121.79.195 performed 'crowdsecurity/ssh-bf' (6 events over ") - assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"start_ip":1534676931,"type":"ban","value":"91.121.79.195"`) + assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"type":"ban","value":"91.121.79.195"`) //test decision_type filter (bad value) w = httptest.NewRecorder() @@ -214,7 +214,7 @@ func TestAlertListFilters(t *testing.T) { router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) assert.Contains(t, w.Body.String(), "Ip 91.121.79.195 performed 'crowdsecurity/ssh-bf' (6 events over ") - assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"start_ip":1534676931,"type":"ban","value":"91.121.79.195"`) + assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"type":"ban","value":"91.121.79.195"`) //test scope (bad value) w = httptest.NewRecorder() @@ -233,7 +233,7 @@ func TestAlertListFilters(t *testing.T) { router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) assert.Contains(t, w.Body.String(), "Ip 91.121.79.195 performed 'crowdsecurity/ssh-bf' (6 events over ") - assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"start_ip":1534676931,"type":"ban","value":"91.121.79.195"`) + assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"type":"ban","value":"91.121.79.195"`) //test scenario (bad value) w = httptest.NewRecorder() @@ -252,7 +252,7 @@ func TestAlertListFilters(t *testing.T) { router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) assert.Contains(t, w.Body.String(), "Ip 91.121.79.195 performed 'crowdsecurity/ssh-bf' (6 events over ") - assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"start_ip":1534676931,"type":"ban","value":"91.121.79.195"`) + assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"type":"ban","value":"91.121.79.195"`) //test ip (bad value) w = httptest.NewRecorder() @@ -270,21 +270,21 @@ func TestAlertListFilters(t *testing.T) { req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", loginResp.Token)) router.ServeHTTP(w, req) assert.Equal(t, 500, w.Code) - assert.Equal(t, `{"message":"unable to parse 'gruueq': %!s(\u003cnil\u003e): invalid ip address / range"}`, w.Body.String()) + assert.Equal(t, `{"message":"unable to convert 'gruueq' to int: invalid address: invalid ip address / range"}`, w.Body.String()) //test range (ok) w = httptest.NewRecorder() - req, _ = http.NewRequest("GET", "/v1/alerts?range=91.121.79.0/24", nil) + req, _ = http.NewRequest("GET", "/v1/alerts?range=91.121.79.0/24&contains=false", nil) req.Header.Add("User-Agent", UserAgent) req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", loginResp.Token)) router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) assert.Contains(t, w.Body.String(), "Ip 91.121.79.195 performed 'crowdsecurity/ssh-bf' (6 events over ") - assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"start_ip":1534676931,"type":"ban","value":"91.121.79.195"`) + assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"type":"ban","value":"91.121.79.195"`) //test range w = httptest.NewRecorder() - req, _ = http.NewRequest("GET", "/v1/alerts?range=99.122.77.0/24", nil) + req, _ = http.NewRequest("GET", "/v1/alerts?range=99.122.77.0/24&contains=false", nil) req.Header.Add("User-Agent", UserAgent) req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", loginResp.Token)) router.ServeHTTP(w, req) @@ -298,7 +298,7 @@ func TestAlertListFilters(t *testing.T) { req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", loginResp.Token)) router.ServeHTTP(w, req) assert.Equal(t, 500, w.Code) - assert.Equal(t, `{"message":"unable to convert 'ratata' to int interval: 'ratata' is not a valid CIDR: invalid ip address / range"}`, w.Body.String()) + assert.Equal(t, `{"message":"unable to convert 'ratata' to int: invalid address: invalid ip address / range"}`, w.Body.String()) //test since (ok) w = httptest.NewRecorder() @@ -308,7 +308,7 @@ func TestAlertListFilters(t *testing.T) { router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) assert.Contains(t, w.Body.String(), "Ip 91.121.79.195 performed 'crowdsecurity/ssh-bf' (6 events over ") - assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"start_ip":1534676931,"type":"ban","value":"91.121.79.195"`) + assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"type":"ban","value":"91.121.79.195"`) //test since (ok but yelds no results) w = httptest.NewRecorder() @@ -336,7 +336,7 @@ func TestAlertListFilters(t *testing.T) { router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) assert.Contains(t, w.Body.String(), "Ip 91.121.79.195 performed 'crowdsecurity/ssh-bf' (6 events over ") - assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"start_ip":1534676931,"type":"ban","value":"91.121.79.195"`) + assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"type":"ban","value":"91.121.79.195"`) //test until (ok but no return) w = httptest.NewRecorder() @@ -364,7 +364,7 @@ func TestAlertListFilters(t *testing.T) { router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) assert.Contains(t, w.Body.String(), "Ip 91.121.79.195 performed 'crowdsecurity/ssh-bf' (6 events over ") - assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"start_ip":1534676931,"type":"ban","value":"91.121.79.195"`) + assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"type":"ban","value":"91.121.79.195"`) //test simulated (ok) w = httptest.NewRecorder() @@ -374,7 +374,7 @@ func TestAlertListFilters(t *testing.T) { router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) assert.Contains(t, w.Body.String(), "Ip 91.121.79.195 performed 'crowdsecurity/ssh-bf' (6 events over ") - assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"start_ip":1534676931,"type":"ban","value":"91.121.79.195"`) + assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"type":"ban","value":"91.121.79.195"`) //test has active decision w = httptest.NewRecorder() @@ -384,7 +384,7 @@ func TestAlertListFilters(t *testing.T) { router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) assert.Contains(t, w.Body.String(), "Ip 91.121.79.195 performed 'crowdsecurity/ssh-bf' (6 events over ") - assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"start_ip":1534676931,"type":"ban","value":"91.121.79.195"`) + assert.Contains(t, w.Body.String(), `scope":"Ip","simulated":false,"type":"ban","value":"91.121.79.195"`) //test has active decision w = httptest.NewRecorder() diff --git a/pkg/apiserver/apic.go b/pkg/apiserver/apic.go index 640446dbb..4814adbe9 100644 --- a/pkg/apiserver/apic.go +++ b/pkg/apiserver/apic.go @@ -9,7 +9,6 @@ import ( "time" "github.com/crowdsecurity/crowdsec/pkg/apiclient" - "github.com/crowdsecurity/crowdsec/pkg/apiserver/controllers" "github.com/crowdsecurity/crowdsec/pkg/csconfig" "github.com/crowdsecurity/crowdsec/pkg/cwversion" "github.com/crowdsecurity/crowdsec/pkg/database" @@ -269,28 +268,30 @@ func (a *apic) PullTop() error { // process new decisions for _, decision := range data.New { - /*ensure scope makes sense no matter what consensus gives*/ - if strings.ToLower(*decision.Scope) == "ip" { - *decision.Scope = types.Ip - } else if strings.ToLower(*decision.Scope) == "range" { - *decision.Scope = types.Range + var start_ip, start_sfx, end_ip, end_sfx int64 + var sz int + + /*if the scope is IP or Range, convert the value to integers */ + if strings.ToLower(*decision.Scope) == "ip" || strings.ToLower(*decision.Scope) == "range" { + sz, start_ip, start_sfx, end_ip, end_sfx, err = types.Addr2Ints(*decision.Value) + if err != nil { + return errors.Wrapf(err, "invalid ip/range %s", *decision.Value) + } } duration, err := time.ParseDuration(*decision.Duration) if err != nil { return errors.Wrapf(err, "parse decision duration '%s':", *decision.Duration) } - startIP, endIP, err := controllers.GetIpsFromIpRange(*decision.Value) - if err != nil { - return errors.Wrapf(err, "ip to int '%s':", *decision.Value) - } - _, err = a.dbClient.Ent.Decision.Create(). SetUntil(time.Now().Add(duration)). SetScenario(*decision.Scenario). SetType(*decision.Type). - SetStartIP(startIP). - SetEndIP(endIP). + SetIPSize(int64(sz)). + SetStartIP(start_ip). + SetStartSuffix(start_sfx). + SetEndIP(end_ip). + SetEndSuffix(end_sfx). SetValue(*decision.Value). SetScope(*decision.Scope). SetOrigin(*decision.Origin). diff --git a/pkg/apiserver/controllers/utils.go b/pkg/apiserver/controllers/utils.go deleted file mode 100644 index 1af63478d..000000000 --- a/pkg/apiserver/controllers/utils.go +++ /dev/null @@ -1,65 +0,0 @@ -package controllers - -import ( - "encoding/binary" - "fmt" - "net" -) - -func IP2Int(ip net.IP) uint32 { - if len(ip) == 16 { - return binary.BigEndian.Uint32(ip[12:16]) - } - return binary.BigEndian.Uint32(ip) -} - -func Int2ip(nn uint32) net.IP { - ip := make(net.IP, 4) - binary.BigEndian.PutUint32(ip, nn) - return ip -} - -func IsIpv4(host string) bool { - return net.ParseIP(host) != nil -} - -//Stolen from : https://github.com/llimllib/ipaddress/ -// Return the final address of a net range. Convert to IPv4 if possible, -// otherwise return an ipv6 -func LastAddress(n *net.IPNet) net.IP { - ip := n.IP.To4() - if ip == nil { - ip = n.IP - return net.IP{ - ip[0] | ^n.Mask[0], ip[1] | ^n.Mask[1], ip[2] | ^n.Mask[2], - ip[3] | ^n.Mask[3], ip[4] | ^n.Mask[4], ip[5] | ^n.Mask[5], - ip[6] | ^n.Mask[6], ip[7] | ^n.Mask[7], ip[8] | ^n.Mask[8], - ip[9] | ^n.Mask[9], ip[10] | ^n.Mask[10], ip[11] | ^n.Mask[11], - ip[12] | ^n.Mask[12], ip[13] | ^n.Mask[13], ip[14] | ^n.Mask[14], - ip[15] | ^n.Mask[15]} - } - - return net.IPv4( - ip[0]|^n.Mask[0], - ip[1]|^n.Mask[1], - ip[2]|^n.Mask[2], - ip[3]|^n.Mask[3]) -} - -func GetIpsFromIpRange(host string) (int64, int64, error) { - var ipStart int64 - var ipEnd int64 - var err error - var parsedRange *net.IPNet - - if _, parsedRange, err = net.ParseCIDR(host); err != nil { - return ipStart, ipEnd, fmt.Errorf("'%s' is not a valid CIDR", host) - } - if parsedRange == nil { - return ipStart, ipEnd, fmt.Errorf("unable to parse network : %s", err) - } - ipStart = int64(IP2Int(parsedRange.IP)) - ipEnd = int64(IP2Int(LastAddress(parsedRange))) - - return ipStart, ipEnd, nil -} diff --git a/pkg/apiserver/controllers/v1/alerts.go b/pkg/apiserver/controllers/v1/alerts.go index 9fe3d5837..b24fb25a4 100644 --- a/pkg/apiserver/controllers/v1/alerts.go +++ b/pkg/apiserver/controllers/v1/alerts.go @@ -78,8 +78,6 @@ func FormatOneAlert(alert *ent.Alert) *models.Alert { Duration: &duration, // transform into time.Time ? Scenario: &decisionItem.Scenario, Type: &decisionItem.Type, - StartIP: decisionItem.StartIP, - EndIP: decisionItem.EndIP, Scope: &decisionItem.Scope, Value: &decisionItem.Value, Origin: &decisionItem.Origin, @@ -119,15 +117,7 @@ func (c *Controller) CreateAlert(gctx *gin.Context) { } for _, alert := range input { - if len(alert.Decisions) > 0 { - log.Debugf("alert %s already has decisions, don't apply profiles", *alert.Message) - for _, decision := range alert.Decisions { - if decision.EndIP != 0 && decision.StartIP != 0 && decision.EndIP < decision.StartIP { - gctx.JSON(http.StatusBadRequest, gin.H{"message": "'start_ip' must be lower than or equal to 'end_ip' in decisions"}) - return - } - } - } else { + if len(alert.Decisions) == 0 { decisions, err := csprofiles.EvaluateProfiles(c.Profiles, alert) if err != nil { gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()}) diff --git a/pkg/apiserver/controllers/v1/decisions.go b/pkg/apiserver/controllers/v1/decisions.go index f734291b5..6815e0cbd 100644 --- a/pkg/apiserver/controllers/v1/decisions.go +++ b/pkg/apiserver/controllers/v1/decisions.go @@ -21,8 +21,6 @@ func FormatDecisions(decisions []*ent.Decision) ([]*models.Decision, error) { decision := models.Decision{ ID: int64(dbDecision.ID), Duration: &duration, - EndIP: dbDecision.EndIP, - StartIP: dbDecision.StartIP, Scenario: &dbDecision.Scenario, Scope: &dbDecision.Scope, Value: &dbDecision.Value, diff --git a/pkg/apiserver/decisions_test.go b/pkg/apiserver/decisions_test.go index 7d467005f..dc15cb4f0 100644 --- a/pkg/apiserver/decisions_test.go +++ b/pkg/apiserver/decisions_test.go @@ -58,7 +58,7 @@ func TestDeleteDecisionRange(t *testing.T) { // delete by range w = httptest.NewRecorder() - req, _ = http.NewRequest("DELETE", "/v1/decisions?range=91.121.79.0/24", strings.NewReader("")) + req, _ = http.NewRequest("DELETE", "/v1/decisions?range=91.121.79.0/24&contains=false", strings.NewReader("")) req.Header.Add("User-Agent", UserAgent) req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", loginResp.Token)) router.ServeHTTP(w, req) @@ -179,8 +179,8 @@ func TestGetDecisionFilters(t *testing.T) { req.Header.Add("X-Api-Key", APIKey) router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) - assert.Contains(t, w.Body.String(), `"end_ip":1534676915,"id":1,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","start_ip":1534676915,"type":"ban","value":"91.121.79.179"`) - assert.Contains(t, w.Body.String(), `"end_ip":1534676914,"id":2,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","start_ip":1534676914,"type":"ban","value":"91.121.79.178"`) + assert.Contains(t, w.Body.String(), `"id":1,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","type":"ban","value":"91.121.79.179"`) + assert.Contains(t, w.Body.String(), `"id":2,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","type":"ban","value":"91.121.79.178"`) // Get Decision : type filter w = httptest.NewRecorder() @@ -189,8 +189,8 @@ func TestGetDecisionFilters(t *testing.T) { req.Header.Add("X-Api-Key", APIKey) router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) - assert.Contains(t, w.Body.String(), `"end_ip":1534676915,"id":1,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","start_ip":1534676915,"type":"ban","value":"91.121.79.179"`) - assert.Contains(t, w.Body.String(), `"end_ip":1534676914,"id":2,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","start_ip":1534676914,"type":"ban","value":"91.121.79.178"`) + assert.Contains(t, w.Body.String(), `"id":1,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","type":"ban","value":"91.121.79.179"`) + assert.Contains(t, w.Body.String(), `"id":2,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","type":"ban","value":"91.121.79.178"`) // Get Decision : scope/value w = httptest.NewRecorder() @@ -199,8 +199,8 @@ func TestGetDecisionFilters(t *testing.T) { req.Header.Add("X-Api-Key", APIKey) router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) - assert.Contains(t, w.Body.String(), `"end_ip":1534676915,"id":1,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","start_ip":1534676915,"type":"ban","value":"91.121.79.179"`) - assert.NotContains(t, w.Body.String(), `"end_ip":1534676914,"id":2,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","start_ip":1534676914,"type":"ban","value":"91.121.79.178"`) + assert.Contains(t, w.Body.String(), `"id":1,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","type":"ban","value":"91.121.79.179"`) + assert.NotContains(t, w.Body.String(), `"id":2,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","type":"ban","value":"91.121.79.178"`) // Get Decision : ip filter w = httptest.NewRecorder() @@ -209,18 +209,18 @@ func TestGetDecisionFilters(t *testing.T) { req.Header.Add("X-Api-Key", APIKey) router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) - assert.Contains(t, w.Body.String(), `"end_ip":1534676915,"id":1,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","start_ip":1534676915,"type":"ban","value":"91.121.79.179"`) - assert.NotContains(t, w.Body.String(), `"end_ip":1534676914,"id":2,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","start_ip":1534676914,"type":"ban","value":"91.121.79.178"`) + assert.Contains(t, w.Body.String(), `"id":1,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","type":"ban","value":"91.121.79.179"`) + assert.NotContains(t, w.Body.String(), `"id":2,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","type":"ban","value":"91.121.79.178"`) // Get decision : by range w = httptest.NewRecorder() - req, _ = http.NewRequest("GET", "/v1/decisions?range=91.121.79.0/24", strings.NewReader("")) + req, _ = http.NewRequest("GET", "/v1/decisions?range=91.121.79.0/24&contains=false", strings.NewReader("")) req.Header.Add("User-Agent", UserAgent) req.Header.Add("X-Api-Key", APIKey) router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) - assert.Contains(t, w.Body.String(), `"end_ip":1534676915,"id":1,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","start_ip":1534676915,"type":"ban","value":"91.121.79.179"`) - assert.Contains(t, w.Body.String(), `"end_ip":1534676914,"id":2,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","start_ip":1534676914,"type":"ban","value":"91.121.79.178"`) + assert.Contains(t, w.Body.String(), `"id":1,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","type":"ban","value":"91.121.79.179"`) + assert.Contains(t, w.Body.String(), `"id":2,"origin":"crowdsec","scenario":"crowdsecurity/ssh-bf","scope":"Ip","type":"ban","value":"91.121.79.178"`) } func TestGetDecision(t *testing.T) { @@ -277,7 +277,7 @@ func TestGetDecision(t *testing.T) { router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) - assert.Contains(t, w.Body.String(), "\"end_ip\":2130706433,\"id\":1,\"origin\":\"test\",\"scenario\":\"crowdsecurity/test\",\"scope\":\"ip\",\"start_ip\":2130706433,\"type\":\"ban\",\"value\":\"127.0.0.1\"}]") + assert.Contains(t, w.Body.String(), "\"id\":1,\"origin\":\"test\",\"scenario\":\"crowdsecurity/test\",\"scope\":\"ip\",\"type\":\"ban\",\"value\":\"127.0.0.1\"}]") } @@ -449,5 +449,5 @@ func TestStreamDecision(t *testing.T) { router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) - assert.Contains(t, w.Body.String(), "\"end_ip\":2130706433,\"id\":1,\"origin\":\"test\",\"scenario\":\"crowdsecurity/test\",\"scope\":\"ip\",\"start_ip\":2130706433,\"type\":\"ban\",\"value\":\"127.0.0.1\"}]}") + assert.Contains(t, w.Body.String(), "\"id\":1,\"origin\":\"test\",\"scenario\":\"crowdsecurity/test\",\"scope\":\"ip\",\"type\":\"ban\",\"value\":\"127.0.0.1\"}]}") } diff --git a/pkg/apiserver/tests/alertWithInvalidMachineID_sample.json b/pkg/apiserver/tests/alertWithInvalidMachineID_sample.json index ecc937480..65ea45aa6 100644 --- a/pkg/apiserver/tests/alertWithInvalidMachineID_sample.json +++ b/pkg/apiserver/tests/alertWithInvalidMachineID_sample.json @@ -8,8 +8,6 @@ { "id": 1, "duration": "1h", - "start_ip": 2130706433, - "end_ip": 2130706433, "origin": "test", "scenario": "crowdsecurity/test", "scope": "ip", diff --git a/pkg/apiserver/tests/alert_sample.json b/pkg/apiserver/tests/alert_sample.json index d76396197..1abecb447 100644 --- a/pkg/apiserver/tests/alert_sample.json +++ b/pkg/apiserver/tests/alert_sample.json @@ -8,8 +8,6 @@ { "id": 1, "duration": "1h", - "start_ip": 2130706433, - "end_ip": 2130706433, "origin": "test", "scenario": "crowdsecurity/test", "scope": "ip", diff --git a/pkg/apiserver/tests/invalidAlert_sample.json b/pkg/apiserver/tests/invalidAlert_sample.json index 84c26a81e..aac313135 100644 --- a/pkg/apiserver/tests/invalidAlert_sample.json +++ b/pkg/apiserver/tests/invalidAlert_sample.json @@ -7,8 +7,6 @@ { "id": 1, "duration": "1h", - "start_ip": 2130706433, - "end_ip": 2130706433, "origin": "test", "scenario": "crowdsecurity/test", "scope": "ip", diff --git a/pkg/apiserver/utils_test.go b/pkg/apiserver/utils_test.go deleted file mode 100644 index f5bd08223..000000000 --- a/pkg/apiserver/utils_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package apiserver - -import ( - "net" - "testing" - - "github.com/crowdsecurity/crowdsec/pkg/apiserver/controllers" - log "github.com/sirupsen/logrus" - - "github.com/stretchr/testify/assert" -) - -func TestIP2Int(t *testing.T) { - ipInt := controllers.IP2Int(net.ParseIP("127.0.0.1")) - assert.Equal(t, uint32(2130706433), ipInt) - - ipInt = controllers.IP2Int([]byte{127, 0, 0, 1}) - assert.Equal(t, uint32(2130706433), ipInt) -} - -func TestInt2IP(t *testing.T) { - IP := controllers.Int2ip(uint32(2130706433)) - assert.Equal(t, "127.0.0.1", IP.String()) -} - -func TestIsIPv4(t *testing.T) { - IsIpv4 := controllers.IsIpv4("127.0.0.1") - assert.Equal(t, true, IsIpv4) - - IsIpv4 = controllers.IsIpv4("127.0.0") - assert.Equal(t, false, IsIpv4) -} - -func TestLastAddress(t *testing.T) { - _, ipv4Net, err := net.ParseCIDR("192.168.0.1/24") - if err != nil { - log.Fatal(err) - } - - lastAddress := controllers.LastAddress(ipv4Net) - assert.Equal(t, "192.168.0.255", lastAddress.String()) -} - -func TestGetIpsFromIpRange(t *testing.T) { - IPStart, IPEnd, err := controllers.GetIpsFromIpRange("192.168.0.1/65") - assert.Equal(t, "'192.168.0.1/65' is not a valid CIDR", err.Error()) - assert.Equal(t, int64(0), IPStart) - assert.Equal(t, int64(0), IPEnd) - - IPStart, IPEnd, err = controllers.GetIpsFromIpRange("192.168.0.1/24") - assert.Equal(t, nil, err) - assert.Equal(t, int64(3232235520), IPStart) - assert.Equal(t, int64(3232235775), IPEnd) -} diff --git a/pkg/csprofiles/csprofiles.go b/pkg/csprofiles/csprofiles.go index 7d816c74f..c5b72e795 100644 --- a/pkg/csprofiles/csprofiles.go +++ b/pkg/csprofiles/csprofiles.go @@ -2,8 +2,6 @@ package csprofiles import ( "fmt" - "net" - "strings" "github.com/antonmedv/expr" "github.com/crowdsecurity/crowdsec/pkg/csconfig" @@ -45,37 +43,6 @@ func GenerateDecisionFromProfile(Profile *csconfig.ProfileCfg, Alert *models.Ale /*for the others, let's populate it from the alert and its source*/ decision.Value = new(string) *decision.Value = *Alert.Source.Value - - if strings.EqualFold(*decision.Scope, types.Ip) { - srcAddr := net.ParseIP(Alert.Source.IP) - if srcAddr == nil { - return nil, fmt.Errorf("can't parse ip %s", Alert.Source.IP) - } - decision.StartIP = int64(types.IP2Int(srcAddr)) - decision.EndIP = decision.StartIP - } else if strings.EqualFold(*decision.Scope, types.Range) { - - /*here we're asked to ban a full range. let's keep in mind that it's not always possible : - - the alert is about an IP, but the geolite enrichment failed - - the alert is about an IP, but the geolite enrichment isn't present - - the alert is about a range, in this case it should succeed - */ - if Alert.Source.Range != "" { - srcAddr, srcRange, err := net.ParseCIDR(Alert.Source.Range) - if err != nil { - log.Warningf("Profile [%s] requires IP decision, but can't parse '%s' from '%s'", - Profile.Name, *Alert.Source.Value, *Alert.Scenario) - continue - } - decision.StartIP = int64(types.IP2Int(srcAddr)) - decision.EndIP = int64(types.IP2Int(types.LastAddress(srcRange))) - decision.Value = new(string) - *decision.Value = Alert.Source.Range - } else { - log.Warningf("Profile [%s] requires scope decision, but information is missing from %s", Profile.Name, *Alert.Scenario) - continue - } - } decision.Origin = new(string) *decision.Origin = "crowdsec" if refDecision.Origin != nil { diff --git a/pkg/database/alerts.go b/pkg/database/alerts.go index 04c4d61ab..90e70a9e4 100644 --- a/pkg/database/alerts.go +++ b/pkg/database/alerts.go @@ -191,17 +191,30 @@ func (c *Client) CreateAlertBulk(machineId string, alertList []*models.Alert) ([ if len(alertItem.Decisions) > 0 { decisionBulk := make([]*ent.DecisionCreate, len(alertItem.Decisions)) for i, decisionItem := range alertItem.Decisions { + var start_ip, start_sfx, end_ip, end_sfx int64 + var sz int duration, err := time.ParseDuration(*decisionItem.Duration) if err != nil { return []string{}, errors.Wrapf(ParseDurationFail, "decision duration '%v' : %s", decisionItem.Duration, err) } + + /*if the scope is IP or Range, convert the value to integers */ + if strings.ToLower(*decisionItem.Scope) == "ip" || strings.ToLower(*decisionItem.Scope) == "range" { + sz, start_ip, start_sfx, end_ip, end_sfx, err = types.Addr2Ints(*decisionItem.Value) + if err != nil { + return []string{}, errors.Wrapf(ParseDurationFail, "invalid addr/range %s : %s", *decisionItem.Value, err) + } + } decisionBulk[i] = c.Ent.Decision.Create(). SetUntil(ts.Add(duration)). SetScenario(*decisionItem.Scenario). SetType(*decisionItem.Type). - SetStartIP(decisionItem.StartIP). - SetEndIP(decisionItem.EndIP). + SetStartIP(start_ip). + SetStartSuffix(start_sfx). + SetEndIP(end_ip). + SetEndSuffix(end_sfx). + SetIPSize(int64(sz)). SetValue(*decisionItem.Value). SetScope(*decisionItem.Scope). SetOrigin(*decisionItem.Origin). @@ -275,8 +288,12 @@ func (c *Client) CreateAlertBulk(machineId string, alertList []*models.Alert) ([ func BuildAlertRequestFromFilter(alerts *ent.AlertQuery, filter map[string][]string) (*ent.AlertQuery, error) { var err error - var startIP, endIP int64 + var start_ip, start_sfx, end_ip, end_sfx int64 var hasActiveDecision bool + var ip_sz int + var contains bool = true + /*if contains is true, return bans that *contains* the given value (value is the inner) + else, return bans that are *contained* by the given value (value is the outer)*/ /*the simulated filter is a bit different : if it's not present *or* set to false, specifically exclude records with simulated to true */ if v, ok := filter["simulated"]; ok { @@ -288,6 +305,11 @@ func BuildAlertRequestFromFilter(alerts *ent.AlertQuery, filter map[string][]str for param, value := range filter { switch param { + case "contains": + contains, err = strconv.ParseBool(value[0]) + if err != nil { + return nil, errors.Wrapf(InvalidFilter, "invalid contains value : %s", err) + } case "scope": var scope string = value[0] if strings.ToLower(scope) == "ip" { @@ -300,19 +322,10 @@ func BuildAlertRequestFromFilter(alerts *ent.AlertQuery, filter map[string][]str alerts = alerts.Where(alert.SourceValueEQ(value[0])) case "scenario": alerts = alerts.Where(alert.ScenarioEQ(value[0])) - case "ip": - isValidIP := IsIpv4(value[0]) - if !isValidIP { - return nil, errors.Wrapf(InvalidIPOrRange, "unable to parse '%s': %s", value[0], err) - } - startIP, endIP, err = GetIpsFromIpRange(value[0] + "/32") + case "ip", "range": + ip_sz, start_ip, start_sfx, end_ip, end_sfx, err = types.Addr2Ints(value[0]) if err != nil { - return nil, errors.Wrapf(InvalidIPOrRange, "unable to convert '%s' to int interval: %s", value[0], err) - } - case "range": - startIP, endIP, err = GetIpsFromIpRange(value[0]) - if err != nil { - return nil, errors.Wrapf(InvalidIPOrRange, "unable to convert '%s' to int interval: %s", value[0], err) + return nil, errors.Wrapf(InvalidIPOrRange, "unable to convert '%s' to int: %s", value[0], err) } case "since": duration, err := types.ParseDuration(value[0]) @@ -369,21 +382,74 @@ func BuildAlertRequestFromFilter(alerts *ent.AlertQuery, filter map[string][]str return nil, errors.Wrapf(InvalidFilter, "Filter parameter '%s' is unknown (=%s)", param, value[0]) } } - if startIP != 0 && endIP != 0 { - /*the user is checking for a single IP*/ - if startIP == endIP { - //DECISION_START <= IP_Q >= DECISON_END + + if ip_sz == 4 { + if contains { /*decision contains {start_ip,end_ip}*/ alerts = alerts.Where(alert.And( - alert.HasDecisionsWith(decision.StartIPLTE(startIP)), - alert.HasDecisionsWith(decision.EndIPGTE(endIP)), + alert.HasDecisionsWith(decision.StartIPLTE(start_ip)), + alert.HasDecisionsWith(decision.EndIPGTE(end_ip)), + alert.HasDecisionsWith(decision.IPSizeEQ(int64(ip_sz))), )) - } else { /*the user is checking for a RANGE */ - //START_Q >= DECISION_START AND END_Q <= DECISION_END + } else { /*decision is contained within {start_ip,end_ip}*/ alerts = alerts.Where(alert.And( - alert.HasDecisionsWith(decision.StartIPGTE(startIP)), - alert.HasDecisionsWith(decision.EndIPLTE(endIP)), + alert.HasDecisionsWith(decision.StartIPGTE(start_ip)), + alert.HasDecisionsWith(decision.EndIPLTE(end_ip)), + alert.HasDecisionsWith(decision.IPSizeEQ(int64(ip_sz))), )) } + } else if ip_sz == 16 { + + if contains { /*decision contains {start_ip,end_ip}*/ + alerts = alerts.Where(alert.And( + //matching addr size + alert.HasDecisionsWith(decision.IPSizeEQ(int64(ip_sz))), + alert.Or( + //decision.start_ip < query.start_ip + alert.HasDecisionsWith(decision.StartIPLT(start_ip)), + alert.And( + //decision.start_ip == query.start_ip + alert.HasDecisionsWith(decision.StartIPEQ(start_ip)), + //decision.start_suffix <= query.start_suffix + alert.HasDecisionsWith(decision.StartSuffixLTE(start_sfx)), + )), + alert.Or( + //decision.end_ip > query.end_ip + alert.HasDecisionsWith(decision.EndIPGT(end_ip)), + alert.And( + //decision.end_ip == query.end_ip + alert.HasDecisionsWith(decision.EndIPEQ(end_ip)), + //decision.end_suffix >= query.end_suffix + alert.HasDecisionsWith(decision.EndSuffixGTE(end_sfx)), + ), + ), + )) + } else { /*decision is contained within {start_ip,end_ip}*/ + alerts = alerts.Where(alert.And( + //matching addr size + alert.HasDecisionsWith(decision.IPSizeEQ(int64(ip_sz))), + alert.Or( + //decision.start_ip > query.start_ip + alert.HasDecisionsWith(decision.StartIPGT(start_ip)), + alert.And( + //decision.start_ip == query.start_ip + alert.HasDecisionsWith(decision.StartIPEQ(start_ip)), + //decision.start_suffix >= query.start_suffix + alert.HasDecisionsWith(decision.StartSuffixGTE(start_sfx)), + )), + alert.Or( + //decision.end_ip < query.end_ip + alert.HasDecisionsWith(decision.EndIPLT(end_ip)), + alert.And( + //decision.end_ip == query.end_ip + alert.HasDecisionsWith(decision.EndIPEQ(end_ip)), + //decision.end_suffix <= query.end_suffix + alert.HasDecisionsWith(decision.EndSuffixLTE(end_sfx)), + ), + ), + )) + } + } else if ip_sz != 0 { + return nil, errors.Wrapf(InvalidFilter, "Unknown ip size %d", ip_sz) } return alerts, nil } diff --git a/pkg/database/decisions.go b/pkg/database/decisions.go index 338677060..f32c55fb9 100644 --- a/pkg/database/decisions.go +++ b/pkg/database/decisions.go @@ -15,8 +15,14 @@ import ( ) func BuildDecisionRequestWithFilter(query *ent.DecisionQuery, filter map[string][]string) (*ent.DecisionQuery, error) { + + //func BuildDecisionRequestWithFilter(query *ent.Query, filter map[string][]string) (*ent.DecisionQuery, error) { var err error - var startIP, endIP int64 + var start_ip, start_sfx, end_ip, end_sfx int64 + var ip_sz int + var contains bool = true + /*if contains is true, return bans that *contains* the given value (value is the inner) + else, return bans that are *contained* by the given value (value is the outer)*/ /*the simulated filter is a bit different : if it's not present *or* set to false, specifically exclude records with simulated to true */ if v, ok := filter["simulated"]; ok { @@ -30,6 +36,11 @@ func BuildDecisionRequestWithFilter(query *ent.DecisionQuery, filter map[string] for param, value := range filter { switch param { + case "contains": + contains, err = strconv.ParseBool(value[0]) + if err != nil { + return nil, errors.Wrapf(InvalidFilter, "invalid contains value : %s", err) + } case "scope": var scope string = value[0] if strings.ToLower(scope) == "ip" { @@ -42,40 +53,84 @@ func BuildDecisionRequestWithFilter(query *ent.DecisionQuery, filter map[string] query = query.Where(decision.ValueEQ(value[0])) case "type": query = query.Where(decision.TypeEQ(value[0])) - case "ip": - isValidIP := IsIpv4(value[0]) - if !isValidIP { - return nil, errors.Wrapf(InvalidIPOrRange, "unable to parse '%s': %s", value[0], err) - } - startIP, endIP, err = GetIpsFromIpRange(value[0] + "/32") + case "ip", "range": + ip_sz, start_ip, start_sfx, end_ip, end_sfx, err = types.Addr2Ints(value[0]) if err != nil { - return nil, errors.Wrapf(InvalidIPOrRange, "unable to convert '%s' to int interval: %s", value[0], err) - } - case "range": - startIP, endIP, err = GetIpsFromIpRange(value[0]) - if err != nil { - return nil, errors.Wrapf(InvalidIPOrRange, "unable to convert '%s' to int interval: %s", value[0], err) + return nil, errors.Wrapf(InvalidIPOrRange, "unable to convert '%s' to int: %s", value[0], err) } default: return query, errors.Wrapf(InvalidFilter, "'%s' doesn't exist", param) } } - if startIP != 0 && endIP != 0 { - /*the user is checking for a single IP*/ - if startIP == endIP { - //DECISION_START <= IP_Q >= DECISON_END + if ip_sz == 4 { + + if contains { /*decision contains {start_ip,end_ip}*/ query = query.Where(decision.And( - decision.StartIPLTE(startIP), - decision.EndIPGTE(endIP), + decision.StartIPLTE(start_ip), + decision.EndIPGTE(end_ip), + decision.IPSizeEQ(int64(ip_sz)), )) - } else { /*the user is checking for a RANGE */ - //START_Q >= DECISION_START AND END_Q <= DECISION_END + } else { /*decision is contained within {start_ip,end_ip}*/ query = query.Where(decision.And( - decision.StartIPGTE(startIP), - decision.EndIPLTE(endIP), + decision.StartIPGTE(start_ip), + decision.EndIPLTE(end_ip), + decision.IPSizeEQ(int64(ip_sz)), )) } + } else if ip_sz == 16 { + + if contains { /*decision contains {start_ip,end_ip}*/ + query = query.Where(decision.And( + //matching addr size + decision.IPSizeEQ(int64(ip_sz)), + decision.Or( + //decision.start_ip < query.start_ip + decision.StartIPLT(start_ip), + decision.And( + //decision.start_ip == query.start_ip + decision.StartIPEQ(start_ip), + //decision.start_suffix <= query.start_suffix + decision.StartSuffixLTE(start_sfx), + )), + decision.Or( + //decision.end_ip > query.end_ip + decision.EndIPGT(end_ip), + decision.And( + //decision.end_ip == query.end_ip + decision.EndIPEQ(end_ip), + //decision.end_suffix >= query.end_suffix + decision.EndSuffixGTE(end_sfx), + ), + ), + )) + } else { /*decision is contained {start_ip,end_ip}*/ + query = query.Where(decision.And( + //matching addr size + decision.IPSizeEQ(int64(ip_sz)), + decision.Or( + //decision.start_ip > query.start_ip + decision.StartIPGT(start_ip), + decision.And( + //decision.start_ip == query.start_ip + decision.StartIPEQ(start_ip), + //decision.start_suffix >= query.start_suffix + decision.StartSuffixGTE(start_sfx), + )), + decision.Or( + //decision.end_ip < query.end_ip + decision.EndIPLT(end_ip), + decision.And( + //decision.end_ip == query.end_ip + decision.EndIPEQ(end_ip), + //decision.end_suffix <= query.end_suffix + decision.EndSuffixLTE(end_sfx), + ), + ), + )) + } + } else if ip_sz != 0 { + return nil, errors.Wrapf(InvalidFilter, "Unknown ip size %d", ip_sz) } return query, nil } @@ -158,52 +213,101 @@ func (c *Client) DeleteDecisionById(decisionId int) error { func (c *Client) DeleteDecisionsWithFilter(filter map[string][]string) (string, error) { var err error - var startIP, endIP int64 + var start_ip, start_sfx, end_ip, end_sfx int64 + var ip_sz int + var contains bool = true + /*if contains is true, return bans that *contains* the given value (value is the inner) + else, return bans that are *contained* by the given value (value is the outer) */ decisions := c.Ent.Decision.Delete() - for param, value := range filter { switch param { + case "contains": + contains, err = strconv.ParseBool(value[0]) + if err != nil { + return "0", errors.Wrapf(InvalidFilter, "invalid contains value : %s", err) + } case "scope": decisions = decisions.Where(decision.ScopeEQ(value[0])) case "value": decisions = decisions.Where(decision.ValueEQ(value[0])) case "type": decisions = decisions.Where(decision.TypeEQ(value[0])) - case "ip": - isValidIP := IsIpv4(value[0]) - if !isValidIP { - return "0", errors.Wrap(InvalidIPOrRange, fmt.Sprintf("unable to parse '%s': %s", value[0], err)) - } - startIP, endIP, err = GetIpsFromIpRange(value[0] + "/32") + case "ip", "range": + ip_sz, start_ip, start_sfx, end_ip, end_sfx, err = types.Addr2Ints(value[0]) if err != nil { - return "0", errors.Wrap(InvalidIPOrRange, fmt.Sprintf("unable to convert '%s' to int interval: %s", value[0], err)) - } - case "range": - startIP, endIP, err = GetIpsFromIpRange(value[0]) - if err != nil { - return "0", errors.Wrap(InvalidIPOrRange, fmt.Sprintf("unable to convert '%s' to int interval: %s", value[0], err)) + return "0", errors.Wrapf(InvalidIPOrRange, "unable to convert '%s' to int: %s", value[0], err) } default: return "0", errors.Wrap(InvalidFilter, fmt.Sprintf("'%s' doesn't exist", param)) } - - if startIP != 0 && endIP != 0 { - /*the user is checking for a single IP*/ - if startIP == endIP { - //DECISION_START <= IP_Q >= DECISON_END - decisions = decisions.Where(decision.And( - decision.StartIPLTE(startIP), - decision.EndIPGTE(endIP), - )) - } else { /*the user is checking for a RANGE */ - //START_Q >= DECISION_START AND END_Q <= DECISION_END - decisions = decisions.Where(decision.And( - decision.StartIPGTE(startIP), - decision.EndIPLTE(endIP), - )) - } + } + if ip_sz == 4 { + if contains { /*decision contains {start_ip,end_ip}*/ + decisions = decisions.Where(decision.And( + decision.StartIPLTE(start_ip), + decision.EndIPGTE(end_ip), + decision.IPSizeEQ(int64(ip_sz)), + )) + } else { /*decision is contained within {start_ip,end_ip}*/ + decisions = decisions.Where(decision.And( + decision.StartIPGTE(start_ip), + decision.EndIPLTE(end_ip), + decision.IPSizeEQ(int64(ip_sz)), + )) } + } else if ip_sz == 16 { + if contains { /*decision contains {start_ip,end_ip}*/ + decisions = decisions.Where(decision.And( + //matching addr size + decision.IPSizeEQ(int64(ip_sz)), + decision.Or( + //decision.start_ip < query.start_ip + decision.StartIPLT(start_ip), + decision.And( + //decision.start_ip == query.start_ip + decision.StartIPEQ(start_ip), + //decision.start_suffix <= query.start_suffix + decision.StartSuffixLTE(start_sfx), + )), + decision.Or( + //decision.end_ip > query.end_ip + decision.EndIPGT(end_ip), + decision.And( + //decision.end_ip == query.end_ip + decision.EndIPEQ(end_ip), + //decision.end_suffix >= query.end_suffix + decision.EndSuffixGTE(end_sfx), + ), + ), + )) + } else { + decisions = decisions.Where(decision.And( + //matching addr size + decision.IPSizeEQ(int64(ip_sz)), + decision.Or( + //decision.start_ip > query.start_ip + decision.StartIPGT(start_ip), + decision.And( + //decision.start_ip == query.start_ip + decision.StartIPEQ(start_ip), + //decision.start_suffix >= query.start_suffix + decision.StartSuffixGTE(start_sfx), + )), + decision.Or( + //decision.end_ip < query.end_ip + decision.EndIPLT(end_ip), + decision.And( + //decision.end_ip == query.end_ip + decision.EndIPEQ(end_ip), + //decision.end_suffix <= query.end_suffix + decision.EndSuffixLTE(end_sfx), + ), + ), + )) + } + } else if ip_sz != 0 { + return "0", errors.Wrapf(InvalidFilter, "Unknown ip size %d", ip_sz) } nbDeleted, err := decisions.Exec(c.CTX) @@ -217,51 +321,104 @@ func (c *Client) DeleteDecisionsWithFilter(filter map[string][]string) (string, // SoftDeleteDecisionsWithFilter udpate the expiration time to now() for the decisions matching the filter func (c *Client) SoftDeleteDecisionsWithFilter(filter map[string][]string) (string, error) { var err error - var startIP, endIP int64 - + var start_ip, start_sfx, end_ip, end_sfx int64 + var ip_sz int + var contains bool = true + /*if contains is true, return bans that *contains* the given value (value is the inner) + else, return bans that are *contained* by the given value (value is the outer)*/ decisions := c.Ent.Decision.Update().Where(decision.UntilGT(time.Now())) for param, value := range filter { switch param { + case "contains": + contains, err = strconv.ParseBool(value[0]) + if err != nil { + return "0", errors.Wrapf(InvalidFilter, "invalid contains value : %s", err) + } case "scope": decisions = decisions.Where(decision.ScopeEQ(value[0])) case "value": decisions = decisions.Where(decision.ValueEQ(value[0])) case "type": decisions = decisions.Where(decision.TypeEQ(value[0])) - case "ip": - isValidIP := IsIpv4(value[0]) - if !isValidIP { - return "0", errors.Wrapf(InvalidIPOrRange, "unable to parse '%s': %s", value[0], err) - } - startIP, endIP, err = GetIpsFromIpRange(value[0] + "/32") + case "ip", "range": + ip_sz, start_ip, start_sfx, end_ip, end_sfx, err = types.Addr2Ints(value[0]) if err != nil { - return "0", errors.Wrapf(InvalidIPOrRange, "unable to convert '%s' to int interval: %s", value[0], err) - } - case "range": - startIP, endIP, err = GetIpsFromIpRange(value[0]) - if err != nil { - return "0", errors.Wrapf(InvalidIPOrRange, "unable to convert '%s' to int interval: %s", value[0], err) + return "0", errors.Wrapf(InvalidIPOrRange, "unable to convert '%s' to int: %s", value[0], err) } default: return "0", errors.Wrapf(InvalidFilter, "'%s' doesn't exist", param) } - - if startIP != 0 && endIP != 0 { - /*the user is checking for a single IP*/ - if startIP == endIP { - //DECISION_START <= IP_Q >= DECISON_END - decisions = decisions.Where(decision.And( - decision.StartIPLTE(startIP), - decision.EndIPGTE(endIP), - )) - } else { /*the user is checking for a RANGE */ - //START_Q >= DECISION_START AND END_Q <= DECISION_END - decisions = decisions.Where(decision.And( - decision.StartIPGTE(startIP), - decision.EndIPLTE(endIP), - )) - } + } + if ip_sz == 4 { + if contains { + /*Decision contains {start_ip,end_ip}*/ + decisions = decisions.Where(decision.And( + decision.StartIPLTE(start_ip), + decision.EndIPGTE(end_ip), + decision.IPSizeEQ(int64(ip_sz)), + )) + } else { + /*Decision is contained within {start_ip,end_ip}*/ + decisions = decisions.Where(decision.And( + decision.StartIPGTE(start_ip), + decision.EndIPLTE(end_ip), + decision.IPSizeEQ(int64(ip_sz)), + )) } + } else if ip_sz == 16 { + /*decision contains {start_ip,end_ip}*/ + if contains { + decisions = decisions.Where(decision.And( + //matching addr size + decision.IPSizeEQ(int64(ip_sz)), + decision.Or( + //decision.start_ip < query.start_ip + decision.StartIPLT(start_ip), + decision.And( + //decision.start_ip == query.start_ip + decision.StartIPEQ(start_ip), + //decision.start_suffix <= query.start_suffix + decision.StartSuffixLTE(start_sfx), + )), + decision.Or( + //decision.end_ip > query.end_ip + decision.EndIPGT(end_ip), + decision.And( + //decision.end_ip == query.end_ip + decision.EndIPEQ(end_ip), + //decision.end_suffix >= query.end_suffix + decision.EndSuffixGTE(end_sfx), + ), + ), + )) + } else { + /*decision is contained within {start_ip,end_ip}*/ + decisions = decisions.Where(decision.And( + //matching addr size + decision.IPSizeEQ(int64(ip_sz)), + decision.Or( + //decision.start_ip > query.start_ip + decision.StartIPGT(start_ip), + decision.And( + //decision.start_ip == query.start_ip + decision.StartIPEQ(start_ip), + //decision.start_suffix >= query.start_suffix + decision.StartSuffixGTE(start_sfx), + )), + decision.Or( + //decision.end_ip < query.end_ip + decision.EndIPLT(end_ip), + decision.And( + //decision.end_ip == query.end_ip + decision.EndIPEQ(end_ip), + //decision.end_suffix <= query.end_suffix + decision.EndSuffixLTE(end_sfx), + ), + ), + )) + } + } else if ip_sz != 0 { + return "0", errors.Wrapf(InvalidFilter, "Unknown ip size %d", ip_sz) } nbDeleted, err := decisions.SetUntil(time.Now()).Save(c.CTX) if err != nil { diff --git a/pkg/database/ent/alert.go b/pkg/database/ent/alert.go index b9656345e..832b3c8ad 100644 --- a/pkg/database/ent/alert.go +++ b/pkg/database/ent/alert.go @@ -124,204 +124,216 @@ func (e AlertEdges) MetasOrErr() ([]*Meta, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*Alert) scanValues() []interface{} { - return []interface{}{ - &sql.NullInt64{}, // id - &sql.NullTime{}, // created_at - &sql.NullTime{}, // updated_at - &sql.NullString{}, // scenario - &sql.NullString{}, // bucketId - &sql.NullString{}, // message - &sql.NullInt64{}, // eventsCount - &sql.NullTime{}, // startedAt - &sql.NullTime{}, // stoppedAt - &sql.NullString{}, // sourceIp - &sql.NullString{}, // sourceRange - &sql.NullString{}, // sourceAsNumber - &sql.NullString{}, // sourceAsName - &sql.NullString{}, // sourceCountry - &sql.NullFloat64{}, // sourceLatitude - &sql.NullFloat64{}, // sourceLongitude - &sql.NullString{}, // sourceScope - &sql.NullString{}, // sourceValue - &sql.NullInt64{}, // capacity - &sql.NullString{}, // leakSpeed - &sql.NullString{}, // scenarioVersion - &sql.NullString{}, // scenarioHash - &sql.NullBool{}, // simulated - } -} - -// fkValues returns the types for scanning foreign-keys values from sql.Rows. -func (*Alert) fkValues() []interface{} { - return []interface{}{ - &sql.NullInt64{}, // machine_alerts +func (*Alert) scanValues(columns []string) ([]interface{}, error) { + values := make([]interface{}, len(columns)) + for i := range columns { + switch columns[i] { + case alert.FieldSimulated: + values[i] = &sql.NullBool{} + case alert.FieldSourceLatitude, alert.FieldSourceLongitude: + values[i] = &sql.NullFloat64{} + case alert.FieldID, alert.FieldEventsCount, alert.FieldCapacity: + values[i] = &sql.NullInt64{} + case alert.FieldScenario, alert.FieldBucketId, alert.FieldMessage, alert.FieldSourceIp, alert.FieldSourceRange, alert.FieldSourceAsNumber, alert.FieldSourceAsName, alert.FieldSourceCountry, alert.FieldSourceScope, alert.FieldSourceValue, alert.FieldLeakSpeed, alert.FieldScenarioVersion, alert.FieldScenarioHash: + values[i] = &sql.NullString{} + case alert.FieldCreatedAt, alert.FieldUpdatedAt, alert.FieldStartedAt, alert.FieldStoppedAt: + values[i] = &sql.NullTime{} + case alert.ForeignKeys[0]: // machine_alerts + values[i] = &sql.NullInt64{} + default: + return nil, fmt.Errorf("unexpected column %q for type Alert", columns[i]) + } } + return values, nil } // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Alert fields. -func (a *Alert) assignValues(values ...interface{}) error { - if m, n := len(values), len(alert.Columns); m < n { +func (a *Alert) 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) } - value, ok := values[0].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - a.ID = int(value.Int64) - values = values[1:] - if value, ok := values[0].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[0]) - } else if value.Valid { - a.CreatedAt = value.Time - } - if value, ok := values[1].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[1]) - } else if value.Valid { - a.UpdatedAt = value.Time - } - if value, ok := values[2].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field scenario", values[2]) - } else if value.Valid { - a.Scenario = value.String - } - if value, ok := values[3].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field bucketId", values[3]) - } else if value.Valid { - a.BucketId = value.String - } - if value, ok := values[4].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field message", values[4]) - } else if value.Valid { - a.Message = value.String - } - if value, ok := values[5].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field eventsCount", values[5]) - } else if value.Valid { - a.EventsCount = int32(value.Int64) - } - if value, ok := values[6].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field startedAt", values[6]) - } else if value.Valid { - a.StartedAt = value.Time - } - if value, ok := values[7].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field stoppedAt", values[7]) - } else if value.Valid { - a.StoppedAt = value.Time - } - if value, ok := values[8].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field sourceIp", values[8]) - } else if value.Valid { - a.SourceIp = value.String - } - if value, ok := values[9].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field sourceRange", values[9]) - } else if value.Valid { - a.SourceRange = value.String - } - if value, ok := values[10].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field sourceAsNumber", values[10]) - } else if value.Valid { - a.SourceAsNumber = value.String - } - if value, ok := values[11].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field sourceAsName", values[11]) - } else if value.Valid { - a.SourceAsName = value.String - } - if value, ok := values[12].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field sourceCountry", values[12]) - } else if value.Valid { - a.SourceCountry = value.String - } - if value, ok := values[13].(*sql.NullFloat64); !ok { - return fmt.Errorf("unexpected type %T for field sourceLatitude", values[13]) - } else if value.Valid { - a.SourceLatitude = float32(value.Float64) - } - if value, ok := values[14].(*sql.NullFloat64); !ok { - return fmt.Errorf("unexpected type %T for field sourceLongitude", values[14]) - } else if value.Valid { - a.SourceLongitude = float32(value.Float64) - } - if value, ok := values[15].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field sourceScope", values[15]) - } else if value.Valid { - a.SourceScope = value.String - } - if value, ok := values[16].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field sourceValue", values[16]) - } else if value.Valid { - a.SourceValue = value.String - } - if value, ok := values[17].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field capacity", values[17]) - } else if value.Valid { - a.Capacity = int32(value.Int64) - } - if value, ok := values[18].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field leakSpeed", values[18]) - } else if value.Valid { - a.LeakSpeed = value.String - } - if value, ok := values[19].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field scenarioVersion", values[19]) - } else if value.Valid { - a.ScenarioVersion = value.String - } - if value, ok := values[20].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field scenarioHash", values[20]) - } else if value.Valid { - a.ScenarioHash = value.String - } - if value, ok := values[21].(*sql.NullBool); !ok { - return fmt.Errorf("unexpected type %T for field simulated", values[21]) - } else if value.Valid { - a.Simulated = value.Bool - } - values = values[22:] - if len(values) == len(alert.ForeignKeys) { - if value, ok := values[0].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for edge-field machine_alerts", value) - } else if value.Valid { - a.machine_alerts = new(int) - *a.machine_alerts = int(value.Int64) + for i := range columns { + switch columns[i] { + case alert.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + a.ID = int(value.Int64) + case alert.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 { + a.CreatedAt = value.Time + } + case alert.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 { + a.UpdatedAt = value.Time + } + case alert.FieldScenario: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field scenario", values[i]) + } else if value.Valid { + a.Scenario = value.String + } + case alert.FieldBucketId: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field bucketId", values[i]) + } else if value.Valid { + a.BucketId = value.String + } + case alert.FieldMessage: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field message", values[i]) + } else if value.Valid { + a.Message = value.String + } + case alert.FieldEventsCount: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field eventsCount", values[i]) + } else if value.Valid { + a.EventsCount = int32(value.Int64) + } + case alert.FieldStartedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field startedAt", values[i]) + } else if value.Valid { + a.StartedAt = value.Time + } + case alert.FieldStoppedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field stoppedAt", values[i]) + } else if value.Valid { + a.StoppedAt = value.Time + } + case alert.FieldSourceIp: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field sourceIp", values[i]) + } else if value.Valid { + a.SourceIp = value.String + } + case alert.FieldSourceRange: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field sourceRange", values[i]) + } else if value.Valid { + a.SourceRange = value.String + } + case alert.FieldSourceAsNumber: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field sourceAsNumber", values[i]) + } else if value.Valid { + a.SourceAsNumber = value.String + } + case alert.FieldSourceAsName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field sourceAsName", values[i]) + } else if value.Valid { + a.SourceAsName = value.String + } + case alert.FieldSourceCountry: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field sourceCountry", values[i]) + } else if value.Valid { + a.SourceCountry = value.String + } + case alert.FieldSourceLatitude: + if value, ok := values[i].(*sql.NullFloat64); !ok { + return fmt.Errorf("unexpected type %T for field sourceLatitude", values[i]) + } else if value.Valid { + a.SourceLatitude = float32(value.Float64) + } + case alert.FieldSourceLongitude: + if value, ok := values[i].(*sql.NullFloat64); !ok { + return fmt.Errorf("unexpected type %T for field sourceLongitude", values[i]) + } else if value.Valid { + a.SourceLongitude = float32(value.Float64) + } + case alert.FieldSourceScope: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field sourceScope", values[i]) + } else if value.Valid { + a.SourceScope = value.String + } + case alert.FieldSourceValue: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field sourceValue", values[i]) + } else if value.Valid { + a.SourceValue = value.String + } + case alert.FieldCapacity: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field capacity", values[i]) + } else if value.Valid { + a.Capacity = int32(value.Int64) + } + case alert.FieldLeakSpeed: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field leakSpeed", values[i]) + } else if value.Valid { + a.LeakSpeed = value.String + } + case alert.FieldScenarioVersion: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field scenarioVersion", values[i]) + } else if value.Valid { + a.ScenarioVersion = value.String + } + case alert.FieldScenarioHash: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field scenarioHash", values[i]) + } else if value.Valid { + a.ScenarioHash = value.String + } + case alert.FieldSimulated: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field simulated", values[i]) + } else if value.Valid { + a.Simulated = value.Bool + } + case alert.ForeignKeys[0]: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for edge-field machine_alerts", value) + } else if value.Valid { + a.machine_alerts = new(int) + *a.machine_alerts = int(value.Int64) + } } } return nil } -// QueryOwner queries the owner edge of the Alert. +// QueryOwner queries the "owner" edge of the Alert entity. func (a *Alert) QueryOwner() *MachineQuery { return (&AlertClient{config: a.config}).QueryOwner(a) } -// QueryDecisions queries the decisions edge of the Alert. +// QueryDecisions queries the "decisions" edge of the Alert entity. func (a *Alert) QueryDecisions() *DecisionQuery { return (&AlertClient{config: a.config}).QueryDecisions(a) } -// QueryEvents queries the events edge of the Alert. +// QueryEvents queries the "events" edge of the Alert entity. func (a *Alert) QueryEvents() *EventQuery { return (&AlertClient{config: a.config}).QueryEvents(a) } -// QueryMetas queries the metas edge of the Alert. +// QueryMetas queries the "metas" edge of the Alert entity. func (a *Alert) QueryMetas() *MetaQuery { return (&AlertClient{config: a.config}).QueryMetas(a) } // Update returns a builder for updating this Alert. -// Note that, you need to call Alert.Unwrap() before calling this method, if this Alert +// Note that you need to call Alert.Unwrap() before calling this method if this Alert // was returned from a transaction, and the transaction was committed or rolled back. func (a *Alert) Update() *AlertUpdateOne { return (&AlertClient{config: a.config}).UpdateOne(a) } -// Unwrap unwraps the entity that was returned from a transaction after it was closed, -// so that all next queries will be executed through the driver which created the transaction. +// Unwrap unwraps the Alert 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 (a *Alert) Unwrap() *Alert { tx, ok := a.config.driver.(*txDriver) if !ok { diff --git a/pkg/database/ent/alert/alert.go b/pkg/database/ent/alert/alert.go index 130d7ef66..2c891a250 100644 --- a/pkg/database/ent/alert/alert.go +++ b/pkg/database/ent/alert/alert.go @@ -145,20 +145,20 @@ func ValidColumn(column string) bool { } var ( - // DefaultCreatedAt holds the default value on creation for the created_at field. + // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the updated_at field. + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. DefaultUpdatedAt func() time.Time - // DefaultBucketId holds the default value on creation for the bucketId field. + // DefaultBucketId holds the default value on creation for the "bucketId" field. DefaultBucketId string - // DefaultMessage holds the default value on creation for the message field. + // DefaultMessage holds the default value on creation for the "message" field. DefaultMessage string - // DefaultEventsCount holds the default value on creation for the eventsCount field. + // DefaultEventsCount holds the default value on creation for the "eventsCount" field. DefaultEventsCount int32 - // DefaultStartedAt holds the default value on creation for the startedAt field. + // DefaultStartedAt holds the default value on creation for the "startedAt" field. DefaultStartedAt func() time.Time - // DefaultStoppedAt holds the default value on creation for the stoppedAt field. + // DefaultStoppedAt holds the default value on creation for the "stoppedAt" field. DefaultStoppedAt func() time.Time - // DefaultSimulated holds the default value on creation for the simulated field. + // DefaultSimulated holds the default value on creation for the "simulated" field. DefaultSimulated bool ) diff --git a/pkg/database/ent/alert/where.go b/pkg/database/ent/alert/where.go index a40588664..ce53a95dd 100644 --- a/pkg/database/ent/alert/where.go +++ b/pkg/database/ent/alert/where.go @@ -10,7 +10,7 @@ import ( "github.com/facebook/ent/dialect/sql/sqlgraph" ) -// ID filters vertices based on their identifier. +// ID filters vertices based on their ID field. func ID(id int) predicate.Alert { return predicate.Alert(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldID), id)) @@ -2676,7 +2676,7 @@ func HasMetasWith(preds ...predicate.Meta) predicate.Alert { }) } -// And groups list of predicates with the AND operator between them. +// And groups predicates with the AND operator between them. func And(predicates ...predicate.Alert) predicate.Alert { return predicate.Alert(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) @@ -2687,7 +2687,7 @@ func And(predicates ...predicate.Alert) predicate.Alert { }) } -// Or groups list of predicates with the OR operator between them. +// Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Alert) predicate.Alert { return predicate.Alert(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) diff --git a/pkg/database/ent/alert_create.go b/pkg/database/ent/alert_create.go index de5daa144..af281690e 100644 --- a/pkg/database/ent/alert_create.go +++ b/pkg/database/ent/alert_create.go @@ -24,13 +24,13 @@ type AlertCreate struct { hooks []Hook } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (ac *AlertCreate) SetCreatedAt(t time.Time) *AlertCreate { ac.mutation.SetCreatedAt(t) return ac } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (ac *AlertCreate) SetNillableCreatedAt(t *time.Time) *AlertCreate { if t != nil { ac.SetCreatedAt(*t) @@ -38,13 +38,13 @@ func (ac *AlertCreate) SetNillableCreatedAt(t *time.Time) *AlertCreate { return ac } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (ac *AlertCreate) SetUpdatedAt(t time.Time) *AlertCreate { ac.mutation.SetUpdatedAt(t) return ac } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (ac *AlertCreate) SetNillableUpdatedAt(t *time.Time) *AlertCreate { if t != nil { ac.SetUpdatedAt(*t) @@ -52,19 +52,19 @@ func (ac *AlertCreate) SetNillableUpdatedAt(t *time.Time) *AlertCreate { return ac } -// SetScenario sets the scenario field. +// SetScenario sets the "scenario" field. func (ac *AlertCreate) SetScenario(s string) *AlertCreate { ac.mutation.SetScenario(s) return ac } -// SetBucketId sets the bucketId field. +// SetBucketId sets the "bucketId" field. func (ac *AlertCreate) SetBucketId(s string) *AlertCreate { ac.mutation.SetBucketId(s) return ac } -// SetNillableBucketId sets the bucketId field if the given value is not nil. +// SetNillableBucketId sets the "bucketId" field if the given value is not nil. func (ac *AlertCreate) SetNillableBucketId(s *string) *AlertCreate { if s != nil { ac.SetBucketId(*s) @@ -72,13 +72,13 @@ func (ac *AlertCreate) SetNillableBucketId(s *string) *AlertCreate { return ac } -// SetMessage sets the message field. +// SetMessage sets the "message" field. func (ac *AlertCreate) SetMessage(s string) *AlertCreate { ac.mutation.SetMessage(s) return ac } -// SetNillableMessage sets the message field if the given value is not nil. +// SetNillableMessage sets the "message" field if the given value is not nil. func (ac *AlertCreate) SetNillableMessage(s *string) *AlertCreate { if s != nil { ac.SetMessage(*s) @@ -86,13 +86,13 @@ func (ac *AlertCreate) SetNillableMessage(s *string) *AlertCreate { return ac } -// SetEventsCount sets the eventsCount field. +// SetEventsCount sets the "eventsCount" field. func (ac *AlertCreate) SetEventsCount(i int32) *AlertCreate { ac.mutation.SetEventsCount(i) return ac } -// SetNillableEventsCount sets the eventsCount field if the given value is not nil. +// SetNillableEventsCount sets the "eventsCount" field if the given value is not nil. func (ac *AlertCreate) SetNillableEventsCount(i *int32) *AlertCreate { if i != nil { ac.SetEventsCount(*i) @@ -100,13 +100,13 @@ func (ac *AlertCreate) SetNillableEventsCount(i *int32) *AlertCreate { return ac } -// SetStartedAt sets the startedAt field. +// SetStartedAt sets the "startedAt" field. func (ac *AlertCreate) SetStartedAt(t time.Time) *AlertCreate { ac.mutation.SetStartedAt(t) return ac } -// SetNillableStartedAt sets the startedAt field if the given value is not nil. +// SetNillableStartedAt sets the "startedAt" field if the given value is not nil. func (ac *AlertCreate) SetNillableStartedAt(t *time.Time) *AlertCreate { if t != nil { ac.SetStartedAt(*t) @@ -114,13 +114,13 @@ func (ac *AlertCreate) SetNillableStartedAt(t *time.Time) *AlertCreate { return ac } -// SetStoppedAt sets the stoppedAt field. +// SetStoppedAt sets the "stoppedAt" field. func (ac *AlertCreate) SetStoppedAt(t time.Time) *AlertCreate { ac.mutation.SetStoppedAt(t) return ac } -// SetNillableStoppedAt sets the stoppedAt field if the given value is not nil. +// SetNillableStoppedAt sets the "stoppedAt" field if the given value is not nil. func (ac *AlertCreate) SetNillableStoppedAt(t *time.Time) *AlertCreate { if t != nil { ac.SetStoppedAt(*t) @@ -128,13 +128,13 @@ func (ac *AlertCreate) SetNillableStoppedAt(t *time.Time) *AlertCreate { return ac } -// SetSourceIp sets the sourceIp field. +// SetSourceIp sets the "sourceIp" field. func (ac *AlertCreate) SetSourceIp(s string) *AlertCreate { ac.mutation.SetSourceIp(s) return ac } -// SetNillableSourceIp sets the sourceIp field if the given value is not nil. +// SetNillableSourceIp sets the "sourceIp" field if the given value is not nil. func (ac *AlertCreate) SetNillableSourceIp(s *string) *AlertCreate { if s != nil { ac.SetSourceIp(*s) @@ -142,13 +142,13 @@ func (ac *AlertCreate) SetNillableSourceIp(s *string) *AlertCreate { return ac } -// SetSourceRange sets the sourceRange field. +// SetSourceRange sets the "sourceRange" field. func (ac *AlertCreate) SetSourceRange(s string) *AlertCreate { ac.mutation.SetSourceRange(s) return ac } -// SetNillableSourceRange sets the sourceRange field if the given value is not nil. +// SetNillableSourceRange sets the "sourceRange" field if the given value is not nil. func (ac *AlertCreate) SetNillableSourceRange(s *string) *AlertCreate { if s != nil { ac.SetSourceRange(*s) @@ -156,13 +156,13 @@ func (ac *AlertCreate) SetNillableSourceRange(s *string) *AlertCreate { return ac } -// SetSourceAsNumber sets the sourceAsNumber field. +// SetSourceAsNumber sets the "sourceAsNumber" field. func (ac *AlertCreate) SetSourceAsNumber(s string) *AlertCreate { ac.mutation.SetSourceAsNumber(s) return ac } -// SetNillableSourceAsNumber sets the sourceAsNumber field if the given value is not nil. +// SetNillableSourceAsNumber sets the "sourceAsNumber" field if the given value is not nil. func (ac *AlertCreate) SetNillableSourceAsNumber(s *string) *AlertCreate { if s != nil { ac.SetSourceAsNumber(*s) @@ -170,13 +170,13 @@ func (ac *AlertCreate) SetNillableSourceAsNumber(s *string) *AlertCreate { return ac } -// SetSourceAsName sets the sourceAsName field. +// SetSourceAsName sets the "sourceAsName" field. func (ac *AlertCreate) SetSourceAsName(s string) *AlertCreate { ac.mutation.SetSourceAsName(s) return ac } -// SetNillableSourceAsName sets the sourceAsName field if the given value is not nil. +// SetNillableSourceAsName sets the "sourceAsName" field if the given value is not nil. func (ac *AlertCreate) SetNillableSourceAsName(s *string) *AlertCreate { if s != nil { ac.SetSourceAsName(*s) @@ -184,13 +184,13 @@ func (ac *AlertCreate) SetNillableSourceAsName(s *string) *AlertCreate { return ac } -// SetSourceCountry sets the sourceCountry field. +// SetSourceCountry sets the "sourceCountry" field. func (ac *AlertCreate) SetSourceCountry(s string) *AlertCreate { ac.mutation.SetSourceCountry(s) return ac } -// SetNillableSourceCountry sets the sourceCountry field if the given value is not nil. +// SetNillableSourceCountry sets the "sourceCountry" field if the given value is not nil. func (ac *AlertCreate) SetNillableSourceCountry(s *string) *AlertCreate { if s != nil { ac.SetSourceCountry(*s) @@ -198,13 +198,13 @@ func (ac *AlertCreate) SetNillableSourceCountry(s *string) *AlertCreate { return ac } -// SetSourceLatitude sets the sourceLatitude field. +// SetSourceLatitude sets the "sourceLatitude" field. func (ac *AlertCreate) SetSourceLatitude(f float32) *AlertCreate { ac.mutation.SetSourceLatitude(f) return ac } -// SetNillableSourceLatitude sets the sourceLatitude field if the given value is not nil. +// SetNillableSourceLatitude sets the "sourceLatitude" field if the given value is not nil. func (ac *AlertCreate) SetNillableSourceLatitude(f *float32) *AlertCreate { if f != nil { ac.SetSourceLatitude(*f) @@ -212,13 +212,13 @@ func (ac *AlertCreate) SetNillableSourceLatitude(f *float32) *AlertCreate { return ac } -// SetSourceLongitude sets the sourceLongitude field. +// SetSourceLongitude sets the "sourceLongitude" field. func (ac *AlertCreate) SetSourceLongitude(f float32) *AlertCreate { ac.mutation.SetSourceLongitude(f) return ac } -// SetNillableSourceLongitude sets the sourceLongitude field if the given value is not nil. +// SetNillableSourceLongitude sets the "sourceLongitude" field if the given value is not nil. func (ac *AlertCreate) SetNillableSourceLongitude(f *float32) *AlertCreate { if f != nil { ac.SetSourceLongitude(*f) @@ -226,13 +226,13 @@ func (ac *AlertCreate) SetNillableSourceLongitude(f *float32) *AlertCreate { return ac } -// SetSourceScope sets the sourceScope field. +// SetSourceScope sets the "sourceScope" field. func (ac *AlertCreate) SetSourceScope(s string) *AlertCreate { ac.mutation.SetSourceScope(s) return ac } -// SetNillableSourceScope sets the sourceScope field if the given value is not nil. +// SetNillableSourceScope sets the "sourceScope" field if the given value is not nil. func (ac *AlertCreate) SetNillableSourceScope(s *string) *AlertCreate { if s != nil { ac.SetSourceScope(*s) @@ -240,13 +240,13 @@ func (ac *AlertCreate) SetNillableSourceScope(s *string) *AlertCreate { return ac } -// SetSourceValue sets the sourceValue field. +// SetSourceValue sets the "sourceValue" field. func (ac *AlertCreate) SetSourceValue(s string) *AlertCreate { ac.mutation.SetSourceValue(s) return ac } -// SetNillableSourceValue sets the sourceValue field if the given value is not nil. +// SetNillableSourceValue sets the "sourceValue" field if the given value is not nil. func (ac *AlertCreate) SetNillableSourceValue(s *string) *AlertCreate { if s != nil { ac.SetSourceValue(*s) @@ -254,13 +254,13 @@ func (ac *AlertCreate) SetNillableSourceValue(s *string) *AlertCreate { return ac } -// SetCapacity sets the capacity field. +// SetCapacity sets the "capacity" field. func (ac *AlertCreate) SetCapacity(i int32) *AlertCreate { ac.mutation.SetCapacity(i) return ac } -// SetNillableCapacity sets the capacity field if the given value is not nil. +// SetNillableCapacity sets the "capacity" field if the given value is not nil. func (ac *AlertCreate) SetNillableCapacity(i *int32) *AlertCreate { if i != nil { ac.SetCapacity(*i) @@ -268,13 +268,13 @@ func (ac *AlertCreate) SetNillableCapacity(i *int32) *AlertCreate { return ac } -// SetLeakSpeed sets the leakSpeed field. +// SetLeakSpeed sets the "leakSpeed" field. func (ac *AlertCreate) SetLeakSpeed(s string) *AlertCreate { ac.mutation.SetLeakSpeed(s) return ac } -// SetNillableLeakSpeed sets the leakSpeed field if the given value is not nil. +// SetNillableLeakSpeed sets the "leakSpeed" field if the given value is not nil. func (ac *AlertCreate) SetNillableLeakSpeed(s *string) *AlertCreate { if s != nil { ac.SetLeakSpeed(*s) @@ -282,13 +282,13 @@ func (ac *AlertCreate) SetNillableLeakSpeed(s *string) *AlertCreate { return ac } -// SetScenarioVersion sets the scenarioVersion field. +// SetScenarioVersion sets the "scenarioVersion" field. func (ac *AlertCreate) SetScenarioVersion(s string) *AlertCreate { ac.mutation.SetScenarioVersion(s) return ac } -// SetNillableScenarioVersion sets the scenarioVersion field if the given value is not nil. +// SetNillableScenarioVersion sets the "scenarioVersion" field if the given value is not nil. func (ac *AlertCreate) SetNillableScenarioVersion(s *string) *AlertCreate { if s != nil { ac.SetScenarioVersion(*s) @@ -296,13 +296,13 @@ func (ac *AlertCreate) SetNillableScenarioVersion(s *string) *AlertCreate { return ac } -// SetScenarioHash sets the scenarioHash field. +// SetScenarioHash sets the "scenarioHash" field. func (ac *AlertCreate) SetScenarioHash(s string) *AlertCreate { ac.mutation.SetScenarioHash(s) return ac } -// SetNillableScenarioHash sets the scenarioHash field if the given value is not nil. +// SetNillableScenarioHash sets the "scenarioHash" field if the given value is not nil. func (ac *AlertCreate) SetNillableScenarioHash(s *string) *AlertCreate { if s != nil { ac.SetScenarioHash(*s) @@ -310,13 +310,13 @@ func (ac *AlertCreate) SetNillableScenarioHash(s *string) *AlertCreate { return ac } -// SetSimulated sets the simulated field. +// SetSimulated sets the "simulated" field. func (ac *AlertCreate) SetSimulated(b bool) *AlertCreate { ac.mutation.SetSimulated(b) return ac } -// SetNillableSimulated sets the simulated field if the given value is not nil. +// SetNillableSimulated sets the "simulated" field if the given value is not nil. func (ac *AlertCreate) SetNillableSimulated(b *bool) *AlertCreate { if b != nil { ac.SetSimulated(*b) @@ -324,13 +324,13 @@ func (ac *AlertCreate) SetNillableSimulated(b *bool) *AlertCreate { return ac } -// SetOwnerID sets the owner edge to Machine by id. +// SetOwnerID sets the "owner" edge to the Machine entity by ID. func (ac *AlertCreate) SetOwnerID(id int) *AlertCreate { ac.mutation.SetOwnerID(id) return ac } -// SetNillableOwnerID sets the owner edge to Machine by id if the given value is not nil. +// SetNillableOwnerID sets the "owner" edge to the Machine entity by ID if the given value is not nil. func (ac *AlertCreate) SetNillableOwnerID(id *int) *AlertCreate { if id != nil { ac = ac.SetOwnerID(*id) @@ -338,18 +338,18 @@ func (ac *AlertCreate) SetNillableOwnerID(id *int) *AlertCreate { return ac } -// SetOwner sets the owner edge to Machine. +// SetOwner sets the "owner" edge to the Machine entity. func (ac *AlertCreate) SetOwner(m *Machine) *AlertCreate { return ac.SetOwnerID(m.ID) } -// AddDecisionIDs adds the decisions edge to Decision by ids. +// AddDecisionIDs adds the "decisions" edge to the Decision entity by IDs. func (ac *AlertCreate) AddDecisionIDs(ids ...int) *AlertCreate { ac.mutation.AddDecisionIDs(ids...) return ac } -// AddDecisions adds the decisions edges to Decision. +// AddDecisions adds the "decisions" edges to the Decision entity. func (ac *AlertCreate) AddDecisions(d ...*Decision) *AlertCreate { ids := make([]int, len(d)) for i := range d { @@ -358,13 +358,13 @@ func (ac *AlertCreate) AddDecisions(d ...*Decision) *AlertCreate { return ac.AddDecisionIDs(ids...) } -// AddEventIDs adds the events edge to Event by ids. +// AddEventIDs adds the "events" edge to the Event entity by IDs. func (ac *AlertCreate) AddEventIDs(ids ...int) *AlertCreate { ac.mutation.AddEventIDs(ids...) return ac } -// AddEvents adds the events edges to Event. +// AddEvents adds the "events" edges to the Event entity. func (ac *AlertCreate) AddEvents(e ...*Event) *AlertCreate { ids := make([]int, len(e)) for i := range e { @@ -373,13 +373,13 @@ func (ac *AlertCreate) AddEvents(e ...*Event) *AlertCreate { return ac.AddEventIDs(ids...) } -// AddMetaIDs adds the metas edge to Meta by ids. +// AddMetaIDs adds the "metas" edge to the Meta entity by IDs. func (ac *AlertCreate) AddMetaIDs(ids ...int) *AlertCreate { ac.mutation.AddMetaIDs(ids...) return ac } -// AddMetas adds the metas edges to Meta. +// AddMetas adds the "metas" edges to the Meta entity. func (ac *AlertCreate) AddMetas(m ...*Meta) *AlertCreate { ids := make([]int, len(m)) for i := range m { @@ -770,7 +770,7 @@ func (ac *AlertCreate) createSpec() (*Alert, *sqlgraph.CreateSpec) { return _node, _spec } -// AlertCreateBulk is the builder for creating a bulk of Alert entities. +// AlertCreateBulk is the builder for creating many Alert entities in bulk. type AlertCreateBulk struct { config builders []*AlertCreate @@ -828,7 +828,7 @@ func (acb *AlertCreateBulk) Save(ctx context.Context) ([]*Alert, error) { return nodes, nil } -// SaveX calls Save and panics if Save returns an error. +// SaveX is like Save, but panics if an error occurs. func (acb *AlertCreateBulk) SaveX(ctx context.Context) []*Alert { v, err := acb.Save(ctx) if err != nil { diff --git a/pkg/database/ent/alert_delete.go b/pkg/database/ent/alert_delete.go index 2532aa915..a12279b88 100644 --- a/pkg/database/ent/alert_delete.go +++ b/pkg/database/ent/alert_delete.go @@ -16,14 +16,13 @@ import ( // AlertDelete is the builder for deleting a Alert entity. type AlertDelete struct { config - hooks []Hook - mutation *AlertMutation - predicates []predicate.Alert + hooks []Hook + mutation *AlertMutation } -// Where adds a new predicate to the delete builder. +// Where adds a new predicate to the AlertDelete builder. func (ad *AlertDelete) Where(ps ...predicate.Alert) *AlertDelete { - ad.predicates = append(ad.predicates, ps...) + ad.mutation.predicates = append(ad.mutation.predicates, ps...) return ad } @@ -75,7 +74,7 @@ func (ad *AlertDelete) sqlExec(ctx context.Context) (int, error) { }, }, } - if ps := ad.predicates; len(ps) > 0 { + if ps := ad.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) diff --git a/pkg/database/ent/alert_query.go b/pkg/database/ent/alert_query.go index 55d196953..51cd16de2 100644 --- a/pkg/database/ent/alert_query.go +++ b/pkg/database/ent/alert_query.go @@ -26,7 +26,7 @@ type AlertQuery struct { limit *int offset *int order []OrderFunc - unique []string + fields []string predicates []predicate.Alert // eager-loading edges. withOwner *MachineQuery @@ -39,7 +39,7 @@ type AlertQuery struct { path func(context.Context) (*sql.Selector, error) } -// Where adds a new predicate for the builder. +// Where adds a new predicate for the AlertQuery builder. func (aq *AlertQuery) Where(ps ...predicate.Alert) *AlertQuery { aq.predicates = append(aq.predicates, ps...) return aq @@ -63,7 +63,7 @@ func (aq *AlertQuery) Order(o ...OrderFunc) *AlertQuery { return aq } -// QueryOwner chains the current query on the owner edge. +// QueryOwner chains the current query on the "owner" edge. func (aq *AlertQuery) QueryOwner() *MachineQuery { query := &MachineQuery{config: aq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { @@ -85,7 +85,7 @@ func (aq *AlertQuery) QueryOwner() *MachineQuery { return query } -// QueryDecisions chains the current query on the decisions edge. +// QueryDecisions chains the current query on the "decisions" edge. func (aq *AlertQuery) QueryDecisions() *DecisionQuery { query := &DecisionQuery{config: aq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { @@ -107,7 +107,7 @@ func (aq *AlertQuery) QueryDecisions() *DecisionQuery { return query } -// QueryEvents chains the current query on the events edge. +// QueryEvents chains the current query on the "events" edge. func (aq *AlertQuery) QueryEvents() *EventQuery { query := &EventQuery{config: aq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { @@ -129,7 +129,7 @@ func (aq *AlertQuery) QueryEvents() *EventQuery { return query } -// QueryMetas chains the current query on the metas edge. +// QueryMetas chains the current query on the "metas" edge. func (aq *AlertQuery) QueryMetas() *MetaQuery { query := &MetaQuery{config: aq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { @@ -151,7 +151,8 @@ func (aq *AlertQuery) QueryMetas() *MetaQuery { return query } -// First returns the first Alert entity in the query. Returns *NotFoundError when no alert was found. +// First returns the first Alert entity from the query. +// Returns a *NotFoundError when no Alert was found. func (aq *AlertQuery) First(ctx context.Context) (*Alert, error) { nodes, err := aq.Limit(1).All(ctx) if err != nil { @@ -172,7 +173,8 @@ func (aq *AlertQuery) FirstX(ctx context.Context) *Alert { return node } -// FirstID returns the first Alert id in the query. Returns *NotFoundError when no id was found. +// FirstID returns the first Alert ID from the query. +// Returns a *NotFoundError when no Alert ID was found. func (aq *AlertQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int if ids, err = aq.Limit(1).IDs(ctx); err != nil { @@ -185,8 +187,8 @@ func (aq *AlertQuery) FirstID(ctx context.Context) (id int, err error) { return ids[0], nil } -// FirstXID is like FirstID, but panics if an error occurs. -func (aq *AlertQuery) FirstXID(ctx context.Context) int { +// FirstIDX is like FirstID, but panics if an error occurs. +func (aq *AlertQuery) FirstIDX(ctx context.Context) int { id, err := aq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -194,7 +196,9 @@ func (aq *AlertQuery) FirstXID(ctx context.Context) int { return id } -// Only returns the only Alert entity in the query, returns an error if not exactly one entity was returned. +// Only returns a single Alert entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when exactly one Alert entity is not found. +// Returns a *NotFoundError when no Alert entities are found. func (aq *AlertQuery) Only(ctx context.Context) (*Alert, error) { nodes, err := aq.Limit(2).All(ctx) if err != nil { @@ -219,7 +223,9 @@ func (aq *AlertQuery) OnlyX(ctx context.Context) *Alert { return node } -// OnlyID returns the only Alert id in the query, returns an error if not exactly one id was returned. +// OnlyID is like Only, but returns the only Alert ID in the query. +// Returns a *NotSingularError when exactly one Alert ID is not found. +// Returns a *NotFoundError when no entities are found. func (aq *AlertQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int if ids, err = aq.Limit(2).IDs(ctx); err != nil { @@ -262,7 +268,7 @@ func (aq *AlertQuery) AllX(ctx context.Context) []*Alert { return nodes } -// IDs executes the query and returns a list of Alert ids. +// IDs executes the query and returns a list of Alert IDs. func (aq *AlertQuery) IDs(ctx context.Context) ([]int, error) { var ids []int if err := aq.Select(alert.FieldID).Scan(ctx, &ids); err != nil { @@ -314,24 +320,30 @@ func (aq *AlertQuery) ExistX(ctx context.Context) bool { return exist } -// Clone returns a duplicate of the query builder, including all associated steps. It can be +// Clone returns a duplicate of the AlertQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. func (aq *AlertQuery) Clone() *AlertQuery { + if aq == nil { + return nil + } return &AlertQuery{ - config: aq.config, - limit: aq.limit, - offset: aq.offset, - order: append([]OrderFunc{}, aq.order...), - unique: append([]string{}, aq.unique...), - predicates: append([]predicate.Alert{}, aq.predicates...), + config: aq.config, + limit: aq.limit, + offset: aq.offset, + order: append([]OrderFunc{}, aq.order...), + predicates: append([]predicate.Alert{}, aq.predicates...), + withOwner: aq.withOwner.Clone(), + withDecisions: aq.withDecisions.Clone(), + withEvents: aq.withEvents.Clone(), + withMetas: aq.withMetas.Clone(), // clone intermediate query. sql: aq.sql.Clone(), path: aq.path, } } -// WithOwner tells the query-builder to eager-loads the nodes that are connected to -// the "owner" edge. The optional arguments used to configure the query builder of the edge. +// WithOwner tells the query-builder to eager-load the nodes that are connected to +// the "owner" edge. The optional arguments are used to configure the query builder of the edge. func (aq *AlertQuery) WithOwner(opts ...func(*MachineQuery)) *AlertQuery { query := &MachineQuery{config: aq.config} for _, opt := range opts { @@ -341,8 +353,8 @@ func (aq *AlertQuery) WithOwner(opts ...func(*MachineQuery)) *AlertQuery { return aq } -// WithDecisions tells the query-builder to eager-loads the nodes that are connected to -// the "decisions" edge. The optional arguments used to configure the query builder of the edge. +// WithDecisions tells the query-builder to eager-load the nodes that are connected to +// the "decisions" edge. The optional arguments are used to configure the query builder of the edge. func (aq *AlertQuery) WithDecisions(opts ...func(*DecisionQuery)) *AlertQuery { query := &DecisionQuery{config: aq.config} for _, opt := range opts { @@ -352,8 +364,8 @@ func (aq *AlertQuery) WithDecisions(opts ...func(*DecisionQuery)) *AlertQuery { return aq } -// WithEvents tells the query-builder to eager-loads the nodes that are connected to -// the "events" edge. The optional arguments used to configure the query builder of the edge. +// WithEvents tells the query-builder to eager-load the nodes that are connected to +// the "events" edge. The optional arguments are used to configure the query builder of the edge. func (aq *AlertQuery) WithEvents(opts ...func(*EventQuery)) *AlertQuery { query := &EventQuery{config: aq.config} for _, opt := range opts { @@ -363,8 +375,8 @@ func (aq *AlertQuery) WithEvents(opts ...func(*EventQuery)) *AlertQuery { return aq } -// WithMetas tells the query-builder to eager-loads the nodes that are connected to -// the "metas" edge. The optional arguments used to configure the query builder of the edge. +// WithMetas tells the query-builder to eager-load the nodes that are connected to +// the "metas" edge. The optional arguments are used to configure the query builder of the edge. func (aq *AlertQuery) WithMetas(opts ...func(*MetaQuery)) *AlertQuery { query := &MetaQuery{config: aq.config} for _, opt := range opts { @@ -374,7 +386,7 @@ func (aq *AlertQuery) WithMetas(opts ...func(*MetaQuery)) *AlertQuery { return aq } -// GroupBy used to group vertices by one or more fields/columns. +// GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // // Example: @@ -401,7 +413,8 @@ func (aq *AlertQuery) GroupBy(field string, fields ...string) *AlertGroupBy { return group } -// Select one or more fields from the given query. +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. // // Example: // @@ -414,18 +427,16 @@ func (aq *AlertQuery) GroupBy(field string, fields ...string) *AlertGroupBy { // Scan(ctx, &v) // func (aq *AlertQuery) Select(field string, fields ...string) *AlertSelect { - selector := &AlertSelect{config: aq.config} - selector.fields = append([]string{field}, fields...) - selector.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := aq.prepareQuery(ctx); err != nil { - return nil, err - } - return aq.sqlQuery(), nil - } - return selector + aq.fields = append([]string{field}, fields...) + return &AlertSelect{AlertQuery: aq} } func (aq *AlertQuery) prepareQuery(ctx context.Context) error { + for _, f := range aq.fields { + if !alert.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } if aq.path != nil { prev, err := aq.path(ctx) if err != nil { @@ -454,22 +465,18 @@ func (aq *AlertQuery) sqlAll(ctx context.Context) ([]*Alert, error) { if withFKs { _spec.Node.Columns = append(_spec.Node.Columns, alert.ForeignKeys...) } - _spec.ScanValues = func() []interface{} { + _spec.ScanValues = func(columns []string) ([]interface{}, error) { node := &Alert{config: aq.config} nodes = append(nodes, node) - values := node.scanValues() - if withFKs { - values = append(values, node.fkValues()...) - } - return values + return node.scanValues(columns) } - _spec.Assign = func(values ...interface{}) error { + _spec.Assign = func(columns []string, values []interface{}) error { if len(nodes) == 0 { return fmt.Errorf("ent: Assign called without calling ScanValues") } node := nodes[len(nodes)-1] node.Edges.loadedTypes = loadedTypes - return node.assignValues(values...) + return node.assignValues(columns, values) } if err := sqlgraph.QueryNodes(ctx, aq.driver, _spec); err != nil { return nil, err @@ -509,6 +516,7 @@ func (aq *AlertQuery) sqlAll(ctx context.Context) ([]*Alert, error) { for i := range nodes { fks = append(fks, nodes[i].ID) nodeids[nodes[i].ID] = nodes[i] + nodes[i].Edges.Decisions = []*Decision{} } query.withFKs = true query.Where(predicate.Decision(func(s *sql.Selector) { @@ -537,6 +545,7 @@ func (aq *AlertQuery) sqlAll(ctx context.Context) ([]*Alert, error) { for i := range nodes { fks = append(fks, nodes[i].ID) nodeids[nodes[i].ID] = nodes[i] + nodes[i].Edges.Events = []*Event{} } query.withFKs = true query.Where(predicate.Event(func(s *sql.Selector) { @@ -565,6 +574,7 @@ func (aq *AlertQuery) sqlAll(ctx context.Context) ([]*Alert, error) { for i := range nodes { fks = append(fks, nodes[i].ID) nodeids[nodes[i].ID] = nodes[i] + nodes[i].Edges.Metas = []*Meta{} } query.withFKs = true query.Where(predicate.Meta(func(s *sql.Selector) { @@ -616,6 +626,15 @@ func (aq *AlertQuery) querySpec() *sqlgraph.QuerySpec { From: aq.sql, Unique: true, } + if fields := aq.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, alert.FieldID) + for i := range fields { + if fields[i] != alert.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } if ps := aq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -664,7 +683,7 @@ func (aq *AlertQuery) sqlQuery() *sql.Selector { return selector } -// AlertGroupBy is the builder for group-by Alert entities. +// AlertGroupBy is the group-by builder for Alert entities. type AlertGroupBy struct { config fields []string @@ -680,7 +699,7 @@ func (agb *AlertGroupBy) Aggregate(fns ...AggregateFunc) *AlertGroupBy { return agb } -// Scan applies the group-by query and scan the result into the given value. +// Scan applies the group-by query and scans the result into the given value. func (agb *AlertGroupBy) Scan(ctx context.Context, v interface{}) error { query, err := agb.path(ctx) if err != nil { @@ -697,7 +716,8 @@ func (agb *AlertGroupBy) ScanX(ctx context.Context, v interface{}) { } } -// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field. +// Strings returns list of strings from group-by. +// It is only allowed when executing a group-by query with one field. func (agb *AlertGroupBy) Strings(ctx context.Context) ([]string, error) { if len(agb.fields) > 1 { return nil, errors.New("ent: AlertGroupBy.Strings is not achievable when grouping more than 1 field") @@ -718,7 +738,8 @@ func (agb *AlertGroupBy) StringsX(ctx context.Context) []string { return v } -// String returns a single string from group-by. It is only allowed when querying group-by with one field. +// String returns a single string from a group-by query. +// It is only allowed when executing a group-by query with one field. func (agb *AlertGroupBy) String(ctx context.Context) (_ string, err error) { var v []string if v, err = agb.Strings(ctx); err != nil { @@ -744,7 +765,8 @@ func (agb *AlertGroupBy) StringX(ctx context.Context) string { return v } -// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field. +// Ints returns list of ints from group-by. +// It is only allowed when executing a group-by query with one field. func (agb *AlertGroupBy) Ints(ctx context.Context) ([]int, error) { if len(agb.fields) > 1 { return nil, errors.New("ent: AlertGroupBy.Ints is not achievable when grouping more than 1 field") @@ -765,7 +787,8 @@ func (agb *AlertGroupBy) IntsX(ctx context.Context) []int { return v } -// Int returns a single int from group-by. It is only allowed when querying group-by with one field. +// Int returns a single int from a group-by query. +// It is only allowed when executing a group-by query with one field. func (agb *AlertGroupBy) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = agb.Ints(ctx); err != nil { @@ -791,7 +814,8 @@ func (agb *AlertGroupBy) IntX(ctx context.Context) int { return v } -// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field. +// Float64s returns list of float64s from group-by. +// It is only allowed when executing a group-by query with one field. func (agb *AlertGroupBy) Float64s(ctx context.Context) ([]float64, error) { if len(agb.fields) > 1 { return nil, errors.New("ent: AlertGroupBy.Float64s is not achievable when grouping more than 1 field") @@ -812,7 +836,8 @@ func (agb *AlertGroupBy) Float64sX(ctx context.Context) []float64 { return v } -// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field. +// Float64 returns a single float64 from a group-by query. +// It is only allowed when executing a group-by query with one field. func (agb *AlertGroupBy) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = agb.Float64s(ctx); err != nil { @@ -838,7 +863,8 @@ func (agb *AlertGroupBy) Float64X(ctx context.Context) float64 { return v } -// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field. +// Bools returns list of bools from group-by. +// It is only allowed when executing a group-by query with one field. func (agb *AlertGroupBy) Bools(ctx context.Context) ([]bool, error) { if len(agb.fields) > 1 { return nil, errors.New("ent: AlertGroupBy.Bools is not achievable when grouping more than 1 field") @@ -859,7 +885,8 @@ func (agb *AlertGroupBy) BoolsX(ctx context.Context) []bool { return v } -// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field. +// Bool returns a single bool from a group-by query. +// It is only allowed when executing a group-by query with one field. func (agb *AlertGroupBy) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = agb.Bools(ctx); err != nil { @@ -914,22 +941,19 @@ func (agb *AlertGroupBy) sqlQuery() *sql.Selector { return selector.Select(columns...).GroupBy(agb.fields...) } -// AlertSelect is the builder for select fields of Alert entities. +// AlertSelect is the builder for selecting fields of Alert entities. type AlertSelect struct { - config - fields []string + *AlertQuery // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + sql *sql.Selector } -// Scan applies the selector query and scan the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (as *AlertSelect) Scan(ctx context.Context, v interface{}) error { - query, err := as.path(ctx) - if err != nil { + if err := as.prepareQuery(ctx); err != nil { return err } - as.sql = query + as.sql = as.AlertQuery.sqlQuery() return as.sqlScan(ctx, v) } @@ -940,7 +964,7 @@ func (as *AlertSelect) ScanX(ctx context.Context, v interface{}) { } } -// Strings returns list of strings from selector. It is only allowed when selecting one field. +// Strings returns list of strings from a selector. It is only allowed when selecting one field. func (as *AlertSelect) Strings(ctx context.Context) ([]string, error) { if len(as.fields) > 1 { return nil, errors.New("ent: AlertSelect.Strings is not achievable when selecting more than 1 field") @@ -961,7 +985,7 @@ func (as *AlertSelect) StringsX(ctx context.Context) []string { return v } -// String returns a single string from selector. It is only allowed when selecting one field. +// String returns a single string from a selector. It is only allowed when selecting one field. func (as *AlertSelect) String(ctx context.Context) (_ string, err error) { var v []string if v, err = as.Strings(ctx); err != nil { @@ -987,7 +1011,7 @@ func (as *AlertSelect) StringX(ctx context.Context) string { return v } -// Ints returns list of ints from selector. It is only allowed when selecting one field. +// Ints returns list of ints from a selector. It is only allowed when selecting one field. func (as *AlertSelect) Ints(ctx context.Context) ([]int, error) { if len(as.fields) > 1 { return nil, errors.New("ent: AlertSelect.Ints is not achievable when selecting more than 1 field") @@ -1008,7 +1032,7 @@ func (as *AlertSelect) IntsX(ctx context.Context) []int { return v } -// Int returns a single int from selector. It is only allowed when selecting one field. +// Int returns a single int from a selector. It is only allowed when selecting one field. func (as *AlertSelect) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = as.Ints(ctx); err != nil { @@ -1034,7 +1058,7 @@ func (as *AlertSelect) IntX(ctx context.Context) int { return v } -// Float64s returns list of float64s from selector. It is only allowed when selecting one field. +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. func (as *AlertSelect) Float64s(ctx context.Context) ([]float64, error) { if len(as.fields) > 1 { return nil, errors.New("ent: AlertSelect.Float64s is not achievable when selecting more than 1 field") @@ -1055,7 +1079,7 @@ func (as *AlertSelect) Float64sX(ctx context.Context) []float64 { return v } -// Float64 returns a single float64 from selector. It is only allowed when selecting one field. +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. func (as *AlertSelect) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = as.Float64s(ctx); err != nil { @@ -1081,7 +1105,7 @@ func (as *AlertSelect) Float64X(ctx context.Context) float64 { return v } -// Bools returns list of bools from selector. It is only allowed when selecting one field. +// Bools returns list of bools from a selector. It is only allowed when selecting one field. func (as *AlertSelect) Bools(ctx context.Context) ([]bool, error) { if len(as.fields) > 1 { return nil, errors.New("ent: AlertSelect.Bools is not achievable when selecting more than 1 field") @@ -1102,7 +1126,7 @@ func (as *AlertSelect) BoolsX(ctx context.Context) []bool { return v } -// Bool returns a single bool from selector. It is only allowed when selecting one field. +// Bool returns a single bool from a selector. It is only allowed when selecting one field. func (as *AlertSelect) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = as.Bools(ctx); err != nil { @@ -1129,11 +1153,6 @@ func (as *AlertSelect) BoolX(ctx context.Context) bool { } func (as *AlertSelect) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range as.fields { - if !alert.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for selection", f)} - } - } rows := &sql.Rows{} query, args := as.sqlQuery().Query() if err := as.driver.Query(ctx, query, args, rows); err != nil { diff --git a/pkg/database/ent/alert_update.go b/pkg/database/ent/alert_update.go index 48b4daef9..5bcf5e92f 100644 --- a/pkg/database/ent/alert_update.go +++ b/pkg/database/ent/alert_update.go @@ -21,24 +21,23 @@ import ( // AlertUpdate is the builder for updating Alert entities. type AlertUpdate struct { config - hooks []Hook - mutation *AlertMutation - predicates []predicate.Alert + hooks []Hook + mutation *AlertMutation } -// Where adds a new predicate for the builder. +// Where adds a new predicate for the AlertUpdate builder. func (au *AlertUpdate) Where(ps ...predicate.Alert) *AlertUpdate { - au.predicates = append(au.predicates, ps...) + au.mutation.predicates = append(au.mutation.predicates, ps...) return au } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (au *AlertUpdate) SetCreatedAt(t time.Time) *AlertUpdate { au.mutation.SetCreatedAt(t) return au } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (au *AlertUpdate) SetNillableCreatedAt(t *time.Time) *AlertUpdate { if t != nil { au.SetCreatedAt(*t) @@ -46,13 +45,13 @@ func (au *AlertUpdate) SetNillableCreatedAt(t *time.Time) *AlertUpdate { return au } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (au *AlertUpdate) SetUpdatedAt(t time.Time) *AlertUpdate { au.mutation.SetUpdatedAt(t) return au } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (au *AlertUpdate) SetNillableUpdatedAt(t *time.Time) *AlertUpdate { if t != nil { au.SetUpdatedAt(*t) @@ -60,19 +59,19 @@ func (au *AlertUpdate) SetNillableUpdatedAt(t *time.Time) *AlertUpdate { return au } -// SetScenario sets the scenario field. +// SetScenario sets the "scenario" field. func (au *AlertUpdate) SetScenario(s string) *AlertUpdate { au.mutation.SetScenario(s) return au } -// SetBucketId sets the bucketId field. +// SetBucketId sets the "bucketId" field. func (au *AlertUpdate) SetBucketId(s string) *AlertUpdate { au.mutation.SetBucketId(s) return au } -// SetNillableBucketId sets the bucketId field if the given value is not nil. +// SetNillableBucketId sets the "bucketId" field if the given value is not nil. func (au *AlertUpdate) SetNillableBucketId(s *string) *AlertUpdate { if s != nil { au.SetBucketId(*s) @@ -80,19 +79,19 @@ func (au *AlertUpdate) SetNillableBucketId(s *string) *AlertUpdate { return au } -// ClearBucketId clears the value of bucketId. +// ClearBucketId clears the value of the "bucketId" field. func (au *AlertUpdate) ClearBucketId() *AlertUpdate { au.mutation.ClearBucketId() return au } -// SetMessage sets the message field. +// SetMessage sets the "message" field. func (au *AlertUpdate) SetMessage(s string) *AlertUpdate { au.mutation.SetMessage(s) return au } -// SetNillableMessage sets the message field if the given value is not nil. +// SetNillableMessage sets the "message" field if the given value is not nil. func (au *AlertUpdate) SetNillableMessage(s *string) *AlertUpdate { if s != nil { au.SetMessage(*s) @@ -100,20 +99,20 @@ func (au *AlertUpdate) SetNillableMessage(s *string) *AlertUpdate { return au } -// ClearMessage clears the value of message. +// ClearMessage clears the value of the "message" field. func (au *AlertUpdate) ClearMessage() *AlertUpdate { au.mutation.ClearMessage() return au } -// SetEventsCount sets the eventsCount field. +// SetEventsCount sets the "eventsCount" field. func (au *AlertUpdate) SetEventsCount(i int32) *AlertUpdate { au.mutation.ResetEventsCount() au.mutation.SetEventsCount(i) return au } -// SetNillableEventsCount sets the eventsCount field if the given value is not nil. +// SetNillableEventsCount sets the "eventsCount" field if the given value is not nil. func (au *AlertUpdate) SetNillableEventsCount(i *int32) *AlertUpdate { if i != nil { au.SetEventsCount(*i) @@ -121,25 +120,25 @@ func (au *AlertUpdate) SetNillableEventsCount(i *int32) *AlertUpdate { return au } -// AddEventsCount adds i to eventsCount. +// AddEventsCount adds i to the "eventsCount" field. func (au *AlertUpdate) AddEventsCount(i int32) *AlertUpdate { au.mutation.AddEventsCount(i) return au } -// ClearEventsCount clears the value of eventsCount. +// ClearEventsCount clears the value of the "eventsCount" field. func (au *AlertUpdate) ClearEventsCount() *AlertUpdate { au.mutation.ClearEventsCount() return au } -// SetStartedAt sets the startedAt field. +// SetStartedAt sets the "startedAt" field. func (au *AlertUpdate) SetStartedAt(t time.Time) *AlertUpdate { au.mutation.SetStartedAt(t) return au } -// SetNillableStartedAt sets the startedAt field if the given value is not nil. +// SetNillableStartedAt sets the "startedAt" field if the given value is not nil. func (au *AlertUpdate) SetNillableStartedAt(t *time.Time) *AlertUpdate { if t != nil { au.SetStartedAt(*t) @@ -147,19 +146,19 @@ func (au *AlertUpdate) SetNillableStartedAt(t *time.Time) *AlertUpdate { return au } -// ClearStartedAt clears the value of startedAt. +// ClearStartedAt clears the value of the "startedAt" field. func (au *AlertUpdate) ClearStartedAt() *AlertUpdate { au.mutation.ClearStartedAt() return au } -// SetStoppedAt sets the stoppedAt field. +// SetStoppedAt sets the "stoppedAt" field. func (au *AlertUpdate) SetStoppedAt(t time.Time) *AlertUpdate { au.mutation.SetStoppedAt(t) return au } -// SetNillableStoppedAt sets the stoppedAt field if the given value is not nil. +// SetNillableStoppedAt sets the "stoppedAt" field if the given value is not nil. func (au *AlertUpdate) SetNillableStoppedAt(t *time.Time) *AlertUpdate { if t != nil { au.SetStoppedAt(*t) @@ -167,19 +166,19 @@ func (au *AlertUpdate) SetNillableStoppedAt(t *time.Time) *AlertUpdate { return au } -// ClearStoppedAt clears the value of stoppedAt. +// ClearStoppedAt clears the value of the "stoppedAt" field. func (au *AlertUpdate) ClearStoppedAt() *AlertUpdate { au.mutation.ClearStoppedAt() return au } -// SetSourceIp sets the sourceIp field. +// SetSourceIp sets the "sourceIp" field. func (au *AlertUpdate) SetSourceIp(s string) *AlertUpdate { au.mutation.SetSourceIp(s) return au } -// SetNillableSourceIp sets the sourceIp field if the given value is not nil. +// SetNillableSourceIp sets the "sourceIp" field if the given value is not nil. func (au *AlertUpdate) SetNillableSourceIp(s *string) *AlertUpdate { if s != nil { au.SetSourceIp(*s) @@ -187,19 +186,19 @@ func (au *AlertUpdate) SetNillableSourceIp(s *string) *AlertUpdate { return au } -// ClearSourceIp clears the value of sourceIp. +// ClearSourceIp clears the value of the "sourceIp" field. func (au *AlertUpdate) ClearSourceIp() *AlertUpdate { au.mutation.ClearSourceIp() return au } -// SetSourceRange sets the sourceRange field. +// SetSourceRange sets the "sourceRange" field. func (au *AlertUpdate) SetSourceRange(s string) *AlertUpdate { au.mutation.SetSourceRange(s) return au } -// SetNillableSourceRange sets the sourceRange field if the given value is not nil. +// SetNillableSourceRange sets the "sourceRange" field if the given value is not nil. func (au *AlertUpdate) SetNillableSourceRange(s *string) *AlertUpdate { if s != nil { au.SetSourceRange(*s) @@ -207,19 +206,19 @@ func (au *AlertUpdate) SetNillableSourceRange(s *string) *AlertUpdate { return au } -// ClearSourceRange clears the value of sourceRange. +// ClearSourceRange clears the value of the "sourceRange" field. func (au *AlertUpdate) ClearSourceRange() *AlertUpdate { au.mutation.ClearSourceRange() return au } -// SetSourceAsNumber sets the sourceAsNumber field. +// SetSourceAsNumber sets the "sourceAsNumber" field. func (au *AlertUpdate) SetSourceAsNumber(s string) *AlertUpdate { au.mutation.SetSourceAsNumber(s) return au } -// SetNillableSourceAsNumber sets the sourceAsNumber field if the given value is not nil. +// SetNillableSourceAsNumber sets the "sourceAsNumber" field if the given value is not nil. func (au *AlertUpdate) SetNillableSourceAsNumber(s *string) *AlertUpdate { if s != nil { au.SetSourceAsNumber(*s) @@ -227,19 +226,19 @@ func (au *AlertUpdate) SetNillableSourceAsNumber(s *string) *AlertUpdate { return au } -// ClearSourceAsNumber clears the value of sourceAsNumber. +// ClearSourceAsNumber clears the value of the "sourceAsNumber" field. func (au *AlertUpdate) ClearSourceAsNumber() *AlertUpdate { au.mutation.ClearSourceAsNumber() return au } -// SetSourceAsName sets the sourceAsName field. +// SetSourceAsName sets the "sourceAsName" field. func (au *AlertUpdate) SetSourceAsName(s string) *AlertUpdate { au.mutation.SetSourceAsName(s) return au } -// SetNillableSourceAsName sets the sourceAsName field if the given value is not nil. +// SetNillableSourceAsName sets the "sourceAsName" field if the given value is not nil. func (au *AlertUpdate) SetNillableSourceAsName(s *string) *AlertUpdate { if s != nil { au.SetSourceAsName(*s) @@ -247,19 +246,19 @@ func (au *AlertUpdate) SetNillableSourceAsName(s *string) *AlertUpdate { return au } -// ClearSourceAsName clears the value of sourceAsName. +// ClearSourceAsName clears the value of the "sourceAsName" field. func (au *AlertUpdate) ClearSourceAsName() *AlertUpdate { au.mutation.ClearSourceAsName() return au } -// SetSourceCountry sets the sourceCountry field. +// SetSourceCountry sets the "sourceCountry" field. func (au *AlertUpdate) SetSourceCountry(s string) *AlertUpdate { au.mutation.SetSourceCountry(s) return au } -// SetNillableSourceCountry sets the sourceCountry field if the given value is not nil. +// SetNillableSourceCountry sets the "sourceCountry" field if the given value is not nil. func (au *AlertUpdate) SetNillableSourceCountry(s *string) *AlertUpdate { if s != nil { au.SetSourceCountry(*s) @@ -267,20 +266,20 @@ func (au *AlertUpdate) SetNillableSourceCountry(s *string) *AlertUpdate { return au } -// ClearSourceCountry clears the value of sourceCountry. +// ClearSourceCountry clears the value of the "sourceCountry" field. func (au *AlertUpdate) ClearSourceCountry() *AlertUpdate { au.mutation.ClearSourceCountry() return au } -// SetSourceLatitude sets the sourceLatitude field. +// SetSourceLatitude sets the "sourceLatitude" field. func (au *AlertUpdate) SetSourceLatitude(f float32) *AlertUpdate { au.mutation.ResetSourceLatitude() au.mutation.SetSourceLatitude(f) return au } -// SetNillableSourceLatitude sets the sourceLatitude field if the given value is not nil. +// SetNillableSourceLatitude sets the "sourceLatitude" field if the given value is not nil. func (au *AlertUpdate) SetNillableSourceLatitude(f *float32) *AlertUpdate { if f != nil { au.SetSourceLatitude(*f) @@ -288,26 +287,26 @@ func (au *AlertUpdate) SetNillableSourceLatitude(f *float32) *AlertUpdate { return au } -// AddSourceLatitude adds f to sourceLatitude. +// AddSourceLatitude adds f to the "sourceLatitude" field. func (au *AlertUpdate) AddSourceLatitude(f float32) *AlertUpdate { au.mutation.AddSourceLatitude(f) return au } -// ClearSourceLatitude clears the value of sourceLatitude. +// ClearSourceLatitude clears the value of the "sourceLatitude" field. func (au *AlertUpdate) ClearSourceLatitude() *AlertUpdate { au.mutation.ClearSourceLatitude() return au } -// SetSourceLongitude sets the sourceLongitude field. +// SetSourceLongitude sets the "sourceLongitude" field. func (au *AlertUpdate) SetSourceLongitude(f float32) *AlertUpdate { au.mutation.ResetSourceLongitude() au.mutation.SetSourceLongitude(f) return au } -// SetNillableSourceLongitude sets the sourceLongitude field if the given value is not nil. +// SetNillableSourceLongitude sets the "sourceLongitude" field if the given value is not nil. func (au *AlertUpdate) SetNillableSourceLongitude(f *float32) *AlertUpdate { if f != nil { au.SetSourceLongitude(*f) @@ -315,25 +314,25 @@ func (au *AlertUpdate) SetNillableSourceLongitude(f *float32) *AlertUpdate { return au } -// AddSourceLongitude adds f to sourceLongitude. +// AddSourceLongitude adds f to the "sourceLongitude" field. func (au *AlertUpdate) AddSourceLongitude(f float32) *AlertUpdate { au.mutation.AddSourceLongitude(f) return au } -// ClearSourceLongitude clears the value of sourceLongitude. +// ClearSourceLongitude clears the value of the "sourceLongitude" field. func (au *AlertUpdate) ClearSourceLongitude() *AlertUpdate { au.mutation.ClearSourceLongitude() return au } -// SetSourceScope sets the sourceScope field. +// SetSourceScope sets the "sourceScope" field. func (au *AlertUpdate) SetSourceScope(s string) *AlertUpdate { au.mutation.SetSourceScope(s) return au } -// SetNillableSourceScope sets the sourceScope field if the given value is not nil. +// SetNillableSourceScope sets the "sourceScope" field if the given value is not nil. func (au *AlertUpdate) SetNillableSourceScope(s *string) *AlertUpdate { if s != nil { au.SetSourceScope(*s) @@ -341,19 +340,19 @@ func (au *AlertUpdate) SetNillableSourceScope(s *string) *AlertUpdate { return au } -// ClearSourceScope clears the value of sourceScope. +// ClearSourceScope clears the value of the "sourceScope" field. func (au *AlertUpdate) ClearSourceScope() *AlertUpdate { au.mutation.ClearSourceScope() return au } -// SetSourceValue sets the sourceValue field. +// SetSourceValue sets the "sourceValue" field. func (au *AlertUpdate) SetSourceValue(s string) *AlertUpdate { au.mutation.SetSourceValue(s) return au } -// SetNillableSourceValue sets the sourceValue field if the given value is not nil. +// SetNillableSourceValue sets the "sourceValue" field if the given value is not nil. func (au *AlertUpdate) SetNillableSourceValue(s *string) *AlertUpdate { if s != nil { au.SetSourceValue(*s) @@ -361,20 +360,20 @@ func (au *AlertUpdate) SetNillableSourceValue(s *string) *AlertUpdate { return au } -// ClearSourceValue clears the value of sourceValue. +// ClearSourceValue clears the value of the "sourceValue" field. func (au *AlertUpdate) ClearSourceValue() *AlertUpdate { au.mutation.ClearSourceValue() return au } -// SetCapacity sets the capacity field. +// SetCapacity sets the "capacity" field. func (au *AlertUpdate) SetCapacity(i int32) *AlertUpdate { au.mutation.ResetCapacity() au.mutation.SetCapacity(i) return au } -// SetNillableCapacity sets the capacity field if the given value is not nil. +// SetNillableCapacity sets the "capacity" field if the given value is not nil. func (au *AlertUpdate) SetNillableCapacity(i *int32) *AlertUpdate { if i != nil { au.SetCapacity(*i) @@ -382,25 +381,25 @@ func (au *AlertUpdate) SetNillableCapacity(i *int32) *AlertUpdate { return au } -// AddCapacity adds i to capacity. +// AddCapacity adds i to the "capacity" field. func (au *AlertUpdate) AddCapacity(i int32) *AlertUpdate { au.mutation.AddCapacity(i) return au } -// ClearCapacity clears the value of capacity. +// ClearCapacity clears the value of the "capacity" field. func (au *AlertUpdate) ClearCapacity() *AlertUpdate { au.mutation.ClearCapacity() return au } -// SetLeakSpeed sets the leakSpeed field. +// SetLeakSpeed sets the "leakSpeed" field. func (au *AlertUpdate) SetLeakSpeed(s string) *AlertUpdate { au.mutation.SetLeakSpeed(s) return au } -// SetNillableLeakSpeed sets the leakSpeed field if the given value is not nil. +// SetNillableLeakSpeed sets the "leakSpeed" field if the given value is not nil. func (au *AlertUpdate) SetNillableLeakSpeed(s *string) *AlertUpdate { if s != nil { au.SetLeakSpeed(*s) @@ -408,19 +407,19 @@ func (au *AlertUpdate) SetNillableLeakSpeed(s *string) *AlertUpdate { return au } -// ClearLeakSpeed clears the value of leakSpeed. +// ClearLeakSpeed clears the value of the "leakSpeed" field. func (au *AlertUpdate) ClearLeakSpeed() *AlertUpdate { au.mutation.ClearLeakSpeed() return au } -// SetScenarioVersion sets the scenarioVersion field. +// SetScenarioVersion sets the "scenarioVersion" field. func (au *AlertUpdate) SetScenarioVersion(s string) *AlertUpdate { au.mutation.SetScenarioVersion(s) return au } -// SetNillableScenarioVersion sets the scenarioVersion field if the given value is not nil. +// SetNillableScenarioVersion sets the "scenarioVersion" field if the given value is not nil. func (au *AlertUpdate) SetNillableScenarioVersion(s *string) *AlertUpdate { if s != nil { au.SetScenarioVersion(*s) @@ -428,19 +427,19 @@ func (au *AlertUpdate) SetNillableScenarioVersion(s *string) *AlertUpdate { return au } -// ClearScenarioVersion clears the value of scenarioVersion. +// ClearScenarioVersion clears the value of the "scenarioVersion" field. func (au *AlertUpdate) ClearScenarioVersion() *AlertUpdate { au.mutation.ClearScenarioVersion() return au } -// SetScenarioHash sets the scenarioHash field. +// SetScenarioHash sets the "scenarioHash" field. func (au *AlertUpdate) SetScenarioHash(s string) *AlertUpdate { au.mutation.SetScenarioHash(s) return au } -// SetNillableScenarioHash sets the scenarioHash field if the given value is not nil. +// SetNillableScenarioHash sets the "scenarioHash" field if the given value is not nil. func (au *AlertUpdate) SetNillableScenarioHash(s *string) *AlertUpdate { if s != nil { au.SetScenarioHash(*s) @@ -448,19 +447,19 @@ func (au *AlertUpdate) SetNillableScenarioHash(s *string) *AlertUpdate { return au } -// ClearScenarioHash clears the value of scenarioHash. +// ClearScenarioHash clears the value of the "scenarioHash" field. func (au *AlertUpdate) ClearScenarioHash() *AlertUpdate { au.mutation.ClearScenarioHash() return au } -// SetSimulated sets the simulated field. +// SetSimulated sets the "simulated" field. func (au *AlertUpdate) SetSimulated(b bool) *AlertUpdate { au.mutation.SetSimulated(b) return au } -// SetNillableSimulated sets the simulated field if the given value is not nil. +// SetNillableSimulated sets the "simulated" field if the given value is not nil. func (au *AlertUpdate) SetNillableSimulated(b *bool) *AlertUpdate { if b != nil { au.SetSimulated(*b) @@ -468,13 +467,13 @@ func (au *AlertUpdate) SetNillableSimulated(b *bool) *AlertUpdate { return au } -// SetOwnerID sets the owner edge to Machine by id. +// SetOwnerID sets the "owner" edge to the Machine entity by ID. func (au *AlertUpdate) SetOwnerID(id int) *AlertUpdate { au.mutation.SetOwnerID(id) return au } -// SetNillableOwnerID sets the owner edge to Machine by id if the given value is not nil. +// SetNillableOwnerID sets the "owner" edge to the Machine entity by ID if the given value is not nil. func (au *AlertUpdate) SetNillableOwnerID(id *int) *AlertUpdate { if id != nil { au = au.SetOwnerID(*id) @@ -482,18 +481,18 @@ func (au *AlertUpdate) SetNillableOwnerID(id *int) *AlertUpdate { return au } -// SetOwner sets the owner edge to Machine. +// SetOwner sets the "owner" edge to the Machine entity. func (au *AlertUpdate) SetOwner(m *Machine) *AlertUpdate { return au.SetOwnerID(m.ID) } -// AddDecisionIDs adds the decisions edge to Decision by ids. +// AddDecisionIDs adds the "decisions" edge to the Decision entity by IDs. func (au *AlertUpdate) AddDecisionIDs(ids ...int) *AlertUpdate { au.mutation.AddDecisionIDs(ids...) return au } -// AddDecisions adds the decisions edges to Decision. +// AddDecisions adds the "decisions" edges to the Decision entity. func (au *AlertUpdate) AddDecisions(d ...*Decision) *AlertUpdate { ids := make([]int, len(d)) for i := range d { @@ -502,13 +501,13 @@ func (au *AlertUpdate) AddDecisions(d ...*Decision) *AlertUpdate { return au.AddDecisionIDs(ids...) } -// AddEventIDs adds the events edge to Event by ids. +// AddEventIDs adds the "events" edge to the Event entity by IDs. func (au *AlertUpdate) AddEventIDs(ids ...int) *AlertUpdate { au.mutation.AddEventIDs(ids...) return au } -// AddEvents adds the events edges to Event. +// AddEvents adds the "events" edges to the Event entity. func (au *AlertUpdate) AddEvents(e ...*Event) *AlertUpdate { ids := make([]int, len(e)) for i := range e { @@ -517,13 +516,13 @@ func (au *AlertUpdate) AddEvents(e ...*Event) *AlertUpdate { return au.AddEventIDs(ids...) } -// AddMetaIDs adds the metas edge to Meta by ids. +// AddMetaIDs adds the "metas" edge to the Meta entity by IDs. func (au *AlertUpdate) AddMetaIDs(ids ...int) *AlertUpdate { au.mutation.AddMetaIDs(ids...) return au } -// AddMetas adds the metas edges to Meta. +// AddMetas adds the "metas" edges to the Meta entity. func (au *AlertUpdate) AddMetas(m ...*Meta) *AlertUpdate { ids := make([]int, len(m)) for i := range m { @@ -537,25 +536,25 @@ func (au *AlertUpdate) Mutation() *AlertMutation { return au.mutation } -// ClearOwner clears the "owner" edge to type Machine. +// ClearOwner clears the "owner" edge to the Machine entity. func (au *AlertUpdate) ClearOwner() *AlertUpdate { au.mutation.ClearOwner() return au } -// ClearDecisions clears all "decisions" edges to type Decision. +// ClearDecisions clears all "decisions" edges to the Decision entity. func (au *AlertUpdate) ClearDecisions() *AlertUpdate { au.mutation.ClearDecisions() return au } -// RemoveDecisionIDs removes the decisions edge to Decision by ids. +// RemoveDecisionIDs removes the "decisions" edge to Decision entities by IDs. func (au *AlertUpdate) RemoveDecisionIDs(ids ...int) *AlertUpdate { au.mutation.RemoveDecisionIDs(ids...) return au } -// RemoveDecisions removes decisions edges to Decision. +// RemoveDecisions removes "decisions" edges to Decision entities. func (au *AlertUpdate) RemoveDecisions(d ...*Decision) *AlertUpdate { ids := make([]int, len(d)) for i := range d { @@ -564,19 +563,19 @@ func (au *AlertUpdate) RemoveDecisions(d ...*Decision) *AlertUpdate { return au.RemoveDecisionIDs(ids...) } -// ClearEvents clears all "events" edges to type Event. +// ClearEvents clears all "events" edges to the Event entity. func (au *AlertUpdate) ClearEvents() *AlertUpdate { au.mutation.ClearEvents() return au } -// RemoveEventIDs removes the events edge to Event by ids. +// RemoveEventIDs removes the "events" edge to Event entities by IDs. func (au *AlertUpdate) RemoveEventIDs(ids ...int) *AlertUpdate { au.mutation.RemoveEventIDs(ids...) return au } -// RemoveEvents removes events edges to Event. +// RemoveEvents removes "events" edges to Event entities. func (au *AlertUpdate) RemoveEvents(e ...*Event) *AlertUpdate { ids := make([]int, len(e)) for i := range e { @@ -585,19 +584,19 @@ func (au *AlertUpdate) RemoveEvents(e ...*Event) *AlertUpdate { return au.RemoveEventIDs(ids...) } -// ClearMetas clears all "metas" edges to type Meta. +// ClearMetas clears all "metas" edges to the Meta entity. func (au *AlertUpdate) ClearMetas() *AlertUpdate { au.mutation.ClearMetas() return au } -// RemoveMetaIDs removes the metas edge to Meta by ids. +// RemoveMetaIDs removes the "metas" edge to Meta entities by IDs. func (au *AlertUpdate) RemoveMetaIDs(ids ...int) *AlertUpdate { au.mutation.RemoveMetaIDs(ids...) return au } -// RemoveMetas removes metas edges to Meta. +// RemoveMetas removes "metas" edges to Meta entities. func (au *AlertUpdate) RemoveMetas(m ...*Meta) *AlertUpdate { ids := make([]int, len(m)) for i := range m { @@ -606,7 +605,7 @@ func (au *AlertUpdate) RemoveMetas(m ...*Meta) *AlertUpdate { return au.RemoveMetaIDs(ids...) } -// Save executes the query and returns the number of rows/vertices matched by this operation. +// Save executes the query and returns the number of nodes affected by the update operation. func (au *AlertUpdate) Save(ctx context.Context) (int, error) { var ( err error @@ -668,7 +667,7 @@ func (au *AlertUpdate) sqlSave(ctx context.Context) (n int, err error) { }, }, } - if ps := au.predicates; len(ps) > 0 { + if ps := au.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) @@ -1180,13 +1179,13 @@ type AlertUpdateOne struct { mutation *AlertMutation } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (auo *AlertUpdateOne) SetCreatedAt(t time.Time) *AlertUpdateOne { auo.mutation.SetCreatedAt(t) return auo } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableCreatedAt(t *time.Time) *AlertUpdateOne { if t != nil { auo.SetCreatedAt(*t) @@ -1194,13 +1193,13 @@ func (auo *AlertUpdateOne) SetNillableCreatedAt(t *time.Time) *AlertUpdateOne { return auo } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (auo *AlertUpdateOne) SetUpdatedAt(t time.Time) *AlertUpdateOne { auo.mutation.SetUpdatedAt(t) return auo } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableUpdatedAt(t *time.Time) *AlertUpdateOne { if t != nil { auo.SetUpdatedAt(*t) @@ -1208,19 +1207,19 @@ func (auo *AlertUpdateOne) SetNillableUpdatedAt(t *time.Time) *AlertUpdateOne { return auo } -// SetScenario sets the scenario field. +// SetScenario sets the "scenario" field. func (auo *AlertUpdateOne) SetScenario(s string) *AlertUpdateOne { auo.mutation.SetScenario(s) return auo } -// SetBucketId sets the bucketId field. +// SetBucketId sets the "bucketId" field. func (auo *AlertUpdateOne) SetBucketId(s string) *AlertUpdateOne { auo.mutation.SetBucketId(s) return auo } -// SetNillableBucketId sets the bucketId field if the given value is not nil. +// SetNillableBucketId sets the "bucketId" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableBucketId(s *string) *AlertUpdateOne { if s != nil { auo.SetBucketId(*s) @@ -1228,19 +1227,19 @@ func (auo *AlertUpdateOne) SetNillableBucketId(s *string) *AlertUpdateOne { return auo } -// ClearBucketId clears the value of bucketId. +// ClearBucketId clears the value of the "bucketId" field. func (auo *AlertUpdateOne) ClearBucketId() *AlertUpdateOne { auo.mutation.ClearBucketId() return auo } -// SetMessage sets the message field. +// SetMessage sets the "message" field. func (auo *AlertUpdateOne) SetMessage(s string) *AlertUpdateOne { auo.mutation.SetMessage(s) return auo } -// SetNillableMessage sets the message field if the given value is not nil. +// SetNillableMessage sets the "message" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableMessage(s *string) *AlertUpdateOne { if s != nil { auo.SetMessage(*s) @@ -1248,20 +1247,20 @@ func (auo *AlertUpdateOne) SetNillableMessage(s *string) *AlertUpdateOne { return auo } -// ClearMessage clears the value of message. +// ClearMessage clears the value of the "message" field. func (auo *AlertUpdateOne) ClearMessage() *AlertUpdateOne { auo.mutation.ClearMessage() return auo } -// SetEventsCount sets the eventsCount field. +// SetEventsCount sets the "eventsCount" field. func (auo *AlertUpdateOne) SetEventsCount(i int32) *AlertUpdateOne { auo.mutation.ResetEventsCount() auo.mutation.SetEventsCount(i) return auo } -// SetNillableEventsCount sets the eventsCount field if the given value is not nil. +// SetNillableEventsCount sets the "eventsCount" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableEventsCount(i *int32) *AlertUpdateOne { if i != nil { auo.SetEventsCount(*i) @@ -1269,25 +1268,25 @@ func (auo *AlertUpdateOne) SetNillableEventsCount(i *int32) *AlertUpdateOne { return auo } -// AddEventsCount adds i to eventsCount. +// AddEventsCount adds i to the "eventsCount" field. func (auo *AlertUpdateOne) AddEventsCount(i int32) *AlertUpdateOne { auo.mutation.AddEventsCount(i) return auo } -// ClearEventsCount clears the value of eventsCount. +// ClearEventsCount clears the value of the "eventsCount" field. func (auo *AlertUpdateOne) ClearEventsCount() *AlertUpdateOne { auo.mutation.ClearEventsCount() return auo } -// SetStartedAt sets the startedAt field. +// SetStartedAt sets the "startedAt" field. func (auo *AlertUpdateOne) SetStartedAt(t time.Time) *AlertUpdateOne { auo.mutation.SetStartedAt(t) return auo } -// SetNillableStartedAt sets the startedAt field if the given value is not nil. +// SetNillableStartedAt sets the "startedAt" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableStartedAt(t *time.Time) *AlertUpdateOne { if t != nil { auo.SetStartedAt(*t) @@ -1295,19 +1294,19 @@ func (auo *AlertUpdateOne) SetNillableStartedAt(t *time.Time) *AlertUpdateOne { return auo } -// ClearStartedAt clears the value of startedAt. +// ClearStartedAt clears the value of the "startedAt" field. func (auo *AlertUpdateOne) ClearStartedAt() *AlertUpdateOne { auo.mutation.ClearStartedAt() return auo } -// SetStoppedAt sets the stoppedAt field. +// SetStoppedAt sets the "stoppedAt" field. func (auo *AlertUpdateOne) SetStoppedAt(t time.Time) *AlertUpdateOne { auo.mutation.SetStoppedAt(t) return auo } -// SetNillableStoppedAt sets the stoppedAt field if the given value is not nil. +// SetNillableStoppedAt sets the "stoppedAt" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableStoppedAt(t *time.Time) *AlertUpdateOne { if t != nil { auo.SetStoppedAt(*t) @@ -1315,19 +1314,19 @@ func (auo *AlertUpdateOne) SetNillableStoppedAt(t *time.Time) *AlertUpdateOne { return auo } -// ClearStoppedAt clears the value of stoppedAt. +// ClearStoppedAt clears the value of the "stoppedAt" field. func (auo *AlertUpdateOne) ClearStoppedAt() *AlertUpdateOne { auo.mutation.ClearStoppedAt() return auo } -// SetSourceIp sets the sourceIp field. +// SetSourceIp sets the "sourceIp" field. func (auo *AlertUpdateOne) SetSourceIp(s string) *AlertUpdateOne { auo.mutation.SetSourceIp(s) return auo } -// SetNillableSourceIp sets the sourceIp field if the given value is not nil. +// SetNillableSourceIp sets the "sourceIp" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableSourceIp(s *string) *AlertUpdateOne { if s != nil { auo.SetSourceIp(*s) @@ -1335,19 +1334,19 @@ func (auo *AlertUpdateOne) SetNillableSourceIp(s *string) *AlertUpdateOne { return auo } -// ClearSourceIp clears the value of sourceIp. +// ClearSourceIp clears the value of the "sourceIp" field. func (auo *AlertUpdateOne) ClearSourceIp() *AlertUpdateOne { auo.mutation.ClearSourceIp() return auo } -// SetSourceRange sets the sourceRange field. +// SetSourceRange sets the "sourceRange" field. func (auo *AlertUpdateOne) SetSourceRange(s string) *AlertUpdateOne { auo.mutation.SetSourceRange(s) return auo } -// SetNillableSourceRange sets the sourceRange field if the given value is not nil. +// SetNillableSourceRange sets the "sourceRange" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableSourceRange(s *string) *AlertUpdateOne { if s != nil { auo.SetSourceRange(*s) @@ -1355,19 +1354,19 @@ func (auo *AlertUpdateOne) SetNillableSourceRange(s *string) *AlertUpdateOne { return auo } -// ClearSourceRange clears the value of sourceRange. +// ClearSourceRange clears the value of the "sourceRange" field. func (auo *AlertUpdateOne) ClearSourceRange() *AlertUpdateOne { auo.mutation.ClearSourceRange() return auo } -// SetSourceAsNumber sets the sourceAsNumber field. +// SetSourceAsNumber sets the "sourceAsNumber" field. func (auo *AlertUpdateOne) SetSourceAsNumber(s string) *AlertUpdateOne { auo.mutation.SetSourceAsNumber(s) return auo } -// SetNillableSourceAsNumber sets the sourceAsNumber field if the given value is not nil. +// SetNillableSourceAsNumber sets the "sourceAsNumber" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableSourceAsNumber(s *string) *AlertUpdateOne { if s != nil { auo.SetSourceAsNumber(*s) @@ -1375,19 +1374,19 @@ func (auo *AlertUpdateOne) SetNillableSourceAsNumber(s *string) *AlertUpdateOne return auo } -// ClearSourceAsNumber clears the value of sourceAsNumber. +// ClearSourceAsNumber clears the value of the "sourceAsNumber" field. func (auo *AlertUpdateOne) ClearSourceAsNumber() *AlertUpdateOne { auo.mutation.ClearSourceAsNumber() return auo } -// SetSourceAsName sets the sourceAsName field. +// SetSourceAsName sets the "sourceAsName" field. func (auo *AlertUpdateOne) SetSourceAsName(s string) *AlertUpdateOne { auo.mutation.SetSourceAsName(s) return auo } -// SetNillableSourceAsName sets the sourceAsName field if the given value is not nil. +// SetNillableSourceAsName sets the "sourceAsName" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableSourceAsName(s *string) *AlertUpdateOne { if s != nil { auo.SetSourceAsName(*s) @@ -1395,19 +1394,19 @@ func (auo *AlertUpdateOne) SetNillableSourceAsName(s *string) *AlertUpdateOne { return auo } -// ClearSourceAsName clears the value of sourceAsName. +// ClearSourceAsName clears the value of the "sourceAsName" field. func (auo *AlertUpdateOne) ClearSourceAsName() *AlertUpdateOne { auo.mutation.ClearSourceAsName() return auo } -// SetSourceCountry sets the sourceCountry field. +// SetSourceCountry sets the "sourceCountry" field. func (auo *AlertUpdateOne) SetSourceCountry(s string) *AlertUpdateOne { auo.mutation.SetSourceCountry(s) return auo } -// SetNillableSourceCountry sets the sourceCountry field if the given value is not nil. +// SetNillableSourceCountry sets the "sourceCountry" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableSourceCountry(s *string) *AlertUpdateOne { if s != nil { auo.SetSourceCountry(*s) @@ -1415,20 +1414,20 @@ func (auo *AlertUpdateOne) SetNillableSourceCountry(s *string) *AlertUpdateOne { return auo } -// ClearSourceCountry clears the value of sourceCountry. +// ClearSourceCountry clears the value of the "sourceCountry" field. func (auo *AlertUpdateOne) ClearSourceCountry() *AlertUpdateOne { auo.mutation.ClearSourceCountry() return auo } -// SetSourceLatitude sets the sourceLatitude field. +// SetSourceLatitude sets the "sourceLatitude" field. func (auo *AlertUpdateOne) SetSourceLatitude(f float32) *AlertUpdateOne { auo.mutation.ResetSourceLatitude() auo.mutation.SetSourceLatitude(f) return auo } -// SetNillableSourceLatitude sets the sourceLatitude field if the given value is not nil. +// SetNillableSourceLatitude sets the "sourceLatitude" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableSourceLatitude(f *float32) *AlertUpdateOne { if f != nil { auo.SetSourceLatitude(*f) @@ -1436,26 +1435,26 @@ func (auo *AlertUpdateOne) SetNillableSourceLatitude(f *float32) *AlertUpdateOne return auo } -// AddSourceLatitude adds f to sourceLatitude. +// AddSourceLatitude adds f to the "sourceLatitude" field. func (auo *AlertUpdateOne) AddSourceLatitude(f float32) *AlertUpdateOne { auo.mutation.AddSourceLatitude(f) return auo } -// ClearSourceLatitude clears the value of sourceLatitude. +// ClearSourceLatitude clears the value of the "sourceLatitude" field. func (auo *AlertUpdateOne) ClearSourceLatitude() *AlertUpdateOne { auo.mutation.ClearSourceLatitude() return auo } -// SetSourceLongitude sets the sourceLongitude field. +// SetSourceLongitude sets the "sourceLongitude" field. func (auo *AlertUpdateOne) SetSourceLongitude(f float32) *AlertUpdateOne { auo.mutation.ResetSourceLongitude() auo.mutation.SetSourceLongitude(f) return auo } -// SetNillableSourceLongitude sets the sourceLongitude field if the given value is not nil. +// SetNillableSourceLongitude sets the "sourceLongitude" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableSourceLongitude(f *float32) *AlertUpdateOne { if f != nil { auo.SetSourceLongitude(*f) @@ -1463,25 +1462,25 @@ func (auo *AlertUpdateOne) SetNillableSourceLongitude(f *float32) *AlertUpdateOn return auo } -// AddSourceLongitude adds f to sourceLongitude. +// AddSourceLongitude adds f to the "sourceLongitude" field. func (auo *AlertUpdateOne) AddSourceLongitude(f float32) *AlertUpdateOne { auo.mutation.AddSourceLongitude(f) return auo } -// ClearSourceLongitude clears the value of sourceLongitude. +// ClearSourceLongitude clears the value of the "sourceLongitude" field. func (auo *AlertUpdateOne) ClearSourceLongitude() *AlertUpdateOne { auo.mutation.ClearSourceLongitude() return auo } -// SetSourceScope sets the sourceScope field. +// SetSourceScope sets the "sourceScope" field. func (auo *AlertUpdateOne) SetSourceScope(s string) *AlertUpdateOne { auo.mutation.SetSourceScope(s) return auo } -// SetNillableSourceScope sets the sourceScope field if the given value is not nil. +// SetNillableSourceScope sets the "sourceScope" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableSourceScope(s *string) *AlertUpdateOne { if s != nil { auo.SetSourceScope(*s) @@ -1489,19 +1488,19 @@ func (auo *AlertUpdateOne) SetNillableSourceScope(s *string) *AlertUpdateOne { return auo } -// ClearSourceScope clears the value of sourceScope. +// ClearSourceScope clears the value of the "sourceScope" field. func (auo *AlertUpdateOne) ClearSourceScope() *AlertUpdateOne { auo.mutation.ClearSourceScope() return auo } -// SetSourceValue sets the sourceValue field. +// SetSourceValue sets the "sourceValue" field. func (auo *AlertUpdateOne) SetSourceValue(s string) *AlertUpdateOne { auo.mutation.SetSourceValue(s) return auo } -// SetNillableSourceValue sets the sourceValue field if the given value is not nil. +// SetNillableSourceValue sets the "sourceValue" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableSourceValue(s *string) *AlertUpdateOne { if s != nil { auo.SetSourceValue(*s) @@ -1509,20 +1508,20 @@ func (auo *AlertUpdateOne) SetNillableSourceValue(s *string) *AlertUpdateOne { return auo } -// ClearSourceValue clears the value of sourceValue. +// ClearSourceValue clears the value of the "sourceValue" field. func (auo *AlertUpdateOne) ClearSourceValue() *AlertUpdateOne { auo.mutation.ClearSourceValue() return auo } -// SetCapacity sets the capacity field. +// SetCapacity sets the "capacity" field. func (auo *AlertUpdateOne) SetCapacity(i int32) *AlertUpdateOne { auo.mutation.ResetCapacity() auo.mutation.SetCapacity(i) return auo } -// SetNillableCapacity sets the capacity field if the given value is not nil. +// SetNillableCapacity sets the "capacity" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableCapacity(i *int32) *AlertUpdateOne { if i != nil { auo.SetCapacity(*i) @@ -1530,25 +1529,25 @@ func (auo *AlertUpdateOne) SetNillableCapacity(i *int32) *AlertUpdateOne { return auo } -// AddCapacity adds i to capacity. +// AddCapacity adds i to the "capacity" field. func (auo *AlertUpdateOne) AddCapacity(i int32) *AlertUpdateOne { auo.mutation.AddCapacity(i) return auo } -// ClearCapacity clears the value of capacity. +// ClearCapacity clears the value of the "capacity" field. func (auo *AlertUpdateOne) ClearCapacity() *AlertUpdateOne { auo.mutation.ClearCapacity() return auo } -// SetLeakSpeed sets the leakSpeed field. +// SetLeakSpeed sets the "leakSpeed" field. func (auo *AlertUpdateOne) SetLeakSpeed(s string) *AlertUpdateOne { auo.mutation.SetLeakSpeed(s) return auo } -// SetNillableLeakSpeed sets the leakSpeed field if the given value is not nil. +// SetNillableLeakSpeed sets the "leakSpeed" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableLeakSpeed(s *string) *AlertUpdateOne { if s != nil { auo.SetLeakSpeed(*s) @@ -1556,19 +1555,19 @@ func (auo *AlertUpdateOne) SetNillableLeakSpeed(s *string) *AlertUpdateOne { return auo } -// ClearLeakSpeed clears the value of leakSpeed. +// ClearLeakSpeed clears the value of the "leakSpeed" field. func (auo *AlertUpdateOne) ClearLeakSpeed() *AlertUpdateOne { auo.mutation.ClearLeakSpeed() return auo } -// SetScenarioVersion sets the scenarioVersion field. +// SetScenarioVersion sets the "scenarioVersion" field. func (auo *AlertUpdateOne) SetScenarioVersion(s string) *AlertUpdateOne { auo.mutation.SetScenarioVersion(s) return auo } -// SetNillableScenarioVersion sets the scenarioVersion field if the given value is not nil. +// SetNillableScenarioVersion sets the "scenarioVersion" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableScenarioVersion(s *string) *AlertUpdateOne { if s != nil { auo.SetScenarioVersion(*s) @@ -1576,19 +1575,19 @@ func (auo *AlertUpdateOne) SetNillableScenarioVersion(s *string) *AlertUpdateOne return auo } -// ClearScenarioVersion clears the value of scenarioVersion. +// ClearScenarioVersion clears the value of the "scenarioVersion" field. func (auo *AlertUpdateOne) ClearScenarioVersion() *AlertUpdateOne { auo.mutation.ClearScenarioVersion() return auo } -// SetScenarioHash sets the scenarioHash field. +// SetScenarioHash sets the "scenarioHash" field. func (auo *AlertUpdateOne) SetScenarioHash(s string) *AlertUpdateOne { auo.mutation.SetScenarioHash(s) return auo } -// SetNillableScenarioHash sets the scenarioHash field if the given value is not nil. +// SetNillableScenarioHash sets the "scenarioHash" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableScenarioHash(s *string) *AlertUpdateOne { if s != nil { auo.SetScenarioHash(*s) @@ -1596,19 +1595,19 @@ func (auo *AlertUpdateOne) SetNillableScenarioHash(s *string) *AlertUpdateOne { return auo } -// ClearScenarioHash clears the value of scenarioHash. +// ClearScenarioHash clears the value of the "scenarioHash" field. func (auo *AlertUpdateOne) ClearScenarioHash() *AlertUpdateOne { auo.mutation.ClearScenarioHash() return auo } -// SetSimulated sets the simulated field. +// SetSimulated sets the "simulated" field. func (auo *AlertUpdateOne) SetSimulated(b bool) *AlertUpdateOne { auo.mutation.SetSimulated(b) return auo } -// SetNillableSimulated sets the simulated field if the given value is not nil. +// SetNillableSimulated sets the "simulated" field if the given value is not nil. func (auo *AlertUpdateOne) SetNillableSimulated(b *bool) *AlertUpdateOne { if b != nil { auo.SetSimulated(*b) @@ -1616,13 +1615,13 @@ func (auo *AlertUpdateOne) SetNillableSimulated(b *bool) *AlertUpdateOne { return auo } -// SetOwnerID sets the owner edge to Machine by id. +// SetOwnerID sets the "owner" edge to the Machine entity by ID. func (auo *AlertUpdateOne) SetOwnerID(id int) *AlertUpdateOne { auo.mutation.SetOwnerID(id) return auo } -// SetNillableOwnerID sets the owner edge to Machine by id if the given value is not nil. +// SetNillableOwnerID sets the "owner" edge to the Machine entity by ID if the given value is not nil. func (auo *AlertUpdateOne) SetNillableOwnerID(id *int) *AlertUpdateOne { if id != nil { auo = auo.SetOwnerID(*id) @@ -1630,18 +1629,18 @@ func (auo *AlertUpdateOne) SetNillableOwnerID(id *int) *AlertUpdateOne { return auo } -// SetOwner sets the owner edge to Machine. +// SetOwner sets the "owner" edge to the Machine entity. func (auo *AlertUpdateOne) SetOwner(m *Machine) *AlertUpdateOne { return auo.SetOwnerID(m.ID) } -// AddDecisionIDs adds the decisions edge to Decision by ids. +// AddDecisionIDs adds the "decisions" edge to the Decision entity by IDs. func (auo *AlertUpdateOne) AddDecisionIDs(ids ...int) *AlertUpdateOne { auo.mutation.AddDecisionIDs(ids...) return auo } -// AddDecisions adds the decisions edges to Decision. +// AddDecisions adds the "decisions" edges to the Decision entity. func (auo *AlertUpdateOne) AddDecisions(d ...*Decision) *AlertUpdateOne { ids := make([]int, len(d)) for i := range d { @@ -1650,13 +1649,13 @@ func (auo *AlertUpdateOne) AddDecisions(d ...*Decision) *AlertUpdateOne { return auo.AddDecisionIDs(ids...) } -// AddEventIDs adds the events edge to Event by ids. +// AddEventIDs adds the "events" edge to the Event entity by IDs. func (auo *AlertUpdateOne) AddEventIDs(ids ...int) *AlertUpdateOne { auo.mutation.AddEventIDs(ids...) return auo } -// AddEvents adds the events edges to Event. +// AddEvents adds the "events" edges to the Event entity. func (auo *AlertUpdateOne) AddEvents(e ...*Event) *AlertUpdateOne { ids := make([]int, len(e)) for i := range e { @@ -1665,13 +1664,13 @@ func (auo *AlertUpdateOne) AddEvents(e ...*Event) *AlertUpdateOne { return auo.AddEventIDs(ids...) } -// AddMetaIDs adds the metas edge to Meta by ids. +// AddMetaIDs adds the "metas" edge to the Meta entity by IDs. func (auo *AlertUpdateOne) AddMetaIDs(ids ...int) *AlertUpdateOne { auo.mutation.AddMetaIDs(ids...) return auo } -// AddMetas adds the metas edges to Meta. +// AddMetas adds the "metas" edges to the Meta entity. func (auo *AlertUpdateOne) AddMetas(m ...*Meta) *AlertUpdateOne { ids := make([]int, len(m)) for i := range m { @@ -1685,25 +1684,25 @@ func (auo *AlertUpdateOne) Mutation() *AlertMutation { return auo.mutation } -// ClearOwner clears the "owner" edge to type Machine. +// ClearOwner clears the "owner" edge to the Machine entity. func (auo *AlertUpdateOne) ClearOwner() *AlertUpdateOne { auo.mutation.ClearOwner() return auo } -// ClearDecisions clears all "decisions" edges to type Decision. +// ClearDecisions clears all "decisions" edges to the Decision entity. func (auo *AlertUpdateOne) ClearDecisions() *AlertUpdateOne { auo.mutation.ClearDecisions() return auo } -// RemoveDecisionIDs removes the decisions edge to Decision by ids. +// RemoveDecisionIDs removes the "decisions" edge to Decision entities by IDs. func (auo *AlertUpdateOne) RemoveDecisionIDs(ids ...int) *AlertUpdateOne { auo.mutation.RemoveDecisionIDs(ids...) return auo } -// RemoveDecisions removes decisions edges to Decision. +// RemoveDecisions removes "decisions" edges to Decision entities. func (auo *AlertUpdateOne) RemoveDecisions(d ...*Decision) *AlertUpdateOne { ids := make([]int, len(d)) for i := range d { @@ -1712,19 +1711,19 @@ func (auo *AlertUpdateOne) RemoveDecisions(d ...*Decision) *AlertUpdateOne { return auo.RemoveDecisionIDs(ids...) } -// ClearEvents clears all "events" edges to type Event. +// ClearEvents clears all "events" edges to the Event entity. func (auo *AlertUpdateOne) ClearEvents() *AlertUpdateOne { auo.mutation.ClearEvents() return auo } -// RemoveEventIDs removes the events edge to Event by ids. +// RemoveEventIDs removes the "events" edge to Event entities by IDs. func (auo *AlertUpdateOne) RemoveEventIDs(ids ...int) *AlertUpdateOne { auo.mutation.RemoveEventIDs(ids...) return auo } -// RemoveEvents removes events edges to Event. +// RemoveEvents removes "events" edges to Event entities. func (auo *AlertUpdateOne) RemoveEvents(e ...*Event) *AlertUpdateOne { ids := make([]int, len(e)) for i := range e { @@ -1733,19 +1732,19 @@ func (auo *AlertUpdateOne) RemoveEvents(e ...*Event) *AlertUpdateOne { return auo.RemoveEventIDs(ids...) } -// ClearMetas clears all "metas" edges to type Meta. +// ClearMetas clears all "metas" edges to the Meta entity. func (auo *AlertUpdateOne) ClearMetas() *AlertUpdateOne { auo.mutation.ClearMetas() return auo } -// RemoveMetaIDs removes the metas edge to Meta by ids. +// RemoveMetaIDs removes the "metas" edge to Meta entities by IDs. func (auo *AlertUpdateOne) RemoveMetaIDs(ids ...int) *AlertUpdateOne { auo.mutation.RemoveMetaIDs(ids...) return auo } -// RemoveMetas removes metas edges to Meta. +// RemoveMetas removes "metas" edges to Meta entities. func (auo *AlertUpdateOne) RemoveMetas(m ...*Meta) *AlertUpdateOne { ids := make([]int, len(m)) for i := range m { @@ -1754,7 +1753,7 @@ func (auo *AlertUpdateOne) RemoveMetas(m ...*Meta) *AlertUpdateOne { return auo.RemoveMetaIDs(ids...) } -// Save executes the query and returns the updated entity. +// Save executes the query and returns the updated Alert entity. func (auo *AlertUpdateOne) Save(ctx context.Context) (*Alert, error) { var ( err error @@ -2310,7 +2309,7 @@ func (auo *AlertUpdateOne) sqlSave(ctx context.Context) (_node *Alert, err error } _node = &Alert{config: auo.config} _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues() + _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{alert.Label} diff --git a/pkg/database/ent/bouncer.go b/pkg/database/ent/bouncer.go index e1041f40c..c93a54877 100644 --- a/pkg/database/ent/bouncer.go +++ b/pkg/database/ent/bouncer.go @@ -39,96 +39,113 @@ type Bouncer struct { } // scanValues returns the types for scanning values from sql.Rows. -func (*Bouncer) scanValues() []interface{} { - return []interface{}{ - &sql.NullInt64{}, // id - &sql.NullTime{}, // created_at - &sql.NullTime{}, // updated_at - &sql.NullString{}, // name - &sql.NullString{}, // api_key - &sql.NullBool{}, // revoked - &sql.NullString{}, // ip_address - &sql.NullString{}, // type - &sql.NullString{}, // version - &sql.NullTime{}, // until - &sql.NullTime{}, // last_pull +func (*Bouncer) scanValues(columns []string) ([]interface{}, error) { + values := make([]interface{}, len(columns)) + for i := range columns { + switch columns[i] { + case bouncer.FieldRevoked: + values[i] = &sql.NullBool{} + case bouncer.FieldID: + values[i] = &sql.NullInt64{} + case bouncer.FieldName, bouncer.FieldAPIKey, bouncer.FieldIPAddress, bouncer.FieldType, bouncer.FieldVersion: + values[i] = &sql.NullString{} + case bouncer.FieldCreatedAt, bouncer.FieldUpdatedAt, bouncer.FieldUntil, bouncer.FieldLastPull: + values[i] = &sql.NullTime{} + default: + return nil, fmt.Errorf("unexpected column %q for type Bouncer", columns[i]) + } } + return values, nil } // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Bouncer fields. -func (b *Bouncer) assignValues(values ...interface{}) error { - if m, n := len(values), len(bouncer.Columns); m < n { +func (b *Bouncer) 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) } - value, ok := values[0].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - b.ID = int(value.Int64) - values = values[1:] - if value, ok := values[0].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[0]) - } else if value.Valid { - b.CreatedAt = value.Time - } - if value, ok := values[1].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[1]) - } else if value.Valid { - b.UpdatedAt = value.Time - } - if value, ok := values[2].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field name", values[2]) - } else if value.Valid { - b.Name = value.String - } - if value, ok := values[3].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field api_key", values[3]) - } else if value.Valid { - b.APIKey = value.String - } - if value, ok := values[4].(*sql.NullBool); !ok { - return fmt.Errorf("unexpected type %T for field revoked", values[4]) - } else if value.Valid { - b.Revoked = value.Bool - } - if value, ok := values[5].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field ip_address", values[5]) - } else if value.Valid { - b.IPAddress = value.String - } - if value, ok := values[6].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field type", values[6]) - } else if value.Valid { - b.Type = value.String - } - if value, ok := values[7].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field version", values[7]) - } else if value.Valid { - b.Version = value.String - } - if value, ok := values[8].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field until", values[8]) - } else if value.Valid { - b.Until = value.Time - } - if value, ok := values[9].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field last_pull", values[9]) - } else if value.Valid { - b.LastPull = value.Time + for i := range columns { + switch columns[i] { + case bouncer.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + b.ID = int(value.Int64) + case bouncer.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 { + b.CreatedAt = value.Time + } + case bouncer.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 { + b.UpdatedAt = value.Time + } + case bouncer.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + b.Name = value.String + } + case bouncer.FieldAPIKey: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field api_key", values[i]) + } else if value.Valid { + b.APIKey = value.String + } + case bouncer.FieldRevoked: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field revoked", values[i]) + } else if value.Valid { + b.Revoked = value.Bool + } + case bouncer.FieldIPAddress: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field ip_address", values[i]) + } else if value.Valid { + b.IPAddress = value.String + } + case bouncer.FieldType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field type", values[i]) + } else if value.Valid { + b.Type = value.String + } + case bouncer.FieldVersion: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field version", values[i]) + } else if value.Valid { + b.Version = value.String + } + case bouncer.FieldUntil: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field until", values[i]) + } else if value.Valid { + b.Until = value.Time + } + case bouncer.FieldLastPull: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field last_pull", values[i]) + } else if value.Valid { + b.LastPull = value.Time + } + } } return nil } // Update returns a builder for updating this Bouncer. -// Note that, you need to call Bouncer.Unwrap() before calling this method, if this Bouncer +// Note that you need to call Bouncer.Unwrap() before calling this method if this Bouncer // was returned from a transaction, and the transaction was committed or rolled back. func (b *Bouncer) Update() *BouncerUpdateOne { return (&BouncerClient{config: b.config}).UpdateOne(b) } -// Unwrap unwraps the entity that was returned from a transaction after it was closed, -// so that all next queries will be executed through the driver which created the transaction. +// Unwrap unwraps the Bouncer 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 (b *Bouncer) Unwrap() *Bouncer { tx, ok := b.config.driver.(*txDriver) if !ok { diff --git a/pkg/database/ent/bouncer/bouncer.go b/pkg/database/ent/bouncer/bouncer.go index 6ed228a27..2e5dbfc18 100644 --- a/pkg/database/ent/bouncer/bouncer.go +++ b/pkg/database/ent/bouncer/bouncer.go @@ -62,14 +62,14 @@ func ValidColumn(column string) bool { } var ( - // DefaultCreatedAt holds the default value on creation for the created_at field. + // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the updated_at field. + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. DefaultUpdatedAt func() time.Time - // DefaultIPAddress holds the default value on creation for the ip_address field. + // DefaultIPAddress holds the default value on creation for the "ip_address" field. DefaultIPAddress string - // DefaultUntil holds the default value on creation for the until field. + // DefaultUntil holds the default value on creation for the "until" field. DefaultUntil func() time.Time - // DefaultLastPull holds the default value on creation for the last_pull field. + // DefaultLastPull holds the default value on creation for the "last_pull" field. DefaultLastPull func() time.Time ) diff --git a/pkg/database/ent/bouncer/where.go b/pkg/database/ent/bouncer/where.go index 4672e9514..4e70e491b 100644 --- a/pkg/database/ent/bouncer/where.go +++ b/pkg/database/ent/bouncer/where.go @@ -9,7 +9,7 @@ import ( "github.com/facebook/ent/dialect/sql" ) -// ID filters vertices based on their identifier. +// ID filters vertices based on their ID field. func ID(id int) predicate.Bouncer { return predicate.Bouncer(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldID), id)) @@ -1091,7 +1091,7 @@ func LastPullLTE(v time.Time) predicate.Bouncer { }) } -// And groups list of predicates with the AND operator between them. +// And groups predicates with the AND operator between them. func And(predicates ...predicate.Bouncer) predicate.Bouncer { return predicate.Bouncer(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) @@ -1102,7 +1102,7 @@ func And(predicates ...predicate.Bouncer) predicate.Bouncer { }) } -// Or groups list of predicates with the OR operator between them. +// Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Bouncer) predicate.Bouncer { return predicate.Bouncer(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) diff --git a/pkg/database/ent/bouncer_create.go b/pkg/database/ent/bouncer_create.go index 1186343b1..df92e83c3 100644 --- a/pkg/database/ent/bouncer_create.go +++ b/pkg/database/ent/bouncer_create.go @@ -20,13 +20,13 @@ type BouncerCreate struct { hooks []Hook } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (bc *BouncerCreate) SetCreatedAt(t time.Time) *BouncerCreate { bc.mutation.SetCreatedAt(t) return bc } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (bc *BouncerCreate) SetNillableCreatedAt(t *time.Time) *BouncerCreate { if t != nil { bc.SetCreatedAt(*t) @@ -34,13 +34,13 @@ func (bc *BouncerCreate) SetNillableCreatedAt(t *time.Time) *BouncerCreate { return bc } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (bc *BouncerCreate) SetUpdatedAt(t time.Time) *BouncerCreate { bc.mutation.SetUpdatedAt(t) return bc } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (bc *BouncerCreate) SetNillableUpdatedAt(t *time.Time) *BouncerCreate { if t != nil { bc.SetUpdatedAt(*t) @@ -48,31 +48,31 @@ func (bc *BouncerCreate) SetNillableUpdatedAt(t *time.Time) *BouncerCreate { return bc } -// SetName sets the name field. +// SetName sets the "name" field. func (bc *BouncerCreate) SetName(s string) *BouncerCreate { bc.mutation.SetName(s) return bc } -// SetAPIKey sets the api_key field. +// SetAPIKey sets the "api_key" field. func (bc *BouncerCreate) SetAPIKey(s string) *BouncerCreate { bc.mutation.SetAPIKey(s) return bc } -// SetRevoked sets the revoked field. +// SetRevoked sets the "revoked" field. func (bc *BouncerCreate) SetRevoked(b bool) *BouncerCreate { bc.mutation.SetRevoked(b) return bc } -// SetIPAddress sets the ip_address field. +// SetIPAddress sets the "ip_address" field. func (bc *BouncerCreate) SetIPAddress(s string) *BouncerCreate { bc.mutation.SetIPAddress(s) return bc } -// SetNillableIPAddress sets the ip_address field if the given value is not nil. +// SetNillableIPAddress sets the "ip_address" field if the given value is not nil. func (bc *BouncerCreate) SetNillableIPAddress(s *string) *BouncerCreate { if s != nil { bc.SetIPAddress(*s) @@ -80,13 +80,13 @@ func (bc *BouncerCreate) SetNillableIPAddress(s *string) *BouncerCreate { return bc } -// SetType sets the type field. +// SetType sets the "type" field. func (bc *BouncerCreate) SetType(s string) *BouncerCreate { bc.mutation.SetType(s) return bc } -// SetNillableType sets the type field if the given value is not nil. +// SetNillableType sets the "type" field if the given value is not nil. func (bc *BouncerCreate) SetNillableType(s *string) *BouncerCreate { if s != nil { bc.SetType(*s) @@ -94,13 +94,13 @@ func (bc *BouncerCreate) SetNillableType(s *string) *BouncerCreate { return bc } -// SetVersion sets the version field. +// SetVersion sets the "version" field. func (bc *BouncerCreate) SetVersion(s string) *BouncerCreate { bc.mutation.SetVersion(s) return bc } -// SetNillableVersion sets the version field if the given value is not nil. +// SetNillableVersion sets the "version" field if the given value is not nil. func (bc *BouncerCreate) SetNillableVersion(s *string) *BouncerCreate { if s != nil { bc.SetVersion(*s) @@ -108,13 +108,13 @@ func (bc *BouncerCreate) SetNillableVersion(s *string) *BouncerCreate { return bc } -// SetUntil sets the until field. +// SetUntil sets the "until" field. func (bc *BouncerCreate) SetUntil(t time.Time) *BouncerCreate { bc.mutation.SetUntil(t) return bc } -// SetNillableUntil sets the until field if the given value is not nil. +// SetNillableUntil sets the "until" field if the given value is not nil. func (bc *BouncerCreate) SetNillableUntil(t *time.Time) *BouncerCreate { if t != nil { bc.SetUntil(*t) @@ -122,13 +122,13 @@ func (bc *BouncerCreate) SetNillableUntil(t *time.Time) *BouncerCreate { return bc } -// SetLastPull sets the last_pull field. +// SetLastPull sets the "last_pull" field. func (bc *BouncerCreate) SetLastPull(t time.Time) *BouncerCreate { bc.mutation.SetLastPull(t) return bc } -// SetNillableLastPull sets the last_pull field if the given value is not nil. +// SetNillableLastPull sets the "last_pull" field if the given value is not nil. func (bc *BouncerCreate) SetNillableLastPull(t *time.Time) *BouncerCreate { if t != nil { bc.SetLastPull(*t) @@ -340,7 +340,7 @@ func (bc *BouncerCreate) createSpec() (*Bouncer, *sqlgraph.CreateSpec) { return _node, _spec } -// BouncerCreateBulk is the builder for creating a bulk of Bouncer entities. +// BouncerCreateBulk is the builder for creating many Bouncer entities in bulk. type BouncerCreateBulk struct { config builders []*BouncerCreate @@ -398,7 +398,7 @@ func (bcb *BouncerCreateBulk) Save(ctx context.Context) ([]*Bouncer, error) { return nodes, nil } -// SaveX calls Save and panics if Save returns an error. +// SaveX is like Save, but panics if an error occurs. func (bcb *BouncerCreateBulk) SaveX(ctx context.Context) []*Bouncer { v, err := bcb.Save(ctx) if err != nil { diff --git a/pkg/database/ent/bouncer_delete.go b/pkg/database/ent/bouncer_delete.go index 9596532ce..10933c3fb 100644 --- a/pkg/database/ent/bouncer_delete.go +++ b/pkg/database/ent/bouncer_delete.go @@ -16,14 +16,13 @@ import ( // BouncerDelete is the builder for deleting a Bouncer entity. type BouncerDelete struct { config - hooks []Hook - mutation *BouncerMutation - predicates []predicate.Bouncer + hooks []Hook + mutation *BouncerMutation } -// Where adds a new predicate to the delete builder. +// Where adds a new predicate to the BouncerDelete builder. func (bd *BouncerDelete) Where(ps ...predicate.Bouncer) *BouncerDelete { - bd.predicates = append(bd.predicates, ps...) + bd.mutation.predicates = append(bd.mutation.predicates, ps...) return bd } @@ -75,7 +74,7 @@ func (bd *BouncerDelete) sqlExec(ctx context.Context) (int, error) { }, }, } - if ps := bd.predicates; len(ps) > 0 { + if ps := bd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) diff --git a/pkg/database/ent/bouncer_query.go b/pkg/database/ent/bouncer_query.go index 330bb94bc..65819923c 100644 --- a/pkg/database/ent/bouncer_query.go +++ b/pkg/database/ent/bouncer_query.go @@ -21,14 +21,14 @@ type BouncerQuery struct { limit *int offset *int order []OrderFunc - unique []string + fields []string predicates []predicate.Bouncer // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) } -// Where adds a new predicate for the builder. +// Where adds a new predicate for the BouncerQuery builder. func (bq *BouncerQuery) Where(ps ...predicate.Bouncer) *BouncerQuery { bq.predicates = append(bq.predicates, ps...) return bq @@ -52,7 +52,8 @@ func (bq *BouncerQuery) Order(o ...OrderFunc) *BouncerQuery { return bq } -// First returns the first Bouncer entity in the query. Returns *NotFoundError when no bouncer was found. +// First returns the first Bouncer entity from the query. +// Returns a *NotFoundError when no Bouncer was found. func (bq *BouncerQuery) First(ctx context.Context) (*Bouncer, error) { nodes, err := bq.Limit(1).All(ctx) if err != nil { @@ -73,7 +74,8 @@ func (bq *BouncerQuery) FirstX(ctx context.Context) *Bouncer { return node } -// FirstID returns the first Bouncer id in the query. Returns *NotFoundError when no id was found. +// FirstID returns the first Bouncer ID from the query. +// Returns a *NotFoundError when no Bouncer ID was found. func (bq *BouncerQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int if ids, err = bq.Limit(1).IDs(ctx); err != nil { @@ -86,8 +88,8 @@ func (bq *BouncerQuery) FirstID(ctx context.Context) (id int, err error) { return ids[0], nil } -// FirstXID is like FirstID, but panics if an error occurs. -func (bq *BouncerQuery) FirstXID(ctx context.Context) int { +// FirstIDX is like FirstID, but panics if an error occurs. +func (bq *BouncerQuery) FirstIDX(ctx context.Context) int { id, err := bq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -95,7 +97,9 @@ func (bq *BouncerQuery) FirstXID(ctx context.Context) int { return id } -// Only returns the only Bouncer entity in the query, returns an error if not exactly one entity was returned. +// Only returns a single Bouncer entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when exactly one Bouncer entity is not found. +// Returns a *NotFoundError when no Bouncer entities are found. func (bq *BouncerQuery) Only(ctx context.Context) (*Bouncer, error) { nodes, err := bq.Limit(2).All(ctx) if err != nil { @@ -120,7 +124,9 @@ func (bq *BouncerQuery) OnlyX(ctx context.Context) *Bouncer { return node } -// OnlyID returns the only Bouncer id in the query, returns an error if not exactly one id was returned. +// OnlyID is like Only, but returns the only Bouncer ID in the query. +// Returns a *NotSingularError when exactly one Bouncer ID is not found. +// Returns a *NotFoundError when no entities are found. func (bq *BouncerQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int if ids, err = bq.Limit(2).IDs(ctx); err != nil { @@ -163,7 +169,7 @@ func (bq *BouncerQuery) AllX(ctx context.Context) []*Bouncer { return nodes } -// IDs executes the query and returns a list of Bouncer ids. +// IDs executes the query and returns a list of Bouncer IDs. func (bq *BouncerQuery) IDs(ctx context.Context) ([]int, error) { var ids []int if err := bq.Select(bouncer.FieldID).Scan(ctx, &ids); err != nil { @@ -215,15 +221,17 @@ func (bq *BouncerQuery) ExistX(ctx context.Context) bool { return exist } -// Clone returns a duplicate of the query builder, including all associated steps. It can be +// Clone returns a duplicate of the BouncerQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. func (bq *BouncerQuery) Clone() *BouncerQuery { + if bq == nil { + return nil + } return &BouncerQuery{ config: bq.config, limit: bq.limit, offset: bq.offset, order: append([]OrderFunc{}, bq.order...), - unique: append([]string{}, bq.unique...), predicates: append([]predicate.Bouncer{}, bq.predicates...), // clone intermediate query. sql: bq.sql.Clone(), @@ -231,7 +239,7 @@ func (bq *BouncerQuery) Clone() *BouncerQuery { } } -// GroupBy used to group vertices by one or more fields/columns. +// GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // // Example: @@ -258,7 +266,8 @@ func (bq *BouncerQuery) GroupBy(field string, fields ...string) *BouncerGroupBy return group } -// Select one or more fields from the given query. +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. // // Example: // @@ -271,18 +280,16 @@ func (bq *BouncerQuery) GroupBy(field string, fields ...string) *BouncerGroupBy // Scan(ctx, &v) // func (bq *BouncerQuery) Select(field string, fields ...string) *BouncerSelect { - selector := &BouncerSelect{config: bq.config} - selector.fields = append([]string{field}, fields...) - selector.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := bq.prepareQuery(ctx); err != nil { - return nil, err - } - return bq.sqlQuery(), nil - } - return selector + bq.fields = append([]string{field}, fields...) + return &BouncerSelect{BouncerQuery: bq} } func (bq *BouncerQuery) prepareQuery(ctx context.Context) error { + for _, f := range bq.fields { + if !bouncer.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } if bq.path != nil { prev, err := bq.path(ctx) if err != nil { @@ -298,18 +305,17 @@ func (bq *BouncerQuery) sqlAll(ctx context.Context) ([]*Bouncer, error) { nodes = []*Bouncer{} _spec = bq.querySpec() ) - _spec.ScanValues = func() []interface{} { + _spec.ScanValues = func(columns []string) ([]interface{}, error) { node := &Bouncer{config: bq.config} nodes = append(nodes, node) - values := node.scanValues() - return values + return node.scanValues(columns) } - _spec.Assign = func(values ...interface{}) error { + _spec.Assign = func(columns []string, values []interface{}) error { if len(nodes) == 0 { return fmt.Errorf("ent: Assign called without calling ScanValues") } node := nodes[len(nodes)-1] - return node.assignValues(values...) + return node.assignValues(columns, values) } if err := sqlgraph.QueryNodes(ctx, bq.driver, _spec); err != nil { return nil, err @@ -346,6 +352,15 @@ func (bq *BouncerQuery) querySpec() *sqlgraph.QuerySpec { From: bq.sql, Unique: true, } + if fields := bq.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, bouncer.FieldID) + for i := range fields { + if fields[i] != bouncer.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } if ps := bq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -394,7 +409,7 @@ func (bq *BouncerQuery) sqlQuery() *sql.Selector { return selector } -// BouncerGroupBy is the builder for group-by Bouncer entities. +// BouncerGroupBy is the group-by builder for Bouncer entities. type BouncerGroupBy struct { config fields []string @@ -410,7 +425,7 @@ func (bgb *BouncerGroupBy) Aggregate(fns ...AggregateFunc) *BouncerGroupBy { return bgb } -// Scan applies the group-by query and scan the result into the given value. +// Scan applies the group-by query and scans the result into the given value. func (bgb *BouncerGroupBy) Scan(ctx context.Context, v interface{}) error { query, err := bgb.path(ctx) if err != nil { @@ -427,7 +442,8 @@ func (bgb *BouncerGroupBy) ScanX(ctx context.Context, v interface{}) { } } -// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field. +// Strings returns list of strings from group-by. +// It is only allowed when executing a group-by query with one field. func (bgb *BouncerGroupBy) Strings(ctx context.Context) ([]string, error) { if len(bgb.fields) > 1 { return nil, errors.New("ent: BouncerGroupBy.Strings is not achievable when grouping more than 1 field") @@ -448,7 +464,8 @@ func (bgb *BouncerGroupBy) StringsX(ctx context.Context) []string { return v } -// String returns a single string from group-by. It is only allowed when querying group-by with one field. +// String returns a single string from a group-by query. +// It is only allowed when executing a group-by query with one field. func (bgb *BouncerGroupBy) String(ctx context.Context) (_ string, err error) { var v []string if v, err = bgb.Strings(ctx); err != nil { @@ -474,7 +491,8 @@ func (bgb *BouncerGroupBy) StringX(ctx context.Context) string { return v } -// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field. +// Ints returns list of ints from group-by. +// It is only allowed when executing a group-by query with one field. func (bgb *BouncerGroupBy) Ints(ctx context.Context) ([]int, error) { if len(bgb.fields) > 1 { return nil, errors.New("ent: BouncerGroupBy.Ints is not achievable when grouping more than 1 field") @@ -495,7 +513,8 @@ func (bgb *BouncerGroupBy) IntsX(ctx context.Context) []int { return v } -// Int returns a single int from group-by. It is only allowed when querying group-by with one field. +// Int returns a single int from a group-by query. +// It is only allowed when executing a group-by query with one field. func (bgb *BouncerGroupBy) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = bgb.Ints(ctx); err != nil { @@ -521,7 +540,8 @@ func (bgb *BouncerGroupBy) IntX(ctx context.Context) int { return v } -// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field. +// Float64s returns list of float64s from group-by. +// It is only allowed when executing a group-by query with one field. func (bgb *BouncerGroupBy) Float64s(ctx context.Context) ([]float64, error) { if len(bgb.fields) > 1 { return nil, errors.New("ent: BouncerGroupBy.Float64s is not achievable when grouping more than 1 field") @@ -542,7 +562,8 @@ func (bgb *BouncerGroupBy) Float64sX(ctx context.Context) []float64 { return v } -// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field. +// Float64 returns a single float64 from a group-by query. +// It is only allowed when executing a group-by query with one field. func (bgb *BouncerGroupBy) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = bgb.Float64s(ctx); err != nil { @@ -568,7 +589,8 @@ func (bgb *BouncerGroupBy) Float64X(ctx context.Context) float64 { return v } -// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field. +// Bools returns list of bools from group-by. +// It is only allowed when executing a group-by query with one field. func (bgb *BouncerGroupBy) Bools(ctx context.Context) ([]bool, error) { if len(bgb.fields) > 1 { return nil, errors.New("ent: BouncerGroupBy.Bools is not achievable when grouping more than 1 field") @@ -589,7 +611,8 @@ func (bgb *BouncerGroupBy) BoolsX(ctx context.Context) []bool { return v } -// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field. +// Bool returns a single bool from a group-by query. +// It is only allowed when executing a group-by query with one field. func (bgb *BouncerGroupBy) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = bgb.Bools(ctx); err != nil { @@ -644,22 +667,19 @@ func (bgb *BouncerGroupBy) sqlQuery() *sql.Selector { return selector.Select(columns...).GroupBy(bgb.fields...) } -// BouncerSelect is the builder for select fields of Bouncer entities. +// BouncerSelect is the builder for selecting fields of Bouncer entities. type BouncerSelect struct { - config - fields []string + *BouncerQuery // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + sql *sql.Selector } -// Scan applies the selector query and scan the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (bs *BouncerSelect) Scan(ctx context.Context, v interface{}) error { - query, err := bs.path(ctx) - if err != nil { + if err := bs.prepareQuery(ctx); err != nil { return err } - bs.sql = query + bs.sql = bs.BouncerQuery.sqlQuery() return bs.sqlScan(ctx, v) } @@ -670,7 +690,7 @@ func (bs *BouncerSelect) ScanX(ctx context.Context, v interface{}) { } } -// Strings returns list of strings from selector. It is only allowed when selecting one field. +// Strings returns list of strings from a selector. It is only allowed when selecting one field. func (bs *BouncerSelect) Strings(ctx context.Context) ([]string, error) { if len(bs.fields) > 1 { return nil, errors.New("ent: BouncerSelect.Strings is not achievable when selecting more than 1 field") @@ -691,7 +711,7 @@ func (bs *BouncerSelect) StringsX(ctx context.Context) []string { return v } -// String returns a single string from selector. It is only allowed when selecting one field. +// String returns a single string from a selector. It is only allowed when selecting one field. func (bs *BouncerSelect) String(ctx context.Context) (_ string, err error) { var v []string if v, err = bs.Strings(ctx); err != nil { @@ -717,7 +737,7 @@ func (bs *BouncerSelect) StringX(ctx context.Context) string { return v } -// Ints returns list of ints from selector. It is only allowed when selecting one field. +// Ints returns list of ints from a selector. It is only allowed when selecting one field. func (bs *BouncerSelect) Ints(ctx context.Context) ([]int, error) { if len(bs.fields) > 1 { return nil, errors.New("ent: BouncerSelect.Ints is not achievable when selecting more than 1 field") @@ -738,7 +758,7 @@ func (bs *BouncerSelect) IntsX(ctx context.Context) []int { return v } -// Int returns a single int from selector. It is only allowed when selecting one field. +// Int returns a single int from a selector. It is only allowed when selecting one field. func (bs *BouncerSelect) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = bs.Ints(ctx); err != nil { @@ -764,7 +784,7 @@ func (bs *BouncerSelect) IntX(ctx context.Context) int { return v } -// Float64s returns list of float64s from selector. It is only allowed when selecting one field. +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. func (bs *BouncerSelect) Float64s(ctx context.Context) ([]float64, error) { if len(bs.fields) > 1 { return nil, errors.New("ent: BouncerSelect.Float64s is not achievable when selecting more than 1 field") @@ -785,7 +805,7 @@ func (bs *BouncerSelect) Float64sX(ctx context.Context) []float64 { return v } -// Float64 returns a single float64 from selector. It is only allowed when selecting one field. +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. func (bs *BouncerSelect) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = bs.Float64s(ctx); err != nil { @@ -811,7 +831,7 @@ func (bs *BouncerSelect) Float64X(ctx context.Context) float64 { return v } -// Bools returns list of bools from selector. It is only allowed when selecting one field. +// Bools returns list of bools from a selector. It is only allowed when selecting one field. func (bs *BouncerSelect) Bools(ctx context.Context) ([]bool, error) { if len(bs.fields) > 1 { return nil, errors.New("ent: BouncerSelect.Bools is not achievable when selecting more than 1 field") @@ -832,7 +852,7 @@ func (bs *BouncerSelect) BoolsX(ctx context.Context) []bool { return v } -// Bool returns a single bool from selector. It is only allowed when selecting one field. +// Bool returns a single bool from a selector. It is only allowed when selecting one field. func (bs *BouncerSelect) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = bs.Bools(ctx); err != nil { @@ -859,11 +879,6 @@ func (bs *BouncerSelect) BoolX(ctx context.Context) bool { } func (bs *BouncerSelect) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range bs.fields { - if !bouncer.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for selection", f)} - } - } rows := &sql.Rows{} query, args := bs.sqlQuery().Query() if err := bs.driver.Query(ctx, query, args, rows); err != nil { diff --git a/pkg/database/ent/bouncer_update.go b/pkg/database/ent/bouncer_update.go index fcf4970e0..3873f66f5 100644 --- a/pkg/database/ent/bouncer_update.go +++ b/pkg/database/ent/bouncer_update.go @@ -17,24 +17,23 @@ import ( // BouncerUpdate is the builder for updating Bouncer entities. type BouncerUpdate struct { config - hooks []Hook - mutation *BouncerMutation - predicates []predicate.Bouncer + hooks []Hook + mutation *BouncerMutation } -// Where adds a new predicate for the builder. +// Where adds a new predicate for the BouncerUpdate builder. func (bu *BouncerUpdate) Where(ps ...predicate.Bouncer) *BouncerUpdate { - bu.predicates = append(bu.predicates, ps...) + bu.mutation.predicates = append(bu.mutation.predicates, ps...) return bu } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (bu *BouncerUpdate) SetCreatedAt(t time.Time) *BouncerUpdate { bu.mutation.SetCreatedAt(t) return bu } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (bu *BouncerUpdate) SetNillableCreatedAt(t *time.Time) *BouncerUpdate { if t != nil { bu.SetCreatedAt(*t) @@ -42,13 +41,13 @@ func (bu *BouncerUpdate) SetNillableCreatedAt(t *time.Time) *BouncerUpdate { return bu } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (bu *BouncerUpdate) SetUpdatedAt(t time.Time) *BouncerUpdate { bu.mutation.SetUpdatedAt(t) return bu } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (bu *BouncerUpdate) SetNillableUpdatedAt(t *time.Time) *BouncerUpdate { if t != nil { bu.SetUpdatedAt(*t) @@ -56,31 +55,31 @@ func (bu *BouncerUpdate) SetNillableUpdatedAt(t *time.Time) *BouncerUpdate { return bu } -// SetName sets the name field. +// SetName sets the "name" field. func (bu *BouncerUpdate) SetName(s string) *BouncerUpdate { bu.mutation.SetName(s) return bu } -// SetAPIKey sets the api_key field. +// SetAPIKey sets the "api_key" field. func (bu *BouncerUpdate) SetAPIKey(s string) *BouncerUpdate { bu.mutation.SetAPIKey(s) return bu } -// SetRevoked sets the revoked field. +// SetRevoked sets the "revoked" field. func (bu *BouncerUpdate) SetRevoked(b bool) *BouncerUpdate { bu.mutation.SetRevoked(b) return bu } -// SetIPAddress sets the ip_address field. +// SetIPAddress sets the "ip_address" field. func (bu *BouncerUpdate) SetIPAddress(s string) *BouncerUpdate { bu.mutation.SetIPAddress(s) return bu } -// SetNillableIPAddress sets the ip_address field if the given value is not nil. +// SetNillableIPAddress sets the "ip_address" field if the given value is not nil. func (bu *BouncerUpdate) SetNillableIPAddress(s *string) *BouncerUpdate { if s != nil { bu.SetIPAddress(*s) @@ -88,19 +87,19 @@ func (bu *BouncerUpdate) SetNillableIPAddress(s *string) *BouncerUpdate { return bu } -// ClearIPAddress clears the value of ip_address. +// ClearIPAddress clears the value of the "ip_address" field. func (bu *BouncerUpdate) ClearIPAddress() *BouncerUpdate { bu.mutation.ClearIPAddress() return bu } -// SetType sets the type field. +// SetType sets the "type" field. func (bu *BouncerUpdate) SetType(s string) *BouncerUpdate { bu.mutation.SetType(s) return bu } -// SetNillableType sets the type field if the given value is not nil. +// SetNillableType sets the "type" field if the given value is not nil. func (bu *BouncerUpdate) SetNillableType(s *string) *BouncerUpdate { if s != nil { bu.SetType(*s) @@ -108,19 +107,19 @@ func (bu *BouncerUpdate) SetNillableType(s *string) *BouncerUpdate { return bu } -// ClearType clears the value of type. +// ClearType clears the value of the "type" field. func (bu *BouncerUpdate) ClearType() *BouncerUpdate { bu.mutation.ClearType() return bu } -// SetVersion sets the version field. +// SetVersion sets the "version" field. func (bu *BouncerUpdate) SetVersion(s string) *BouncerUpdate { bu.mutation.SetVersion(s) return bu } -// SetNillableVersion sets the version field if the given value is not nil. +// SetNillableVersion sets the "version" field if the given value is not nil. func (bu *BouncerUpdate) SetNillableVersion(s *string) *BouncerUpdate { if s != nil { bu.SetVersion(*s) @@ -128,19 +127,19 @@ func (bu *BouncerUpdate) SetNillableVersion(s *string) *BouncerUpdate { return bu } -// ClearVersion clears the value of version. +// ClearVersion clears the value of the "version" field. func (bu *BouncerUpdate) ClearVersion() *BouncerUpdate { bu.mutation.ClearVersion() return bu } -// SetUntil sets the until field. +// SetUntil sets the "until" field. func (bu *BouncerUpdate) SetUntil(t time.Time) *BouncerUpdate { bu.mutation.SetUntil(t) return bu } -// SetNillableUntil sets the until field if the given value is not nil. +// SetNillableUntil sets the "until" field if the given value is not nil. func (bu *BouncerUpdate) SetNillableUntil(t *time.Time) *BouncerUpdate { if t != nil { bu.SetUntil(*t) @@ -148,19 +147,19 @@ func (bu *BouncerUpdate) SetNillableUntil(t *time.Time) *BouncerUpdate { return bu } -// ClearUntil clears the value of until. +// ClearUntil clears the value of the "until" field. func (bu *BouncerUpdate) ClearUntil() *BouncerUpdate { bu.mutation.ClearUntil() return bu } -// SetLastPull sets the last_pull field. +// SetLastPull sets the "last_pull" field. func (bu *BouncerUpdate) SetLastPull(t time.Time) *BouncerUpdate { bu.mutation.SetLastPull(t) return bu } -// SetNillableLastPull sets the last_pull field if the given value is not nil. +// SetNillableLastPull sets the "last_pull" field if the given value is not nil. func (bu *BouncerUpdate) SetNillableLastPull(t *time.Time) *BouncerUpdate { if t != nil { bu.SetLastPull(*t) @@ -173,7 +172,7 @@ func (bu *BouncerUpdate) Mutation() *BouncerMutation { return bu.mutation } -// Save executes the query and returns the number of rows/vertices matched by this operation. +// Save executes the query and returns the number of nodes affected by the update operation. func (bu *BouncerUpdate) Save(ctx context.Context) (int, error) { var ( err error @@ -235,7 +234,7 @@ func (bu *BouncerUpdate) sqlSave(ctx context.Context) (n int, err error) { }, }, } - if ps := bu.predicates; len(ps) > 0 { + if ps := bu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) @@ -354,13 +353,13 @@ type BouncerUpdateOne struct { mutation *BouncerMutation } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (buo *BouncerUpdateOne) SetCreatedAt(t time.Time) *BouncerUpdateOne { buo.mutation.SetCreatedAt(t) return buo } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (buo *BouncerUpdateOne) SetNillableCreatedAt(t *time.Time) *BouncerUpdateOne { if t != nil { buo.SetCreatedAt(*t) @@ -368,13 +367,13 @@ func (buo *BouncerUpdateOne) SetNillableCreatedAt(t *time.Time) *BouncerUpdateOn return buo } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (buo *BouncerUpdateOne) SetUpdatedAt(t time.Time) *BouncerUpdateOne { buo.mutation.SetUpdatedAt(t) return buo } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (buo *BouncerUpdateOne) SetNillableUpdatedAt(t *time.Time) *BouncerUpdateOne { if t != nil { buo.SetUpdatedAt(*t) @@ -382,31 +381,31 @@ func (buo *BouncerUpdateOne) SetNillableUpdatedAt(t *time.Time) *BouncerUpdateOn return buo } -// SetName sets the name field. +// SetName sets the "name" field. func (buo *BouncerUpdateOne) SetName(s string) *BouncerUpdateOne { buo.mutation.SetName(s) return buo } -// SetAPIKey sets the api_key field. +// SetAPIKey sets the "api_key" field. func (buo *BouncerUpdateOne) SetAPIKey(s string) *BouncerUpdateOne { buo.mutation.SetAPIKey(s) return buo } -// SetRevoked sets the revoked field. +// SetRevoked sets the "revoked" field. func (buo *BouncerUpdateOne) SetRevoked(b bool) *BouncerUpdateOne { buo.mutation.SetRevoked(b) return buo } -// SetIPAddress sets the ip_address field. +// SetIPAddress sets the "ip_address" field. func (buo *BouncerUpdateOne) SetIPAddress(s string) *BouncerUpdateOne { buo.mutation.SetIPAddress(s) return buo } -// SetNillableIPAddress sets the ip_address field if the given value is not nil. +// SetNillableIPAddress sets the "ip_address" field if the given value is not nil. func (buo *BouncerUpdateOne) SetNillableIPAddress(s *string) *BouncerUpdateOne { if s != nil { buo.SetIPAddress(*s) @@ -414,19 +413,19 @@ func (buo *BouncerUpdateOne) SetNillableIPAddress(s *string) *BouncerUpdateOne { return buo } -// ClearIPAddress clears the value of ip_address. +// ClearIPAddress clears the value of the "ip_address" field. func (buo *BouncerUpdateOne) ClearIPAddress() *BouncerUpdateOne { buo.mutation.ClearIPAddress() return buo } -// SetType sets the type field. +// SetType sets the "type" field. func (buo *BouncerUpdateOne) SetType(s string) *BouncerUpdateOne { buo.mutation.SetType(s) return buo } -// SetNillableType sets the type field if the given value is not nil. +// SetNillableType sets the "type" field if the given value is not nil. func (buo *BouncerUpdateOne) SetNillableType(s *string) *BouncerUpdateOne { if s != nil { buo.SetType(*s) @@ -434,19 +433,19 @@ func (buo *BouncerUpdateOne) SetNillableType(s *string) *BouncerUpdateOne { return buo } -// ClearType clears the value of type. +// ClearType clears the value of the "type" field. func (buo *BouncerUpdateOne) ClearType() *BouncerUpdateOne { buo.mutation.ClearType() return buo } -// SetVersion sets the version field. +// SetVersion sets the "version" field. func (buo *BouncerUpdateOne) SetVersion(s string) *BouncerUpdateOne { buo.mutation.SetVersion(s) return buo } -// SetNillableVersion sets the version field if the given value is not nil. +// SetNillableVersion sets the "version" field if the given value is not nil. func (buo *BouncerUpdateOne) SetNillableVersion(s *string) *BouncerUpdateOne { if s != nil { buo.SetVersion(*s) @@ -454,19 +453,19 @@ func (buo *BouncerUpdateOne) SetNillableVersion(s *string) *BouncerUpdateOne { return buo } -// ClearVersion clears the value of version. +// ClearVersion clears the value of the "version" field. func (buo *BouncerUpdateOne) ClearVersion() *BouncerUpdateOne { buo.mutation.ClearVersion() return buo } -// SetUntil sets the until field. +// SetUntil sets the "until" field. func (buo *BouncerUpdateOne) SetUntil(t time.Time) *BouncerUpdateOne { buo.mutation.SetUntil(t) return buo } -// SetNillableUntil sets the until field if the given value is not nil. +// SetNillableUntil sets the "until" field if the given value is not nil. func (buo *BouncerUpdateOne) SetNillableUntil(t *time.Time) *BouncerUpdateOne { if t != nil { buo.SetUntil(*t) @@ -474,19 +473,19 @@ func (buo *BouncerUpdateOne) SetNillableUntil(t *time.Time) *BouncerUpdateOne { return buo } -// ClearUntil clears the value of until. +// ClearUntil clears the value of the "until" field. func (buo *BouncerUpdateOne) ClearUntil() *BouncerUpdateOne { buo.mutation.ClearUntil() return buo } -// SetLastPull sets the last_pull field. +// SetLastPull sets the "last_pull" field. func (buo *BouncerUpdateOne) SetLastPull(t time.Time) *BouncerUpdateOne { buo.mutation.SetLastPull(t) return buo } -// SetNillableLastPull sets the last_pull field if the given value is not nil. +// SetNillableLastPull sets the "last_pull" field if the given value is not nil. func (buo *BouncerUpdateOne) SetNillableLastPull(t *time.Time) *BouncerUpdateOne { if t != nil { buo.SetLastPull(*t) @@ -499,7 +498,7 @@ func (buo *BouncerUpdateOne) Mutation() *BouncerMutation { return buo.mutation } -// Save executes the query and returns the updated entity. +// Save executes the query and returns the updated Bouncer entity. func (buo *BouncerUpdateOne) Save(ctx context.Context) (*Bouncer, error) { var ( err error @@ -662,7 +661,7 @@ func (buo *BouncerUpdateOne) sqlSave(ctx context.Context) (_node *Bouncer, err e } _node = &Bouncer{config: buo.config} _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues() + _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, buo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{bouncer.Label} diff --git a/pkg/database/ent/client.go b/pkg/database/ent/client.go index 87aedaac0..cb36bde4c 100644 --- a/pkg/database/ent/client.go +++ b/pkg/database/ent/client.go @@ -98,7 +98,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { }, nil } -// BeginTx returns a transactional client with options. +// BeginTx returns a transactional client with specified options. func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") @@ -174,7 +174,7 @@ func (c *AlertClient) Create() *AlertCreate { return &AlertCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } -// BulkCreate returns a builder for creating a bulk of Alert entities. +// CreateBulk returns a builder for creating a bulk of Alert entities. func (c *AlertClient) CreateBulk(builders ...*AlertCreate) *AlertCreateBulk { return &AlertCreateBulk{config: c.config, builders: builders} } @@ -326,7 +326,7 @@ func (c *BouncerClient) Create() *BouncerCreate { return &BouncerCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } -// BulkCreate returns a builder for creating a bulk of Bouncer entities. +// CreateBulk returns a builder for creating a bulk of Bouncer entities. func (c *BouncerClient) CreateBulk(builders ...*BouncerCreate) *BouncerCreateBulk { return &BouncerCreateBulk{config: c.config, builders: builders} } @@ -414,7 +414,7 @@ func (c *DecisionClient) Create() *DecisionCreate { return &DecisionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } -// BulkCreate returns a builder for creating a bulk of Decision entities. +// CreateBulk returns a builder for creating a bulk of Decision entities. func (c *DecisionClient) CreateBulk(builders ...*DecisionCreate) *DecisionCreateBulk { return &DecisionCreateBulk{config: c.config, builders: builders} } @@ -518,7 +518,7 @@ func (c *EventClient) Create() *EventCreate { return &EventCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } -// BulkCreate returns a builder for creating a bulk of Event entities. +// CreateBulk returns a builder for creating a bulk of Event entities. func (c *EventClient) CreateBulk(builders ...*EventCreate) *EventCreateBulk { return &EventCreateBulk{config: c.config, builders: builders} } @@ -622,7 +622,7 @@ func (c *MachineClient) Create() *MachineCreate { return &MachineCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } -// BulkCreate returns a builder for creating a bulk of Machine entities. +// CreateBulk returns a builder for creating a bulk of Machine entities. func (c *MachineClient) CreateBulk(builders ...*MachineCreate) *MachineCreateBulk { return &MachineCreateBulk{config: c.config, builders: builders} } @@ -726,7 +726,7 @@ func (c *MetaClient) Create() *MetaCreate { return &MetaCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } -// BulkCreate returns a builder for creating a bulk of Meta entities. +// CreateBulk returns a builder for creating a bulk of Meta entities. func (c *MetaClient) CreateBulk(builders ...*MetaCreate) *MetaCreateBulk { return &MetaCreateBulk{config: c.config, builders: builders} } diff --git a/pkg/database/ent/context.go b/pkg/database/ent/context.go index b432b5961..08407261b 100644 --- a/pkg/database/ent/context.go +++ b/pkg/database/ent/context.go @@ -8,7 +8,7 @@ import ( type clientCtxKey struct{} -// FromContext returns the Client stored in a context, or nil if there isn't one. +// FromContext returns a Client stored inside a context, or nil if there isn't one. func FromContext(ctx context.Context) *Client { c, _ := ctx.Value(clientCtxKey{}).(*Client) return c @@ -21,13 +21,13 @@ func NewContext(parent context.Context, c *Client) context.Context { type txCtxKey struct{} -// TxFromContext returns the Tx stored in a context, or nil if there isn't one. +// TxFromContext returns a Tx stored inside a context, or nil if there isn't one. func TxFromContext(ctx context.Context) *Tx { tx, _ := ctx.Value(txCtxKey{}).(*Tx) return tx } -// NewTxContext returns a new context with the given Client attached. +// NewTxContext returns a new context with the given Tx attached. func NewTxContext(parent context.Context, tx *Tx) context.Context { return context.WithValue(parent, txCtxKey{}, tx) } diff --git a/pkg/database/ent/decision.go b/pkg/database/ent/decision.go index c2abb2020..49201f4b0 100644 --- a/pkg/database/ent/decision.go +++ b/pkg/database/ent/decision.go @@ -31,6 +31,12 @@ type Decision struct { 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. @@ -69,123 +75,151 @@ func (e DecisionEdges) OwnerOrErr() (*Alert, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*Decision) scanValues() []interface{} { - return []interface{}{ - &sql.NullInt64{}, // id - &sql.NullTime{}, // created_at - &sql.NullTime{}, // updated_at - &sql.NullTime{}, // until - &sql.NullString{}, // scenario - &sql.NullString{}, // type - &sql.NullInt64{}, // start_ip - &sql.NullInt64{}, // end_ip - &sql.NullString{}, // scope - &sql.NullString{}, // value - &sql.NullString{}, // origin - &sql.NullBool{}, // simulated - } -} - -// fkValues returns the types for scanning foreign-keys values from sql.Rows. -func (*Decision) fkValues() []interface{} { - return []interface{}{ - &sql.NullInt64{}, // alert_decisions +func (*Decision) scanValues(columns []string) ([]interface{}, error) { + values := make([]interface{}, len(columns)) + for i := range columns { + switch columns[i] { + case decision.FieldSimulated: + values[i] = &sql.NullBool{} + case decision.FieldID, decision.FieldStartIP, decision.FieldEndIP, decision.FieldStartSuffix, decision.FieldEndSuffix, decision.FieldIPSize: + values[i] = &sql.NullInt64{} + case decision.FieldScenario, decision.FieldType, decision.FieldScope, decision.FieldValue, decision.FieldOrigin: + values[i] = &sql.NullString{} + case decision.FieldCreatedAt, decision.FieldUpdatedAt, decision.FieldUntil: + values[i] = &sql.NullTime{} + case decision.ForeignKeys[0]: // alert_decisions + values[i] = &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(values ...interface{}) error { - if m, n := len(values), len(decision.Columns); m < n { +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) } - value, ok := values[0].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - d.ID = int(value.Int64) - values = values[1:] - if value, ok := values[0].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[0]) - } else if value.Valid { - d.CreatedAt = value.Time - } - if value, ok := values[1].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[1]) - } else if value.Valid { - d.UpdatedAt = value.Time - } - if value, ok := values[2].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field until", values[2]) - } else if value.Valid { - d.Until = value.Time - } - if value, ok := values[3].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field scenario", values[3]) - } else if value.Valid { - d.Scenario = value.String - } - if value, ok := values[4].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field type", values[4]) - } else if value.Valid { - d.Type = value.String - } - if value, ok := values[5].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field start_ip", values[5]) - } else if value.Valid { - d.StartIP = value.Int64 - } - if value, ok := values[6].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field end_ip", values[6]) - } else if value.Valid { - d.EndIP = value.Int64 - } - if value, ok := values[7].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field scope", values[7]) - } else if value.Valid { - d.Scope = value.String - } - if value, ok := values[8].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field value", values[8]) - } else if value.Valid { - d.Value = value.String - } - if value, ok := values[9].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field origin", values[9]) - } else if value.Valid { - d.Origin = value.String - } - if value, ok := values[10].(*sql.NullBool); !ok { - return fmt.Errorf("unexpected type %T for field simulated", values[10]) - } else if value.Valid { - d.Simulated = value.Bool - } - values = values[11:] - if len(values) == len(decision.ForeignKeys) { - if value, ok := values[0].(*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) + 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 = 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 = 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. +// 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 +// 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 entity that was returned from a transaction after it was closed, -// so that all next queries will be executed through the driver which created the transaction. +// 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 { @@ -214,6 +248,12 @@ func (d *Decision) String() string { 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=") diff --git a/pkg/database/ent/decision/decision.go b/pkg/database/ent/decision/decision.go index e48b04dc5..6402c56e1 100644 --- a/pkg/database/ent/decision/decision.go +++ b/pkg/database/ent/decision/decision.go @@ -25,6 +25,12 @@ const ( FieldStartIP = "start_ip" // FieldEndIP holds the string denoting the end_ip field in the database. FieldEndIP = "end_ip" + // FieldStartSuffix holds the string denoting the start_suffix field in the database. + FieldStartSuffix = "start_suffix" + // FieldEndSuffix holds the string denoting the end_suffix field in the database. + FieldEndSuffix = "end_suffix" + // FieldIPSize holds the string denoting the ip_size field in the database. + FieldIPSize = "ip_size" // FieldScope holds the string denoting the scope field in the database. FieldScope = "scope" // FieldValue holds the string denoting the value field in the database. @@ -58,6 +64,9 @@ var Columns = []string{ FieldType, FieldStartIP, FieldEndIP, + FieldStartSuffix, + FieldEndSuffix, + FieldIPSize, FieldScope, FieldValue, FieldOrigin, @@ -85,10 +94,10 @@ func ValidColumn(column string) bool { } var ( - // DefaultCreatedAt holds the default value on creation for the created_at field. + // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the updated_at field. + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. DefaultUpdatedAt func() time.Time - // DefaultSimulated holds the default value on creation for the simulated field. + // DefaultSimulated holds the default value on creation for the "simulated" field. DefaultSimulated bool ) diff --git a/pkg/database/ent/decision/where.go b/pkg/database/ent/decision/where.go index ae53e41c3..9fa4e2369 100644 --- a/pkg/database/ent/decision/where.go +++ b/pkg/database/ent/decision/where.go @@ -10,7 +10,7 @@ import ( "github.com/facebook/ent/dialect/sql/sqlgraph" ) -// ID filters vertices based on their identifier. +// ID filters vertices based on their ID field. func ID(id int) predicate.Decision { return predicate.Decision(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldID), id)) @@ -142,6 +142,27 @@ func EndIP(v int64) predicate.Decision { }) } +// StartSuffix applies equality check predicate on the "start_suffix" field. It's identical to StartSuffixEQ. +func StartSuffix(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldStartSuffix), v)) + }) +} + +// EndSuffix applies equality check predicate on the "end_suffix" field. It's identical to EndSuffixEQ. +func EndSuffix(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldEndSuffix), v)) + }) +} + +// IPSize applies equality check predicate on the "ip_size" field. It's identical to IPSizeEQ. +func IPSize(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldIPSize), v)) + }) +} + // Scope applies equality check predicate on the "scope" field. It's identical to ScopeEQ. func Scope(v string) predicate.Decision { return predicate.Decision(func(s *sql.Selector) { @@ -800,6 +821,276 @@ func EndIPNotNil() predicate.Decision { }) } +// StartSuffixEQ applies the EQ predicate on the "start_suffix" field. +func StartSuffixEQ(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldStartSuffix), v)) + }) +} + +// StartSuffixNEQ applies the NEQ predicate on the "start_suffix" field. +func StartSuffixNEQ(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldStartSuffix), v)) + }) +} + +// StartSuffixIn applies the In predicate on the "start_suffix" field. +func StartSuffixIn(vs ...int64) predicate.Decision { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Decision(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldStartSuffix), v...)) + }) +} + +// StartSuffixNotIn applies the NotIn predicate on the "start_suffix" field. +func StartSuffixNotIn(vs ...int64) predicate.Decision { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Decision(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldStartSuffix), v...)) + }) +} + +// StartSuffixGT applies the GT predicate on the "start_suffix" field. +func StartSuffixGT(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldStartSuffix), v)) + }) +} + +// StartSuffixGTE applies the GTE predicate on the "start_suffix" field. +func StartSuffixGTE(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldStartSuffix), v)) + }) +} + +// StartSuffixLT applies the LT predicate on the "start_suffix" field. +func StartSuffixLT(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldStartSuffix), v)) + }) +} + +// StartSuffixLTE applies the LTE predicate on the "start_suffix" field. +func StartSuffixLTE(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldStartSuffix), v)) + }) +} + +// StartSuffixIsNil applies the IsNil predicate on the "start_suffix" field. +func StartSuffixIsNil() predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldStartSuffix))) + }) +} + +// StartSuffixNotNil applies the NotNil predicate on the "start_suffix" field. +func StartSuffixNotNil() predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldStartSuffix))) + }) +} + +// EndSuffixEQ applies the EQ predicate on the "end_suffix" field. +func EndSuffixEQ(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldEndSuffix), v)) + }) +} + +// EndSuffixNEQ applies the NEQ predicate on the "end_suffix" field. +func EndSuffixNEQ(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldEndSuffix), v)) + }) +} + +// EndSuffixIn applies the In predicate on the "end_suffix" field. +func EndSuffixIn(vs ...int64) predicate.Decision { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Decision(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldEndSuffix), v...)) + }) +} + +// EndSuffixNotIn applies the NotIn predicate on the "end_suffix" field. +func EndSuffixNotIn(vs ...int64) predicate.Decision { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Decision(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldEndSuffix), v...)) + }) +} + +// EndSuffixGT applies the GT predicate on the "end_suffix" field. +func EndSuffixGT(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldEndSuffix), v)) + }) +} + +// EndSuffixGTE applies the GTE predicate on the "end_suffix" field. +func EndSuffixGTE(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldEndSuffix), v)) + }) +} + +// EndSuffixLT applies the LT predicate on the "end_suffix" field. +func EndSuffixLT(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldEndSuffix), v)) + }) +} + +// EndSuffixLTE applies the LTE predicate on the "end_suffix" field. +func EndSuffixLTE(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldEndSuffix), v)) + }) +} + +// EndSuffixIsNil applies the IsNil predicate on the "end_suffix" field. +func EndSuffixIsNil() predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldEndSuffix))) + }) +} + +// EndSuffixNotNil applies the NotNil predicate on the "end_suffix" field. +func EndSuffixNotNil() predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldEndSuffix))) + }) +} + +// IPSizeEQ applies the EQ predicate on the "ip_size" field. +func IPSizeEQ(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldIPSize), v)) + }) +} + +// IPSizeNEQ applies the NEQ predicate on the "ip_size" field. +func IPSizeNEQ(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldIPSize), v)) + }) +} + +// IPSizeIn applies the In predicate on the "ip_size" field. +func IPSizeIn(vs ...int64) predicate.Decision { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Decision(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldIPSize), v...)) + }) +} + +// IPSizeNotIn applies the NotIn predicate on the "ip_size" field. +func IPSizeNotIn(vs ...int64) predicate.Decision { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Decision(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldIPSize), v...)) + }) +} + +// IPSizeGT applies the GT predicate on the "ip_size" field. +func IPSizeGT(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldIPSize), v)) + }) +} + +// IPSizeGTE applies the GTE predicate on the "ip_size" field. +func IPSizeGTE(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldIPSize), v)) + }) +} + +// IPSizeLT applies the LT predicate on the "ip_size" field. +func IPSizeLT(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldIPSize), v)) + }) +} + +// IPSizeLTE applies the LTE predicate on the "ip_size" field. +func IPSizeLTE(v int64) predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldIPSize), v)) + }) +} + +// IPSizeIsNil applies the IsNil predicate on the "ip_size" field. +func IPSizeIsNil() predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldIPSize))) + }) +} + +// IPSizeNotNil applies the NotNil predicate on the "ip_size" field. +func IPSizeNotNil() predicate.Decision { + return predicate.Decision(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldIPSize))) + }) +} + // ScopeEQ applies the EQ predicate on the "scope" field. func ScopeEQ(v string) predicate.Decision { return predicate.Decision(func(s *sql.Selector) { @@ -1175,7 +1466,7 @@ func HasOwnerWith(preds ...predicate.Alert) predicate.Decision { }) } -// And groups list of predicates with the AND operator between them. +// And groups predicates with the AND operator between them. func And(predicates ...predicate.Decision) predicate.Decision { return predicate.Decision(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) @@ -1186,7 +1477,7 @@ func And(predicates ...predicate.Decision) predicate.Decision { }) } -// Or groups list of predicates with the OR operator between them. +// Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Decision) predicate.Decision { return predicate.Decision(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) diff --git a/pkg/database/ent/decision_create.go b/pkg/database/ent/decision_create.go index a2e9adbea..02c51f65c 100644 --- a/pkg/database/ent/decision_create.go +++ b/pkg/database/ent/decision_create.go @@ -21,13 +21,13 @@ type DecisionCreate struct { hooks []Hook } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (dc *DecisionCreate) SetCreatedAt(t time.Time) *DecisionCreate { dc.mutation.SetCreatedAt(t) return dc } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (dc *DecisionCreate) SetNillableCreatedAt(t *time.Time) *DecisionCreate { if t != nil { dc.SetCreatedAt(*t) @@ -35,13 +35,13 @@ func (dc *DecisionCreate) SetNillableCreatedAt(t *time.Time) *DecisionCreate { return dc } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (dc *DecisionCreate) SetUpdatedAt(t time.Time) *DecisionCreate { dc.mutation.SetUpdatedAt(t) return dc } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (dc *DecisionCreate) SetNillableUpdatedAt(t *time.Time) *DecisionCreate { if t != nil { dc.SetUpdatedAt(*t) @@ -49,31 +49,31 @@ func (dc *DecisionCreate) SetNillableUpdatedAt(t *time.Time) *DecisionCreate { return dc } -// SetUntil sets the until field. +// SetUntil sets the "until" field. func (dc *DecisionCreate) SetUntil(t time.Time) *DecisionCreate { dc.mutation.SetUntil(t) return dc } -// SetScenario sets the scenario field. +// SetScenario sets the "scenario" field. func (dc *DecisionCreate) SetScenario(s string) *DecisionCreate { dc.mutation.SetScenario(s) return dc } -// SetType sets the type field. +// SetType sets the "type" field. func (dc *DecisionCreate) SetType(s string) *DecisionCreate { dc.mutation.SetType(s) return dc } -// SetStartIP sets the start_ip field. +// SetStartIP sets the "start_ip" field. func (dc *DecisionCreate) SetStartIP(i int64) *DecisionCreate { dc.mutation.SetStartIP(i) return dc } -// SetNillableStartIP sets the start_ip field if the given value is not nil. +// SetNillableStartIP sets the "start_ip" field if the given value is not nil. func (dc *DecisionCreate) SetNillableStartIP(i *int64) *DecisionCreate { if i != nil { dc.SetStartIP(*i) @@ -81,13 +81,13 @@ func (dc *DecisionCreate) SetNillableStartIP(i *int64) *DecisionCreate { return dc } -// SetEndIP sets the end_ip field. +// SetEndIP sets the "end_ip" field. func (dc *DecisionCreate) SetEndIP(i int64) *DecisionCreate { dc.mutation.SetEndIP(i) return dc } -// SetNillableEndIP sets the end_ip field if the given value is not nil. +// SetNillableEndIP sets the "end_ip" field if the given value is not nil. func (dc *DecisionCreate) SetNillableEndIP(i *int64) *DecisionCreate { if i != nil { dc.SetEndIP(*i) @@ -95,31 +95,73 @@ func (dc *DecisionCreate) SetNillableEndIP(i *int64) *DecisionCreate { return dc } -// SetScope sets the scope field. +// SetStartSuffix sets the "start_suffix" field. +func (dc *DecisionCreate) SetStartSuffix(i int64) *DecisionCreate { + dc.mutation.SetStartSuffix(i) + return dc +} + +// SetNillableStartSuffix sets the "start_suffix" field if the given value is not nil. +func (dc *DecisionCreate) SetNillableStartSuffix(i *int64) *DecisionCreate { + if i != nil { + dc.SetStartSuffix(*i) + } + return dc +} + +// SetEndSuffix sets the "end_suffix" field. +func (dc *DecisionCreate) SetEndSuffix(i int64) *DecisionCreate { + dc.mutation.SetEndSuffix(i) + return dc +} + +// SetNillableEndSuffix sets the "end_suffix" field if the given value is not nil. +func (dc *DecisionCreate) SetNillableEndSuffix(i *int64) *DecisionCreate { + if i != nil { + dc.SetEndSuffix(*i) + } + return dc +} + +// SetIPSize sets the "ip_size" field. +func (dc *DecisionCreate) SetIPSize(i int64) *DecisionCreate { + dc.mutation.SetIPSize(i) + return dc +} + +// SetNillableIPSize sets the "ip_size" field if the given value is not nil. +func (dc *DecisionCreate) SetNillableIPSize(i *int64) *DecisionCreate { + if i != nil { + dc.SetIPSize(*i) + } + return dc +} + +// SetScope sets the "scope" field. func (dc *DecisionCreate) SetScope(s string) *DecisionCreate { dc.mutation.SetScope(s) return dc } -// SetValue sets the value field. +// SetValue sets the "value" field. func (dc *DecisionCreate) SetValue(s string) *DecisionCreate { dc.mutation.SetValue(s) return dc } -// SetOrigin sets the origin field. +// SetOrigin sets the "origin" field. func (dc *DecisionCreate) SetOrigin(s string) *DecisionCreate { dc.mutation.SetOrigin(s) return dc } -// SetSimulated sets the simulated field. +// SetSimulated sets the "simulated" field. func (dc *DecisionCreate) SetSimulated(b bool) *DecisionCreate { dc.mutation.SetSimulated(b) return dc } -// SetNillableSimulated sets the simulated field if the given value is not nil. +// SetNillableSimulated sets the "simulated" field if the given value is not nil. func (dc *DecisionCreate) SetNillableSimulated(b *bool) *DecisionCreate { if b != nil { dc.SetSimulated(*b) @@ -127,13 +169,13 @@ func (dc *DecisionCreate) SetNillableSimulated(b *bool) *DecisionCreate { return dc } -// SetOwnerID sets the owner edge to Alert by id. +// SetOwnerID sets the "owner" edge to the Alert entity by ID. func (dc *DecisionCreate) SetOwnerID(id int) *DecisionCreate { dc.mutation.SetOwnerID(id) return dc } -// SetNillableOwnerID sets the owner edge to Alert by id if the given value is not nil. +// SetNillableOwnerID sets the "owner" edge to the Alert entity by ID if the given value is not nil. func (dc *DecisionCreate) SetNillableOwnerID(id *int) *DecisionCreate { if id != nil { dc = dc.SetOwnerID(*id) @@ -141,7 +183,7 @@ func (dc *DecisionCreate) SetNillableOwnerID(id *int) *DecisionCreate { return dc } -// SetOwner sets the owner edge to Alert. +// SetOwner sets the "owner" edge to the Alert entity. func (dc *DecisionCreate) SetOwner(a *Alert) *DecisionCreate { return dc.SetOwnerID(a.ID) } @@ -324,6 +366,30 @@ func (dc *DecisionCreate) createSpec() (*Decision, *sqlgraph.CreateSpec) { }) _node.EndIP = value } + if value, ok := dc.mutation.StartSuffix(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldStartSuffix, + }) + _node.StartSuffix = value + } + if value, ok := dc.mutation.EndSuffix(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldEndSuffix, + }) + _node.EndSuffix = value + } + if value, ok := dc.mutation.IPSize(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldIPSize, + }) + _node.IPSize = value + } if value, ok := dc.mutation.Scope(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, @@ -378,7 +444,7 @@ func (dc *DecisionCreate) createSpec() (*Decision, *sqlgraph.CreateSpec) { return _node, _spec } -// DecisionCreateBulk is the builder for creating a bulk of Decision entities. +// DecisionCreateBulk is the builder for creating many Decision entities in bulk. type DecisionCreateBulk struct { config builders []*DecisionCreate @@ -436,7 +502,7 @@ func (dcb *DecisionCreateBulk) Save(ctx context.Context) ([]*Decision, error) { return nodes, nil } -// SaveX calls Save and panics if Save returns an error. +// SaveX is like Save, but panics if an error occurs. func (dcb *DecisionCreateBulk) SaveX(ctx context.Context) []*Decision { v, err := dcb.Save(ctx) if err != nil { diff --git a/pkg/database/ent/decision_delete.go b/pkg/database/ent/decision_delete.go index 58bca2292..b7bee6570 100644 --- a/pkg/database/ent/decision_delete.go +++ b/pkg/database/ent/decision_delete.go @@ -16,14 +16,13 @@ import ( // DecisionDelete is the builder for deleting a Decision entity. type DecisionDelete struct { config - hooks []Hook - mutation *DecisionMutation - predicates []predicate.Decision + hooks []Hook + mutation *DecisionMutation } -// Where adds a new predicate to the delete builder. +// Where adds a new predicate to the DecisionDelete builder. func (dd *DecisionDelete) Where(ps ...predicate.Decision) *DecisionDelete { - dd.predicates = append(dd.predicates, ps...) + dd.mutation.predicates = append(dd.mutation.predicates, ps...) return dd } @@ -75,7 +74,7 @@ func (dd *DecisionDelete) sqlExec(ctx context.Context) (int, error) { }, }, } - if ps := dd.predicates; len(ps) > 0 { + if ps := dd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) diff --git a/pkg/database/ent/decision_query.go b/pkg/database/ent/decision_query.go index 14b3f28da..a87f6e029 100644 --- a/pkg/database/ent/decision_query.go +++ b/pkg/database/ent/decision_query.go @@ -22,7 +22,7 @@ type DecisionQuery struct { limit *int offset *int order []OrderFunc - unique []string + fields []string predicates []predicate.Decision // eager-loading edges. withOwner *AlertQuery @@ -32,7 +32,7 @@ type DecisionQuery struct { path func(context.Context) (*sql.Selector, error) } -// Where adds a new predicate for the builder. +// Where adds a new predicate for the DecisionQuery builder. func (dq *DecisionQuery) Where(ps ...predicate.Decision) *DecisionQuery { dq.predicates = append(dq.predicates, ps...) return dq @@ -56,7 +56,7 @@ func (dq *DecisionQuery) Order(o ...OrderFunc) *DecisionQuery { return dq } -// QueryOwner chains the current query on the owner edge. +// QueryOwner chains the current query on the "owner" edge. func (dq *DecisionQuery) QueryOwner() *AlertQuery { query := &AlertQuery{config: dq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { @@ -78,7 +78,8 @@ func (dq *DecisionQuery) QueryOwner() *AlertQuery { return query } -// First returns the first Decision entity in the query. Returns *NotFoundError when no decision was found. +// First returns the first Decision entity from the query. +// Returns a *NotFoundError when no Decision was found. func (dq *DecisionQuery) First(ctx context.Context) (*Decision, error) { nodes, err := dq.Limit(1).All(ctx) if err != nil { @@ -99,7 +100,8 @@ func (dq *DecisionQuery) FirstX(ctx context.Context) *Decision { return node } -// FirstID returns the first Decision id in the query. Returns *NotFoundError when no id was found. +// FirstID returns the first Decision ID from the query. +// Returns a *NotFoundError when no Decision ID was found. func (dq *DecisionQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int if ids, err = dq.Limit(1).IDs(ctx); err != nil { @@ -112,8 +114,8 @@ func (dq *DecisionQuery) FirstID(ctx context.Context) (id int, err error) { return ids[0], nil } -// FirstXID is like FirstID, but panics if an error occurs. -func (dq *DecisionQuery) FirstXID(ctx context.Context) int { +// FirstIDX is like FirstID, but panics if an error occurs. +func (dq *DecisionQuery) FirstIDX(ctx context.Context) int { id, err := dq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -121,7 +123,9 @@ func (dq *DecisionQuery) FirstXID(ctx context.Context) int { return id } -// Only returns the only Decision entity in the query, returns an error if not exactly one entity was returned. +// Only returns a single Decision entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when exactly one Decision entity is not found. +// Returns a *NotFoundError when no Decision entities are found. func (dq *DecisionQuery) Only(ctx context.Context) (*Decision, error) { nodes, err := dq.Limit(2).All(ctx) if err != nil { @@ -146,7 +150,9 @@ func (dq *DecisionQuery) OnlyX(ctx context.Context) *Decision { return node } -// OnlyID returns the only Decision id in the query, returns an error if not exactly one id was returned. +// OnlyID is like Only, but returns the only Decision ID in the query. +// Returns a *NotSingularError when exactly one Decision ID is not found. +// Returns a *NotFoundError when no entities are found. func (dq *DecisionQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int if ids, err = dq.Limit(2).IDs(ctx); err != nil { @@ -189,7 +195,7 @@ func (dq *DecisionQuery) AllX(ctx context.Context) []*Decision { return nodes } -// IDs executes the query and returns a list of Decision ids. +// IDs executes the query and returns a list of Decision IDs. func (dq *DecisionQuery) IDs(ctx context.Context) ([]int, error) { var ids []int if err := dq.Select(decision.FieldID).Scan(ctx, &ids); err != nil { @@ -241,24 +247,27 @@ func (dq *DecisionQuery) ExistX(ctx context.Context) bool { return exist } -// Clone returns a duplicate of the query builder, including all associated steps. It can be +// Clone returns a duplicate of the DecisionQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. func (dq *DecisionQuery) Clone() *DecisionQuery { + if dq == nil { + return nil + } return &DecisionQuery{ config: dq.config, limit: dq.limit, offset: dq.offset, order: append([]OrderFunc{}, dq.order...), - unique: append([]string{}, dq.unique...), predicates: append([]predicate.Decision{}, dq.predicates...), + withOwner: dq.withOwner.Clone(), // clone intermediate query. sql: dq.sql.Clone(), path: dq.path, } } -// WithOwner tells the query-builder to eager-loads the nodes that are connected to -// the "owner" edge. The optional arguments used to configure the query builder of the edge. +// WithOwner tells the query-builder to eager-load the nodes that are connected to +// the "owner" edge. The optional arguments are used to configure the query builder of the edge. func (dq *DecisionQuery) WithOwner(opts ...func(*AlertQuery)) *DecisionQuery { query := &AlertQuery{config: dq.config} for _, opt := range opts { @@ -268,7 +277,7 @@ func (dq *DecisionQuery) WithOwner(opts ...func(*AlertQuery)) *DecisionQuery { return dq } -// GroupBy used to group vertices by one or more fields/columns. +// GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // // Example: @@ -295,7 +304,8 @@ func (dq *DecisionQuery) GroupBy(field string, fields ...string) *DecisionGroupB return group } -// Select one or more fields from the given query. +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. // // Example: // @@ -308,18 +318,16 @@ func (dq *DecisionQuery) GroupBy(field string, fields ...string) *DecisionGroupB // Scan(ctx, &v) // func (dq *DecisionQuery) Select(field string, fields ...string) *DecisionSelect { - selector := &DecisionSelect{config: dq.config} - selector.fields = append([]string{field}, fields...) - selector.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := dq.prepareQuery(ctx); err != nil { - return nil, err - } - return dq.sqlQuery(), nil - } - return selector + dq.fields = append([]string{field}, fields...) + return &DecisionSelect{DecisionQuery: dq} } func (dq *DecisionQuery) prepareQuery(ctx context.Context) error { + for _, f := range dq.fields { + if !decision.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } if dq.path != nil { prev, err := dq.path(ctx) if err != nil { @@ -345,22 +353,18 @@ func (dq *DecisionQuery) sqlAll(ctx context.Context) ([]*Decision, error) { if withFKs { _spec.Node.Columns = append(_spec.Node.Columns, decision.ForeignKeys...) } - _spec.ScanValues = func() []interface{} { + _spec.ScanValues = func(columns []string) ([]interface{}, error) { node := &Decision{config: dq.config} nodes = append(nodes, node) - values := node.scanValues() - if withFKs { - values = append(values, node.fkValues()...) - } - return values + return node.scanValues(columns) } - _spec.Assign = func(values ...interface{}) error { + _spec.Assign = func(columns []string, values []interface{}) error { if len(nodes) == 0 { return fmt.Errorf("ent: Assign called without calling ScanValues") } node := nodes[len(nodes)-1] node.Edges.loadedTypes = loadedTypes - return node.assignValues(values...) + return node.assignValues(columns, values) } if err := sqlgraph.QueryNodes(ctx, dq.driver, _spec); err != nil { return nil, err @@ -423,6 +427,15 @@ func (dq *DecisionQuery) querySpec() *sqlgraph.QuerySpec { From: dq.sql, Unique: true, } + if fields := dq.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, decision.FieldID) + for i := range fields { + if fields[i] != decision.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } if ps := dq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -471,7 +484,7 @@ func (dq *DecisionQuery) sqlQuery() *sql.Selector { return selector } -// DecisionGroupBy is the builder for group-by Decision entities. +// DecisionGroupBy is the group-by builder for Decision entities. type DecisionGroupBy struct { config fields []string @@ -487,7 +500,7 @@ func (dgb *DecisionGroupBy) Aggregate(fns ...AggregateFunc) *DecisionGroupBy { return dgb } -// Scan applies the group-by query and scan the result into the given value. +// Scan applies the group-by query and scans the result into the given value. func (dgb *DecisionGroupBy) Scan(ctx context.Context, v interface{}) error { query, err := dgb.path(ctx) if err != nil { @@ -504,7 +517,8 @@ func (dgb *DecisionGroupBy) ScanX(ctx context.Context, v interface{}) { } } -// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field. +// Strings returns list of strings from group-by. +// It is only allowed when executing a group-by query with one field. func (dgb *DecisionGroupBy) Strings(ctx context.Context) ([]string, error) { if len(dgb.fields) > 1 { return nil, errors.New("ent: DecisionGroupBy.Strings is not achievable when grouping more than 1 field") @@ -525,7 +539,8 @@ func (dgb *DecisionGroupBy) StringsX(ctx context.Context) []string { return v } -// String returns a single string from group-by. It is only allowed when querying group-by with one field. +// String returns a single string from a group-by query. +// It is only allowed when executing a group-by query with one field. func (dgb *DecisionGroupBy) String(ctx context.Context) (_ string, err error) { var v []string if v, err = dgb.Strings(ctx); err != nil { @@ -551,7 +566,8 @@ func (dgb *DecisionGroupBy) StringX(ctx context.Context) string { return v } -// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field. +// Ints returns list of ints from group-by. +// It is only allowed when executing a group-by query with one field. func (dgb *DecisionGroupBy) Ints(ctx context.Context) ([]int, error) { if len(dgb.fields) > 1 { return nil, errors.New("ent: DecisionGroupBy.Ints is not achievable when grouping more than 1 field") @@ -572,7 +588,8 @@ func (dgb *DecisionGroupBy) IntsX(ctx context.Context) []int { return v } -// Int returns a single int from group-by. It is only allowed when querying group-by with one field. +// Int returns a single int from a group-by query. +// It is only allowed when executing a group-by query with one field. func (dgb *DecisionGroupBy) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = dgb.Ints(ctx); err != nil { @@ -598,7 +615,8 @@ func (dgb *DecisionGroupBy) IntX(ctx context.Context) int { return v } -// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field. +// Float64s returns list of float64s from group-by. +// It is only allowed when executing a group-by query with one field. func (dgb *DecisionGroupBy) Float64s(ctx context.Context) ([]float64, error) { if len(dgb.fields) > 1 { return nil, errors.New("ent: DecisionGroupBy.Float64s is not achievable when grouping more than 1 field") @@ -619,7 +637,8 @@ func (dgb *DecisionGroupBy) Float64sX(ctx context.Context) []float64 { return v } -// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field. +// Float64 returns a single float64 from a group-by query. +// It is only allowed when executing a group-by query with one field. func (dgb *DecisionGroupBy) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = dgb.Float64s(ctx); err != nil { @@ -645,7 +664,8 @@ func (dgb *DecisionGroupBy) Float64X(ctx context.Context) float64 { return v } -// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field. +// Bools returns list of bools from group-by. +// It is only allowed when executing a group-by query with one field. func (dgb *DecisionGroupBy) Bools(ctx context.Context) ([]bool, error) { if len(dgb.fields) > 1 { return nil, errors.New("ent: DecisionGroupBy.Bools is not achievable when grouping more than 1 field") @@ -666,7 +686,8 @@ func (dgb *DecisionGroupBy) BoolsX(ctx context.Context) []bool { return v } -// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field. +// Bool returns a single bool from a group-by query. +// It is only allowed when executing a group-by query with one field. func (dgb *DecisionGroupBy) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = dgb.Bools(ctx); err != nil { @@ -721,22 +742,19 @@ func (dgb *DecisionGroupBy) sqlQuery() *sql.Selector { return selector.Select(columns...).GroupBy(dgb.fields...) } -// DecisionSelect is the builder for select fields of Decision entities. +// DecisionSelect is the builder for selecting fields of Decision entities. type DecisionSelect struct { - config - fields []string + *DecisionQuery // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + sql *sql.Selector } -// Scan applies the selector query and scan the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (ds *DecisionSelect) Scan(ctx context.Context, v interface{}) error { - query, err := ds.path(ctx) - if err != nil { + if err := ds.prepareQuery(ctx); err != nil { return err } - ds.sql = query + ds.sql = ds.DecisionQuery.sqlQuery() return ds.sqlScan(ctx, v) } @@ -747,7 +765,7 @@ func (ds *DecisionSelect) ScanX(ctx context.Context, v interface{}) { } } -// Strings returns list of strings from selector. It is only allowed when selecting one field. +// Strings returns list of strings from a selector. It is only allowed when selecting one field. func (ds *DecisionSelect) Strings(ctx context.Context) ([]string, error) { if len(ds.fields) > 1 { return nil, errors.New("ent: DecisionSelect.Strings is not achievable when selecting more than 1 field") @@ -768,7 +786,7 @@ func (ds *DecisionSelect) StringsX(ctx context.Context) []string { return v } -// String returns a single string from selector. It is only allowed when selecting one field. +// String returns a single string from a selector. It is only allowed when selecting one field. func (ds *DecisionSelect) String(ctx context.Context) (_ string, err error) { var v []string if v, err = ds.Strings(ctx); err != nil { @@ -794,7 +812,7 @@ func (ds *DecisionSelect) StringX(ctx context.Context) string { return v } -// Ints returns list of ints from selector. It is only allowed when selecting one field. +// Ints returns list of ints from a selector. It is only allowed when selecting one field. func (ds *DecisionSelect) Ints(ctx context.Context) ([]int, error) { if len(ds.fields) > 1 { return nil, errors.New("ent: DecisionSelect.Ints is not achievable when selecting more than 1 field") @@ -815,7 +833,7 @@ func (ds *DecisionSelect) IntsX(ctx context.Context) []int { return v } -// Int returns a single int from selector. It is only allowed when selecting one field. +// Int returns a single int from a selector. It is only allowed when selecting one field. func (ds *DecisionSelect) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = ds.Ints(ctx); err != nil { @@ -841,7 +859,7 @@ func (ds *DecisionSelect) IntX(ctx context.Context) int { return v } -// Float64s returns list of float64s from selector. It is only allowed when selecting one field. +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. func (ds *DecisionSelect) Float64s(ctx context.Context) ([]float64, error) { if len(ds.fields) > 1 { return nil, errors.New("ent: DecisionSelect.Float64s is not achievable when selecting more than 1 field") @@ -862,7 +880,7 @@ func (ds *DecisionSelect) Float64sX(ctx context.Context) []float64 { return v } -// Float64 returns a single float64 from selector. It is only allowed when selecting one field. +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. func (ds *DecisionSelect) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = ds.Float64s(ctx); err != nil { @@ -888,7 +906,7 @@ func (ds *DecisionSelect) Float64X(ctx context.Context) float64 { return v } -// Bools returns list of bools from selector. It is only allowed when selecting one field. +// Bools returns list of bools from a selector. It is only allowed when selecting one field. func (ds *DecisionSelect) Bools(ctx context.Context) ([]bool, error) { if len(ds.fields) > 1 { return nil, errors.New("ent: DecisionSelect.Bools is not achievable when selecting more than 1 field") @@ -909,7 +927,7 @@ func (ds *DecisionSelect) BoolsX(ctx context.Context) []bool { return v } -// Bool returns a single bool from selector. It is only allowed when selecting one field. +// Bool returns a single bool from a selector. It is only allowed when selecting one field. func (ds *DecisionSelect) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = ds.Bools(ctx); err != nil { @@ -936,11 +954,6 @@ func (ds *DecisionSelect) BoolX(ctx context.Context) bool { } func (ds *DecisionSelect) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range ds.fields { - if !decision.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for selection", f)} - } - } rows := &sql.Rows{} query, args := ds.sqlQuery().Query() if err := ds.driver.Query(ctx, query, args, rows); err != nil { diff --git a/pkg/database/ent/decision_update.go b/pkg/database/ent/decision_update.go index 4aa681304..9bd4f05c6 100644 --- a/pkg/database/ent/decision_update.go +++ b/pkg/database/ent/decision_update.go @@ -18,24 +18,23 @@ import ( // DecisionUpdate is the builder for updating Decision entities. type DecisionUpdate struct { config - hooks []Hook - mutation *DecisionMutation - predicates []predicate.Decision + hooks []Hook + mutation *DecisionMutation } -// Where adds a new predicate for the builder. +// Where adds a new predicate for the DecisionUpdate builder. func (du *DecisionUpdate) Where(ps ...predicate.Decision) *DecisionUpdate { - du.predicates = append(du.predicates, ps...) + du.mutation.predicates = append(du.mutation.predicates, ps...) return du } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (du *DecisionUpdate) SetCreatedAt(t time.Time) *DecisionUpdate { du.mutation.SetCreatedAt(t) return du } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (du *DecisionUpdate) SetNillableCreatedAt(t *time.Time) *DecisionUpdate { if t != nil { du.SetCreatedAt(*t) @@ -43,13 +42,13 @@ func (du *DecisionUpdate) SetNillableCreatedAt(t *time.Time) *DecisionUpdate { return du } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (du *DecisionUpdate) SetUpdatedAt(t time.Time) *DecisionUpdate { du.mutation.SetUpdatedAt(t) return du } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (du *DecisionUpdate) SetNillableUpdatedAt(t *time.Time) *DecisionUpdate { if t != nil { du.SetUpdatedAt(*t) @@ -57,32 +56,32 @@ func (du *DecisionUpdate) SetNillableUpdatedAt(t *time.Time) *DecisionUpdate { return du } -// SetUntil sets the until field. +// SetUntil sets the "until" field. func (du *DecisionUpdate) SetUntil(t time.Time) *DecisionUpdate { du.mutation.SetUntil(t) return du } -// SetScenario sets the scenario field. +// SetScenario sets the "scenario" field. func (du *DecisionUpdate) SetScenario(s string) *DecisionUpdate { du.mutation.SetScenario(s) return du } -// SetType sets the type field. +// SetType sets the "type" field. func (du *DecisionUpdate) SetType(s string) *DecisionUpdate { du.mutation.SetType(s) return du } -// SetStartIP sets the start_ip field. +// SetStartIP sets the "start_ip" field. func (du *DecisionUpdate) SetStartIP(i int64) *DecisionUpdate { du.mutation.ResetStartIP() du.mutation.SetStartIP(i) return du } -// SetNillableStartIP sets the start_ip field if the given value is not nil. +// SetNillableStartIP sets the "start_ip" field if the given value is not nil. func (du *DecisionUpdate) SetNillableStartIP(i *int64) *DecisionUpdate { if i != nil { du.SetStartIP(*i) @@ -90,26 +89,26 @@ func (du *DecisionUpdate) SetNillableStartIP(i *int64) *DecisionUpdate { return du } -// AddStartIP adds i to start_ip. +// AddStartIP adds i to the "start_ip" field. func (du *DecisionUpdate) AddStartIP(i int64) *DecisionUpdate { du.mutation.AddStartIP(i) return du } -// ClearStartIP clears the value of start_ip. +// ClearStartIP clears the value of the "start_ip" field. func (du *DecisionUpdate) ClearStartIP() *DecisionUpdate { du.mutation.ClearStartIP() return du } -// SetEndIP sets the end_ip field. +// SetEndIP sets the "end_ip" field. func (du *DecisionUpdate) SetEndIP(i int64) *DecisionUpdate { du.mutation.ResetEndIP() du.mutation.SetEndIP(i) return du } -// SetNillableEndIP sets the end_ip field if the given value is not nil. +// SetNillableEndIP sets the "end_ip" field if the given value is not nil. func (du *DecisionUpdate) SetNillableEndIP(i *int64) *DecisionUpdate { if i != nil { du.SetEndIP(*i) @@ -117,43 +116,124 @@ func (du *DecisionUpdate) SetNillableEndIP(i *int64) *DecisionUpdate { return du } -// AddEndIP adds i to end_ip. +// AddEndIP adds i to the "end_ip" field. func (du *DecisionUpdate) AddEndIP(i int64) *DecisionUpdate { du.mutation.AddEndIP(i) return du } -// ClearEndIP clears the value of end_ip. +// ClearEndIP clears the value of the "end_ip" field. func (du *DecisionUpdate) ClearEndIP() *DecisionUpdate { du.mutation.ClearEndIP() return du } -// SetScope sets the scope field. +// SetStartSuffix sets the "start_suffix" field. +func (du *DecisionUpdate) SetStartSuffix(i int64) *DecisionUpdate { + du.mutation.ResetStartSuffix() + du.mutation.SetStartSuffix(i) + return du +} + +// SetNillableStartSuffix sets the "start_suffix" field if the given value is not nil. +func (du *DecisionUpdate) SetNillableStartSuffix(i *int64) *DecisionUpdate { + if i != nil { + du.SetStartSuffix(*i) + } + return du +} + +// AddStartSuffix adds i to the "start_suffix" field. +func (du *DecisionUpdate) AddStartSuffix(i int64) *DecisionUpdate { + du.mutation.AddStartSuffix(i) + return du +} + +// ClearStartSuffix clears the value of the "start_suffix" field. +func (du *DecisionUpdate) ClearStartSuffix() *DecisionUpdate { + du.mutation.ClearStartSuffix() + return du +} + +// SetEndSuffix sets the "end_suffix" field. +func (du *DecisionUpdate) SetEndSuffix(i int64) *DecisionUpdate { + du.mutation.ResetEndSuffix() + du.mutation.SetEndSuffix(i) + return du +} + +// SetNillableEndSuffix sets the "end_suffix" field if the given value is not nil. +func (du *DecisionUpdate) SetNillableEndSuffix(i *int64) *DecisionUpdate { + if i != nil { + du.SetEndSuffix(*i) + } + return du +} + +// AddEndSuffix adds i to the "end_suffix" field. +func (du *DecisionUpdate) AddEndSuffix(i int64) *DecisionUpdate { + du.mutation.AddEndSuffix(i) + return du +} + +// ClearEndSuffix clears the value of the "end_suffix" field. +func (du *DecisionUpdate) ClearEndSuffix() *DecisionUpdate { + du.mutation.ClearEndSuffix() + return du +} + +// SetIPSize sets the "ip_size" field. +func (du *DecisionUpdate) SetIPSize(i int64) *DecisionUpdate { + du.mutation.ResetIPSize() + du.mutation.SetIPSize(i) + return du +} + +// SetNillableIPSize sets the "ip_size" field if the given value is not nil. +func (du *DecisionUpdate) SetNillableIPSize(i *int64) *DecisionUpdate { + if i != nil { + du.SetIPSize(*i) + } + return du +} + +// AddIPSize adds i to the "ip_size" field. +func (du *DecisionUpdate) AddIPSize(i int64) *DecisionUpdate { + du.mutation.AddIPSize(i) + return du +} + +// ClearIPSize clears the value of the "ip_size" field. +func (du *DecisionUpdate) ClearIPSize() *DecisionUpdate { + du.mutation.ClearIPSize() + return du +} + +// SetScope sets the "scope" field. func (du *DecisionUpdate) SetScope(s string) *DecisionUpdate { du.mutation.SetScope(s) return du } -// SetValue sets the value field. +// SetValue sets the "value" field. func (du *DecisionUpdate) SetValue(s string) *DecisionUpdate { du.mutation.SetValue(s) return du } -// SetOrigin sets the origin field. +// SetOrigin sets the "origin" field. func (du *DecisionUpdate) SetOrigin(s string) *DecisionUpdate { du.mutation.SetOrigin(s) return du } -// SetSimulated sets the simulated field. +// SetSimulated sets the "simulated" field. func (du *DecisionUpdate) SetSimulated(b bool) *DecisionUpdate { du.mutation.SetSimulated(b) return du } -// SetNillableSimulated sets the simulated field if the given value is not nil. +// SetNillableSimulated sets the "simulated" field if the given value is not nil. func (du *DecisionUpdate) SetNillableSimulated(b *bool) *DecisionUpdate { if b != nil { du.SetSimulated(*b) @@ -161,13 +241,13 @@ func (du *DecisionUpdate) SetNillableSimulated(b *bool) *DecisionUpdate { return du } -// SetOwnerID sets the owner edge to Alert by id. +// SetOwnerID sets the "owner" edge to the Alert entity by ID. func (du *DecisionUpdate) SetOwnerID(id int) *DecisionUpdate { du.mutation.SetOwnerID(id) return du } -// SetNillableOwnerID sets the owner edge to Alert by id if the given value is not nil. +// SetNillableOwnerID sets the "owner" edge to the Alert entity by ID if the given value is not nil. func (du *DecisionUpdate) SetNillableOwnerID(id *int) *DecisionUpdate { if id != nil { du = du.SetOwnerID(*id) @@ -175,7 +255,7 @@ func (du *DecisionUpdate) SetNillableOwnerID(id *int) *DecisionUpdate { return du } -// SetOwner sets the owner edge to Alert. +// SetOwner sets the "owner" edge to the Alert entity. func (du *DecisionUpdate) SetOwner(a *Alert) *DecisionUpdate { return du.SetOwnerID(a.ID) } @@ -185,13 +265,13 @@ func (du *DecisionUpdate) Mutation() *DecisionMutation { return du.mutation } -// ClearOwner clears the "owner" edge to type Alert. +// ClearOwner clears the "owner" edge to the Alert entity. func (du *DecisionUpdate) ClearOwner() *DecisionUpdate { du.mutation.ClearOwner() return du } -// Save executes the query and returns the number of rows/vertices matched by this operation. +// Save executes the query and returns the number of nodes affected by the update operation. func (du *DecisionUpdate) Save(ctx context.Context) (int, error) { var ( err error @@ -253,7 +333,7 @@ func (du *DecisionUpdate) sqlSave(ctx context.Context) (n int, err error) { }, }, } - if ps := du.predicates; len(ps) > 0 { + if ps := du.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) @@ -335,6 +415,66 @@ func (du *DecisionUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: decision.FieldEndIP, }) } + if value, ok := du.mutation.StartSuffix(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldStartSuffix, + }) + } + if value, ok := du.mutation.AddedStartSuffix(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldStartSuffix, + }) + } + if du.mutation.StartSuffixCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: decision.FieldStartSuffix, + }) + } + if value, ok := du.mutation.EndSuffix(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldEndSuffix, + }) + } + if value, ok := du.mutation.AddedEndSuffix(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldEndSuffix, + }) + } + if du.mutation.EndSuffixCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: decision.FieldEndSuffix, + }) + } + if value, ok := du.mutation.IPSize(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldIPSize, + }) + } + if value, ok := du.mutation.AddedIPSize(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldIPSize, + }) + } + if du.mutation.IPSizeCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: decision.FieldIPSize, + }) + } if value, ok := du.mutation.Scope(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, @@ -416,13 +556,13 @@ type DecisionUpdateOne struct { mutation *DecisionMutation } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (duo *DecisionUpdateOne) SetCreatedAt(t time.Time) *DecisionUpdateOne { duo.mutation.SetCreatedAt(t) return duo } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (duo *DecisionUpdateOne) SetNillableCreatedAt(t *time.Time) *DecisionUpdateOne { if t != nil { duo.SetCreatedAt(*t) @@ -430,13 +570,13 @@ func (duo *DecisionUpdateOne) SetNillableCreatedAt(t *time.Time) *DecisionUpdate return duo } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (duo *DecisionUpdateOne) SetUpdatedAt(t time.Time) *DecisionUpdateOne { duo.mutation.SetUpdatedAt(t) return duo } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (duo *DecisionUpdateOne) SetNillableUpdatedAt(t *time.Time) *DecisionUpdateOne { if t != nil { duo.SetUpdatedAt(*t) @@ -444,32 +584,32 @@ func (duo *DecisionUpdateOne) SetNillableUpdatedAt(t *time.Time) *DecisionUpdate return duo } -// SetUntil sets the until field. +// SetUntil sets the "until" field. func (duo *DecisionUpdateOne) SetUntil(t time.Time) *DecisionUpdateOne { duo.mutation.SetUntil(t) return duo } -// SetScenario sets the scenario field. +// SetScenario sets the "scenario" field. func (duo *DecisionUpdateOne) SetScenario(s string) *DecisionUpdateOne { duo.mutation.SetScenario(s) return duo } -// SetType sets the type field. +// SetType sets the "type" field. func (duo *DecisionUpdateOne) SetType(s string) *DecisionUpdateOne { duo.mutation.SetType(s) return duo } -// SetStartIP sets the start_ip field. +// SetStartIP sets the "start_ip" field. func (duo *DecisionUpdateOne) SetStartIP(i int64) *DecisionUpdateOne { duo.mutation.ResetStartIP() duo.mutation.SetStartIP(i) return duo } -// SetNillableStartIP sets the start_ip field if the given value is not nil. +// SetNillableStartIP sets the "start_ip" field if the given value is not nil. func (duo *DecisionUpdateOne) SetNillableStartIP(i *int64) *DecisionUpdateOne { if i != nil { duo.SetStartIP(*i) @@ -477,26 +617,26 @@ func (duo *DecisionUpdateOne) SetNillableStartIP(i *int64) *DecisionUpdateOne { return duo } -// AddStartIP adds i to start_ip. +// AddStartIP adds i to the "start_ip" field. func (duo *DecisionUpdateOne) AddStartIP(i int64) *DecisionUpdateOne { duo.mutation.AddStartIP(i) return duo } -// ClearStartIP clears the value of start_ip. +// ClearStartIP clears the value of the "start_ip" field. func (duo *DecisionUpdateOne) ClearStartIP() *DecisionUpdateOne { duo.mutation.ClearStartIP() return duo } -// SetEndIP sets the end_ip field. +// SetEndIP sets the "end_ip" field. func (duo *DecisionUpdateOne) SetEndIP(i int64) *DecisionUpdateOne { duo.mutation.ResetEndIP() duo.mutation.SetEndIP(i) return duo } -// SetNillableEndIP sets the end_ip field if the given value is not nil. +// SetNillableEndIP sets the "end_ip" field if the given value is not nil. func (duo *DecisionUpdateOne) SetNillableEndIP(i *int64) *DecisionUpdateOne { if i != nil { duo.SetEndIP(*i) @@ -504,43 +644,124 @@ func (duo *DecisionUpdateOne) SetNillableEndIP(i *int64) *DecisionUpdateOne { return duo } -// AddEndIP adds i to end_ip. +// AddEndIP adds i to the "end_ip" field. func (duo *DecisionUpdateOne) AddEndIP(i int64) *DecisionUpdateOne { duo.mutation.AddEndIP(i) return duo } -// ClearEndIP clears the value of end_ip. +// ClearEndIP clears the value of the "end_ip" field. func (duo *DecisionUpdateOne) ClearEndIP() *DecisionUpdateOne { duo.mutation.ClearEndIP() return duo } -// SetScope sets the scope field. +// SetStartSuffix sets the "start_suffix" field. +func (duo *DecisionUpdateOne) SetStartSuffix(i int64) *DecisionUpdateOne { + duo.mutation.ResetStartSuffix() + duo.mutation.SetStartSuffix(i) + return duo +} + +// SetNillableStartSuffix sets the "start_suffix" field if the given value is not nil. +func (duo *DecisionUpdateOne) SetNillableStartSuffix(i *int64) *DecisionUpdateOne { + if i != nil { + duo.SetStartSuffix(*i) + } + return duo +} + +// AddStartSuffix adds i to the "start_suffix" field. +func (duo *DecisionUpdateOne) AddStartSuffix(i int64) *DecisionUpdateOne { + duo.mutation.AddStartSuffix(i) + return duo +} + +// ClearStartSuffix clears the value of the "start_suffix" field. +func (duo *DecisionUpdateOne) ClearStartSuffix() *DecisionUpdateOne { + duo.mutation.ClearStartSuffix() + return duo +} + +// SetEndSuffix sets the "end_suffix" field. +func (duo *DecisionUpdateOne) SetEndSuffix(i int64) *DecisionUpdateOne { + duo.mutation.ResetEndSuffix() + duo.mutation.SetEndSuffix(i) + return duo +} + +// SetNillableEndSuffix sets the "end_suffix" field if the given value is not nil. +func (duo *DecisionUpdateOne) SetNillableEndSuffix(i *int64) *DecisionUpdateOne { + if i != nil { + duo.SetEndSuffix(*i) + } + return duo +} + +// AddEndSuffix adds i to the "end_suffix" field. +func (duo *DecisionUpdateOne) AddEndSuffix(i int64) *DecisionUpdateOne { + duo.mutation.AddEndSuffix(i) + return duo +} + +// ClearEndSuffix clears the value of the "end_suffix" field. +func (duo *DecisionUpdateOne) ClearEndSuffix() *DecisionUpdateOne { + duo.mutation.ClearEndSuffix() + return duo +} + +// SetIPSize sets the "ip_size" field. +func (duo *DecisionUpdateOne) SetIPSize(i int64) *DecisionUpdateOne { + duo.mutation.ResetIPSize() + duo.mutation.SetIPSize(i) + return duo +} + +// SetNillableIPSize sets the "ip_size" field if the given value is not nil. +func (duo *DecisionUpdateOne) SetNillableIPSize(i *int64) *DecisionUpdateOne { + if i != nil { + duo.SetIPSize(*i) + } + return duo +} + +// AddIPSize adds i to the "ip_size" field. +func (duo *DecisionUpdateOne) AddIPSize(i int64) *DecisionUpdateOne { + duo.mutation.AddIPSize(i) + return duo +} + +// ClearIPSize clears the value of the "ip_size" field. +func (duo *DecisionUpdateOne) ClearIPSize() *DecisionUpdateOne { + duo.mutation.ClearIPSize() + return duo +} + +// SetScope sets the "scope" field. func (duo *DecisionUpdateOne) SetScope(s string) *DecisionUpdateOne { duo.mutation.SetScope(s) return duo } -// SetValue sets the value field. +// SetValue sets the "value" field. func (duo *DecisionUpdateOne) SetValue(s string) *DecisionUpdateOne { duo.mutation.SetValue(s) return duo } -// SetOrigin sets the origin field. +// SetOrigin sets the "origin" field. func (duo *DecisionUpdateOne) SetOrigin(s string) *DecisionUpdateOne { duo.mutation.SetOrigin(s) return duo } -// SetSimulated sets the simulated field. +// SetSimulated sets the "simulated" field. func (duo *DecisionUpdateOne) SetSimulated(b bool) *DecisionUpdateOne { duo.mutation.SetSimulated(b) return duo } -// SetNillableSimulated sets the simulated field if the given value is not nil. +// SetNillableSimulated sets the "simulated" field if the given value is not nil. func (duo *DecisionUpdateOne) SetNillableSimulated(b *bool) *DecisionUpdateOne { if b != nil { duo.SetSimulated(*b) @@ -548,13 +769,13 @@ func (duo *DecisionUpdateOne) SetNillableSimulated(b *bool) *DecisionUpdateOne { return duo } -// SetOwnerID sets the owner edge to Alert by id. +// SetOwnerID sets the "owner" edge to the Alert entity by ID. func (duo *DecisionUpdateOne) SetOwnerID(id int) *DecisionUpdateOne { duo.mutation.SetOwnerID(id) return duo } -// SetNillableOwnerID sets the owner edge to Alert by id if the given value is not nil. +// SetNillableOwnerID sets the "owner" edge to the Alert entity by ID if the given value is not nil. func (duo *DecisionUpdateOne) SetNillableOwnerID(id *int) *DecisionUpdateOne { if id != nil { duo = duo.SetOwnerID(*id) @@ -562,7 +783,7 @@ func (duo *DecisionUpdateOne) SetNillableOwnerID(id *int) *DecisionUpdateOne { return duo } -// SetOwner sets the owner edge to Alert. +// SetOwner sets the "owner" edge to the Alert entity. func (duo *DecisionUpdateOne) SetOwner(a *Alert) *DecisionUpdateOne { return duo.SetOwnerID(a.ID) } @@ -572,13 +793,13 @@ func (duo *DecisionUpdateOne) Mutation() *DecisionMutation { return duo.mutation } -// ClearOwner clears the "owner" edge to type Alert. +// ClearOwner clears the "owner" edge to the Alert entity. func (duo *DecisionUpdateOne) ClearOwner() *DecisionUpdateOne { duo.mutation.ClearOwner() return duo } -// Save executes the query and returns the updated entity. +// Save executes the query and returns the updated Decision entity. func (duo *DecisionUpdateOne) Save(ctx context.Context) (*Decision, error) { var ( err error @@ -720,6 +941,66 @@ func (duo *DecisionUpdateOne) sqlSave(ctx context.Context) (_node *Decision, err Column: decision.FieldEndIP, }) } + if value, ok := duo.mutation.StartSuffix(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldStartSuffix, + }) + } + if value, ok := duo.mutation.AddedStartSuffix(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldStartSuffix, + }) + } + if duo.mutation.StartSuffixCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: decision.FieldStartSuffix, + }) + } + if value, ok := duo.mutation.EndSuffix(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldEndSuffix, + }) + } + if value, ok := duo.mutation.AddedEndSuffix(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldEndSuffix, + }) + } + if duo.mutation.EndSuffixCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: decision.FieldEndSuffix, + }) + } + if value, ok := duo.mutation.IPSize(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldIPSize, + }) + } + if value, ok := duo.mutation.AddedIPSize(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: decision.FieldIPSize, + }) + } + if duo.mutation.IPSizeCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: decision.FieldIPSize, + }) + } if value, ok := duo.mutation.Scope(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, @@ -785,7 +1066,7 @@ func (duo *DecisionUpdateOne) sqlSave(ctx context.Context) (_node *Decision, err } _node = &Decision{config: duo.config} _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues() + _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, duo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{decision.Label} diff --git a/pkg/database/ent/ent.go b/pkg/database/ent/ent.go index 587180b3c..65e256b24 100644 --- a/pkg/database/ent/ent.go +++ b/pkg/database/ent/ent.go @@ -13,7 +13,7 @@ import ( "github.com/facebook/ent/dialect/sql/sqlgraph" ) -// ent aliases to avoid import conflict in user's code. +// ent aliases to avoid import conflicts in user's code. type ( Op = ent.Op Hook = ent.Hook @@ -164,7 +164,7 @@ func IsNotFound(err error) bool { return errors.As(err, &e) } -// MaskNotFound masks nor found error. +// MaskNotFound masks not found error. func MaskNotFound(err error) error { if IsNotFound(err) { return nil @@ -258,7 +258,7 @@ func isSQLConstraintError(err error) (*ConstraintError, bool) { return nil, false } -// rollback calls to tx.Rollback and wraps the given error with the rollback error if occurred. +// rollback calls tx.Rollback and wraps the given error with the rollback error if present. func rollback(tx dialect.Tx, err error) error { if rerr := tx.Rollback(); rerr != nil { err = fmt.Errorf("%s: %v", err.Error(), rerr) diff --git a/pkg/database/ent/event.go b/pkg/database/ent/event.go index f10f0dfba..22197417c 100644 --- a/pkg/database/ent/event.go +++ b/pkg/database/ent/event.go @@ -55,81 +55,89 @@ func (e EventEdges) OwnerOrErr() (*Alert, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*Event) scanValues() []interface{} { - return []interface{}{ - &sql.NullInt64{}, // id - &sql.NullTime{}, // created_at - &sql.NullTime{}, // updated_at - &sql.NullTime{}, // time - &sql.NullString{}, // serialized - } -} - -// fkValues returns the types for scanning foreign-keys values from sql.Rows. -func (*Event) fkValues() []interface{} { - return []interface{}{ - &sql.NullInt64{}, // alert_events +func (*Event) scanValues(columns []string) ([]interface{}, error) { + values := make([]interface{}, len(columns)) + for i := range columns { + switch columns[i] { + case event.FieldID: + values[i] = &sql.NullInt64{} + case event.FieldSerialized: + values[i] = &sql.NullString{} + case event.FieldCreatedAt, event.FieldUpdatedAt, event.FieldTime: + values[i] = &sql.NullTime{} + case event.ForeignKeys[0]: // alert_events + values[i] = &sql.NullInt64{} + default: + return nil, fmt.Errorf("unexpected column %q for type Event", columns[i]) + } } + return values, nil } // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Event fields. -func (e *Event) assignValues(values ...interface{}) error { - if m, n := len(values), len(event.Columns); m < n { +func (e *Event) 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) } - value, ok := values[0].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - e.ID = int(value.Int64) - values = values[1:] - if value, ok := values[0].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[0]) - } else if value.Valid { - e.CreatedAt = value.Time - } - if value, ok := values[1].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[1]) - } else if value.Valid { - e.UpdatedAt = value.Time - } - if value, ok := values[2].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field time", values[2]) - } else if value.Valid { - e.Time = value.Time - } - if value, ok := values[3].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field serialized", values[3]) - } else if value.Valid { - e.Serialized = value.String - } - values = values[4:] - if len(values) == len(event.ForeignKeys) { - if value, ok := values[0].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for edge-field alert_events", value) - } else if value.Valid { - e.alert_events = new(int) - *e.alert_events = int(value.Int64) + for i := range columns { + switch columns[i] { + case event.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + e.ID = int(value.Int64) + case event.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 { + e.CreatedAt = value.Time + } + case event.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 { + e.UpdatedAt = value.Time + } + case event.FieldTime: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field time", values[i]) + } else if value.Valid { + e.Time = value.Time + } + case event.FieldSerialized: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field serialized", values[i]) + } else if value.Valid { + e.Serialized = value.String + } + case event.ForeignKeys[0]: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for edge-field alert_events", value) + } else if value.Valid { + e.alert_events = new(int) + *e.alert_events = int(value.Int64) + } } } return nil } -// QueryOwner queries the owner edge of the Event. +// QueryOwner queries the "owner" edge of the Event entity. func (e *Event) QueryOwner() *AlertQuery { return (&EventClient{config: e.config}).QueryOwner(e) } // Update returns a builder for updating this Event. -// Note that, you need to call Event.Unwrap() before calling this method, if this Event +// Note that you need to call Event.Unwrap() before calling this method if this Event // was returned from a transaction, and the transaction was committed or rolled back. func (e *Event) Update() *EventUpdateOne { return (&EventClient{config: e.config}).UpdateOne(e) } -// Unwrap unwraps the entity that was returned from a transaction after it was closed, -// so that all next queries will be executed through the driver which created the transaction. +// Unwrap unwraps the Event 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 (e *Event) Unwrap() *Event { tx, ok := e.config.driver.(*txDriver) if !ok { diff --git a/pkg/database/ent/event/event.go b/pkg/database/ent/event/event.go index 9ae9d43e8..85e902ce1 100644 --- a/pkg/database/ent/event/event.go +++ b/pkg/database/ent/event/event.go @@ -64,9 +64,9 @@ func ValidColumn(column string) bool { } var ( - // DefaultCreatedAt holds the default value on creation for the created_at field. + // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the updated_at field. + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. DefaultUpdatedAt func() time.Time // SerializedValidator is a validator for the "serialized" field. It is called by the builders before save. SerializedValidator func(string) error diff --git a/pkg/database/ent/event/where.go b/pkg/database/ent/event/where.go index 8e057d7a3..630aadb06 100644 --- a/pkg/database/ent/event/where.go +++ b/pkg/database/ent/event/where.go @@ -10,7 +10,7 @@ import ( "github.com/facebook/ent/dialect/sql/sqlgraph" ) -// ID filters vertices based on their identifier. +// ID filters vertices based on their ID field. func ID(id int) predicate.Event { return predicate.Event(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldID), id)) @@ -488,7 +488,7 @@ func HasOwnerWith(preds ...predicate.Alert) predicate.Event { }) } -// And groups list of predicates with the AND operator between them. +// And groups predicates with the AND operator between them. func And(predicates ...predicate.Event) predicate.Event { return predicate.Event(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) @@ -499,7 +499,7 @@ func And(predicates ...predicate.Event) predicate.Event { }) } -// Or groups list of predicates with the OR operator between them. +// Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Event) predicate.Event { return predicate.Event(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) diff --git a/pkg/database/ent/event_create.go b/pkg/database/ent/event_create.go index ca8c8153d..56e2b4fd9 100644 --- a/pkg/database/ent/event_create.go +++ b/pkg/database/ent/event_create.go @@ -21,13 +21,13 @@ type EventCreate struct { hooks []Hook } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (ec *EventCreate) SetCreatedAt(t time.Time) *EventCreate { ec.mutation.SetCreatedAt(t) return ec } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (ec *EventCreate) SetNillableCreatedAt(t *time.Time) *EventCreate { if t != nil { ec.SetCreatedAt(*t) @@ -35,13 +35,13 @@ func (ec *EventCreate) SetNillableCreatedAt(t *time.Time) *EventCreate { return ec } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (ec *EventCreate) SetUpdatedAt(t time.Time) *EventCreate { ec.mutation.SetUpdatedAt(t) return ec } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (ec *EventCreate) SetNillableUpdatedAt(t *time.Time) *EventCreate { if t != nil { ec.SetUpdatedAt(*t) @@ -49,25 +49,25 @@ func (ec *EventCreate) SetNillableUpdatedAt(t *time.Time) *EventCreate { return ec } -// SetTime sets the time field. +// SetTime sets the "time" field. func (ec *EventCreate) SetTime(t time.Time) *EventCreate { ec.mutation.SetTime(t) return ec } -// SetSerialized sets the serialized field. +// SetSerialized sets the "serialized" field. func (ec *EventCreate) SetSerialized(s string) *EventCreate { ec.mutation.SetSerialized(s) return ec } -// SetOwnerID sets the owner edge to Alert by id. +// SetOwnerID sets the "owner" edge to the Alert entity by ID. func (ec *EventCreate) SetOwnerID(id int) *EventCreate { ec.mutation.SetOwnerID(id) return ec } -// SetNillableOwnerID sets the owner edge to Alert by id if the given value is not nil. +// SetNillableOwnerID sets the "owner" edge to the Alert entity by ID if the given value is not nil. func (ec *EventCreate) SetNillableOwnerID(id *int) *EventCreate { if id != nil { ec = ec.SetOwnerID(*id) @@ -75,7 +75,7 @@ func (ec *EventCreate) SetNillableOwnerID(id *int) *EventCreate { return ec } -// SetOwner sets the owner edge to Alert. +// SetOwner sets the "owner" edge to the Alert entity. func (ec *EventCreate) SetOwner(a *Alert) *EventCreate { return ec.SetOwnerID(a.ID) } @@ -242,7 +242,7 @@ func (ec *EventCreate) createSpec() (*Event, *sqlgraph.CreateSpec) { return _node, _spec } -// EventCreateBulk is the builder for creating a bulk of Event entities. +// EventCreateBulk is the builder for creating many Event entities in bulk. type EventCreateBulk struct { config builders []*EventCreate @@ -300,7 +300,7 @@ func (ecb *EventCreateBulk) Save(ctx context.Context) ([]*Event, error) { return nodes, nil } -// SaveX calls Save and panics if Save returns an error. +// SaveX is like Save, but panics if an error occurs. func (ecb *EventCreateBulk) SaveX(ctx context.Context) []*Event { v, err := ecb.Save(ctx) if err != nil { diff --git a/pkg/database/ent/event_delete.go b/pkg/database/ent/event_delete.go index 71a7753b8..52df277f1 100644 --- a/pkg/database/ent/event_delete.go +++ b/pkg/database/ent/event_delete.go @@ -16,14 +16,13 @@ import ( // EventDelete is the builder for deleting a Event entity. type EventDelete struct { config - hooks []Hook - mutation *EventMutation - predicates []predicate.Event + hooks []Hook + mutation *EventMutation } -// Where adds a new predicate to the delete builder. +// Where adds a new predicate to the EventDelete builder. func (ed *EventDelete) Where(ps ...predicate.Event) *EventDelete { - ed.predicates = append(ed.predicates, ps...) + ed.mutation.predicates = append(ed.mutation.predicates, ps...) return ed } @@ -75,7 +74,7 @@ func (ed *EventDelete) sqlExec(ctx context.Context) (int, error) { }, }, } - if ps := ed.predicates; len(ps) > 0 { + if ps := ed.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) diff --git a/pkg/database/ent/event_query.go b/pkg/database/ent/event_query.go index 002c3f88c..89254ed4d 100644 --- a/pkg/database/ent/event_query.go +++ b/pkg/database/ent/event_query.go @@ -22,7 +22,7 @@ type EventQuery struct { limit *int offset *int order []OrderFunc - unique []string + fields []string predicates []predicate.Event // eager-loading edges. withOwner *AlertQuery @@ -32,7 +32,7 @@ type EventQuery struct { path func(context.Context) (*sql.Selector, error) } -// Where adds a new predicate for the builder. +// Where adds a new predicate for the EventQuery builder. func (eq *EventQuery) Where(ps ...predicate.Event) *EventQuery { eq.predicates = append(eq.predicates, ps...) return eq @@ -56,7 +56,7 @@ func (eq *EventQuery) Order(o ...OrderFunc) *EventQuery { return eq } -// QueryOwner chains the current query on the owner edge. +// QueryOwner chains the current query on the "owner" edge. func (eq *EventQuery) QueryOwner() *AlertQuery { query := &AlertQuery{config: eq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { @@ -78,7 +78,8 @@ func (eq *EventQuery) QueryOwner() *AlertQuery { return query } -// First returns the first Event entity in the query. Returns *NotFoundError when no event was found. +// First returns the first Event entity from the query. +// Returns a *NotFoundError when no Event was found. func (eq *EventQuery) First(ctx context.Context) (*Event, error) { nodes, err := eq.Limit(1).All(ctx) if err != nil { @@ -99,7 +100,8 @@ func (eq *EventQuery) FirstX(ctx context.Context) *Event { return node } -// FirstID returns the first Event id in the query. Returns *NotFoundError when no id was found. +// FirstID returns the first Event ID from the query. +// Returns a *NotFoundError when no Event ID was found. func (eq *EventQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int if ids, err = eq.Limit(1).IDs(ctx); err != nil { @@ -112,8 +114,8 @@ func (eq *EventQuery) FirstID(ctx context.Context) (id int, err error) { return ids[0], nil } -// FirstXID is like FirstID, but panics if an error occurs. -func (eq *EventQuery) FirstXID(ctx context.Context) int { +// FirstIDX is like FirstID, but panics if an error occurs. +func (eq *EventQuery) FirstIDX(ctx context.Context) int { id, err := eq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -121,7 +123,9 @@ func (eq *EventQuery) FirstXID(ctx context.Context) int { return id } -// Only returns the only Event entity in the query, returns an error if not exactly one entity was returned. +// Only returns a single Event entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when exactly one Event entity is not found. +// Returns a *NotFoundError when no Event entities are found. func (eq *EventQuery) Only(ctx context.Context) (*Event, error) { nodes, err := eq.Limit(2).All(ctx) if err != nil { @@ -146,7 +150,9 @@ func (eq *EventQuery) OnlyX(ctx context.Context) *Event { return node } -// OnlyID returns the only Event id in the query, returns an error if not exactly one id was returned. +// OnlyID is like Only, but returns the only Event ID in the query. +// Returns a *NotSingularError when exactly one Event ID is not found. +// Returns a *NotFoundError when no entities are found. func (eq *EventQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int if ids, err = eq.Limit(2).IDs(ctx); err != nil { @@ -189,7 +195,7 @@ func (eq *EventQuery) AllX(ctx context.Context) []*Event { return nodes } -// IDs executes the query and returns a list of Event ids. +// IDs executes the query and returns a list of Event IDs. func (eq *EventQuery) IDs(ctx context.Context) ([]int, error) { var ids []int if err := eq.Select(event.FieldID).Scan(ctx, &ids); err != nil { @@ -241,24 +247,27 @@ func (eq *EventQuery) ExistX(ctx context.Context) bool { return exist } -// Clone returns a duplicate of the query builder, including all associated steps. It can be +// Clone returns a duplicate of the EventQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. func (eq *EventQuery) Clone() *EventQuery { + if eq == nil { + return nil + } return &EventQuery{ config: eq.config, limit: eq.limit, offset: eq.offset, order: append([]OrderFunc{}, eq.order...), - unique: append([]string{}, eq.unique...), predicates: append([]predicate.Event{}, eq.predicates...), + withOwner: eq.withOwner.Clone(), // clone intermediate query. sql: eq.sql.Clone(), path: eq.path, } } -// WithOwner tells the query-builder to eager-loads the nodes that are connected to -// the "owner" edge. The optional arguments used to configure the query builder of the edge. +// WithOwner tells the query-builder to eager-load the nodes that are connected to +// the "owner" edge. The optional arguments are used to configure the query builder of the edge. func (eq *EventQuery) WithOwner(opts ...func(*AlertQuery)) *EventQuery { query := &AlertQuery{config: eq.config} for _, opt := range opts { @@ -268,7 +277,7 @@ func (eq *EventQuery) WithOwner(opts ...func(*AlertQuery)) *EventQuery { return eq } -// GroupBy used to group vertices by one or more fields/columns. +// GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // // Example: @@ -295,7 +304,8 @@ func (eq *EventQuery) GroupBy(field string, fields ...string) *EventGroupBy { return group } -// Select one or more fields from the given query. +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. // // Example: // @@ -308,18 +318,16 @@ func (eq *EventQuery) GroupBy(field string, fields ...string) *EventGroupBy { // Scan(ctx, &v) // func (eq *EventQuery) Select(field string, fields ...string) *EventSelect { - selector := &EventSelect{config: eq.config} - selector.fields = append([]string{field}, fields...) - selector.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := eq.prepareQuery(ctx); err != nil { - return nil, err - } - return eq.sqlQuery(), nil - } - return selector + eq.fields = append([]string{field}, fields...) + return &EventSelect{EventQuery: eq} } func (eq *EventQuery) prepareQuery(ctx context.Context) error { + for _, f := range eq.fields { + if !event.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } if eq.path != nil { prev, err := eq.path(ctx) if err != nil { @@ -345,22 +353,18 @@ func (eq *EventQuery) sqlAll(ctx context.Context) ([]*Event, error) { if withFKs { _spec.Node.Columns = append(_spec.Node.Columns, event.ForeignKeys...) } - _spec.ScanValues = func() []interface{} { + _spec.ScanValues = func(columns []string) ([]interface{}, error) { node := &Event{config: eq.config} nodes = append(nodes, node) - values := node.scanValues() - if withFKs { - values = append(values, node.fkValues()...) - } - return values + return node.scanValues(columns) } - _spec.Assign = func(values ...interface{}) error { + _spec.Assign = func(columns []string, values []interface{}) error { if len(nodes) == 0 { return fmt.Errorf("ent: Assign called without calling ScanValues") } node := nodes[len(nodes)-1] node.Edges.loadedTypes = loadedTypes - return node.assignValues(values...) + return node.assignValues(columns, values) } if err := sqlgraph.QueryNodes(ctx, eq.driver, _spec); err != nil { return nil, err @@ -423,6 +427,15 @@ func (eq *EventQuery) querySpec() *sqlgraph.QuerySpec { From: eq.sql, Unique: true, } + if fields := eq.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, event.FieldID) + for i := range fields { + if fields[i] != event.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } if ps := eq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -471,7 +484,7 @@ func (eq *EventQuery) sqlQuery() *sql.Selector { return selector } -// EventGroupBy is the builder for group-by Event entities. +// EventGroupBy is the group-by builder for Event entities. type EventGroupBy struct { config fields []string @@ -487,7 +500,7 @@ func (egb *EventGroupBy) Aggregate(fns ...AggregateFunc) *EventGroupBy { return egb } -// Scan applies the group-by query and scan the result into the given value. +// Scan applies the group-by query and scans the result into the given value. func (egb *EventGroupBy) Scan(ctx context.Context, v interface{}) error { query, err := egb.path(ctx) if err != nil { @@ -504,7 +517,8 @@ func (egb *EventGroupBy) ScanX(ctx context.Context, v interface{}) { } } -// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field. +// Strings returns list of strings from group-by. +// It is only allowed when executing a group-by query with one field. func (egb *EventGroupBy) Strings(ctx context.Context) ([]string, error) { if len(egb.fields) > 1 { return nil, errors.New("ent: EventGroupBy.Strings is not achievable when grouping more than 1 field") @@ -525,7 +539,8 @@ func (egb *EventGroupBy) StringsX(ctx context.Context) []string { return v } -// String returns a single string from group-by. It is only allowed when querying group-by with one field. +// String returns a single string from a group-by query. +// It is only allowed when executing a group-by query with one field. func (egb *EventGroupBy) String(ctx context.Context) (_ string, err error) { var v []string if v, err = egb.Strings(ctx); err != nil { @@ -551,7 +566,8 @@ func (egb *EventGroupBy) StringX(ctx context.Context) string { return v } -// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field. +// Ints returns list of ints from group-by. +// It is only allowed when executing a group-by query with one field. func (egb *EventGroupBy) Ints(ctx context.Context) ([]int, error) { if len(egb.fields) > 1 { return nil, errors.New("ent: EventGroupBy.Ints is not achievable when grouping more than 1 field") @@ -572,7 +588,8 @@ func (egb *EventGroupBy) IntsX(ctx context.Context) []int { return v } -// Int returns a single int from group-by. It is only allowed when querying group-by with one field. +// Int returns a single int from a group-by query. +// It is only allowed when executing a group-by query with one field. func (egb *EventGroupBy) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = egb.Ints(ctx); err != nil { @@ -598,7 +615,8 @@ func (egb *EventGroupBy) IntX(ctx context.Context) int { return v } -// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field. +// Float64s returns list of float64s from group-by. +// It is only allowed when executing a group-by query with one field. func (egb *EventGroupBy) Float64s(ctx context.Context) ([]float64, error) { if len(egb.fields) > 1 { return nil, errors.New("ent: EventGroupBy.Float64s is not achievable when grouping more than 1 field") @@ -619,7 +637,8 @@ func (egb *EventGroupBy) Float64sX(ctx context.Context) []float64 { return v } -// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field. +// Float64 returns a single float64 from a group-by query. +// It is only allowed when executing a group-by query with one field. func (egb *EventGroupBy) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = egb.Float64s(ctx); err != nil { @@ -645,7 +664,8 @@ func (egb *EventGroupBy) Float64X(ctx context.Context) float64 { return v } -// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field. +// Bools returns list of bools from group-by. +// It is only allowed when executing a group-by query with one field. func (egb *EventGroupBy) Bools(ctx context.Context) ([]bool, error) { if len(egb.fields) > 1 { return nil, errors.New("ent: EventGroupBy.Bools is not achievable when grouping more than 1 field") @@ -666,7 +686,8 @@ func (egb *EventGroupBy) BoolsX(ctx context.Context) []bool { return v } -// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field. +// Bool returns a single bool from a group-by query. +// It is only allowed when executing a group-by query with one field. func (egb *EventGroupBy) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = egb.Bools(ctx); err != nil { @@ -721,22 +742,19 @@ func (egb *EventGroupBy) sqlQuery() *sql.Selector { return selector.Select(columns...).GroupBy(egb.fields...) } -// EventSelect is the builder for select fields of Event entities. +// EventSelect is the builder for selecting fields of Event entities. type EventSelect struct { - config - fields []string + *EventQuery // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + sql *sql.Selector } -// Scan applies the selector query and scan the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (es *EventSelect) Scan(ctx context.Context, v interface{}) error { - query, err := es.path(ctx) - if err != nil { + if err := es.prepareQuery(ctx); err != nil { return err } - es.sql = query + es.sql = es.EventQuery.sqlQuery() return es.sqlScan(ctx, v) } @@ -747,7 +765,7 @@ func (es *EventSelect) ScanX(ctx context.Context, v interface{}) { } } -// Strings returns list of strings from selector. It is only allowed when selecting one field. +// Strings returns list of strings from a selector. It is only allowed when selecting one field. func (es *EventSelect) Strings(ctx context.Context) ([]string, error) { if len(es.fields) > 1 { return nil, errors.New("ent: EventSelect.Strings is not achievable when selecting more than 1 field") @@ -768,7 +786,7 @@ func (es *EventSelect) StringsX(ctx context.Context) []string { return v } -// String returns a single string from selector. It is only allowed when selecting one field. +// String returns a single string from a selector. It is only allowed when selecting one field. func (es *EventSelect) String(ctx context.Context) (_ string, err error) { var v []string if v, err = es.Strings(ctx); err != nil { @@ -794,7 +812,7 @@ func (es *EventSelect) StringX(ctx context.Context) string { return v } -// Ints returns list of ints from selector. It is only allowed when selecting one field. +// Ints returns list of ints from a selector. It is only allowed when selecting one field. func (es *EventSelect) Ints(ctx context.Context) ([]int, error) { if len(es.fields) > 1 { return nil, errors.New("ent: EventSelect.Ints is not achievable when selecting more than 1 field") @@ -815,7 +833,7 @@ func (es *EventSelect) IntsX(ctx context.Context) []int { return v } -// Int returns a single int from selector. It is only allowed when selecting one field. +// Int returns a single int from a selector. It is only allowed when selecting one field. func (es *EventSelect) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = es.Ints(ctx); err != nil { @@ -841,7 +859,7 @@ func (es *EventSelect) IntX(ctx context.Context) int { return v } -// Float64s returns list of float64s from selector. It is only allowed when selecting one field. +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. func (es *EventSelect) Float64s(ctx context.Context) ([]float64, error) { if len(es.fields) > 1 { return nil, errors.New("ent: EventSelect.Float64s is not achievable when selecting more than 1 field") @@ -862,7 +880,7 @@ func (es *EventSelect) Float64sX(ctx context.Context) []float64 { return v } -// Float64 returns a single float64 from selector. It is only allowed when selecting one field. +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. func (es *EventSelect) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = es.Float64s(ctx); err != nil { @@ -888,7 +906,7 @@ func (es *EventSelect) Float64X(ctx context.Context) float64 { return v } -// Bools returns list of bools from selector. It is only allowed when selecting one field. +// Bools returns list of bools from a selector. It is only allowed when selecting one field. func (es *EventSelect) Bools(ctx context.Context) ([]bool, error) { if len(es.fields) > 1 { return nil, errors.New("ent: EventSelect.Bools is not achievable when selecting more than 1 field") @@ -909,7 +927,7 @@ func (es *EventSelect) BoolsX(ctx context.Context) []bool { return v } -// Bool returns a single bool from selector. It is only allowed when selecting one field. +// Bool returns a single bool from a selector. It is only allowed when selecting one field. func (es *EventSelect) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = es.Bools(ctx); err != nil { @@ -936,11 +954,6 @@ func (es *EventSelect) BoolX(ctx context.Context) bool { } func (es *EventSelect) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range es.fields { - if !event.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for selection", f)} - } - } rows := &sql.Rows{} query, args := es.sqlQuery().Query() if err := es.driver.Query(ctx, query, args, rows); err != nil { diff --git a/pkg/database/ent/event_update.go b/pkg/database/ent/event_update.go index 5ebc11678..3e0182bd3 100644 --- a/pkg/database/ent/event_update.go +++ b/pkg/database/ent/event_update.go @@ -18,24 +18,23 @@ import ( // EventUpdate is the builder for updating Event entities. type EventUpdate struct { config - hooks []Hook - mutation *EventMutation - predicates []predicate.Event + hooks []Hook + mutation *EventMutation } -// Where adds a new predicate for the builder. +// Where adds a new predicate for the EventUpdate builder. func (eu *EventUpdate) Where(ps ...predicate.Event) *EventUpdate { - eu.predicates = append(eu.predicates, ps...) + eu.mutation.predicates = append(eu.mutation.predicates, ps...) return eu } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (eu *EventUpdate) SetCreatedAt(t time.Time) *EventUpdate { eu.mutation.SetCreatedAt(t) return eu } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (eu *EventUpdate) SetNillableCreatedAt(t *time.Time) *EventUpdate { if t != nil { eu.SetCreatedAt(*t) @@ -43,13 +42,13 @@ func (eu *EventUpdate) SetNillableCreatedAt(t *time.Time) *EventUpdate { return eu } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (eu *EventUpdate) SetUpdatedAt(t time.Time) *EventUpdate { eu.mutation.SetUpdatedAt(t) return eu } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (eu *EventUpdate) SetNillableUpdatedAt(t *time.Time) *EventUpdate { if t != nil { eu.SetUpdatedAt(*t) @@ -57,25 +56,25 @@ func (eu *EventUpdate) SetNillableUpdatedAt(t *time.Time) *EventUpdate { return eu } -// SetTime sets the time field. +// SetTime sets the "time" field. func (eu *EventUpdate) SetTime(t time.Time) *EventUpdate { eu.mutation.SetTime(t) return eu } -// SetSerialized sets the serialized field. +// SetSerialized sets the "serialized" field. func (eu *EventUpdate) SetSerialized(s string) *EventUpdate { eu.mutation.SetSerialized(s) return eu } -// SetOwnerID sets the owner edge to Alert by id. +// SetOwnerID sets the "owner" edge to the Alert entity by ID. func (eu *EventUpdate) SetOwnerID(id int) *EventUpdate { eu.mutation.SetOwnerID(id) return eu } -// SetNillableOwnerID sets the owner edge to Alert by id if the given value is not nil. +// SetNillableOwnerID sets the "owner" edge to the Alert entity by ID if the given value is not nil. func (eu *EventUpdate) SetNillableOwnerID(id *int) *EventUpdate { if id != nil { eu = eu.SetOwnerID(*id) @@ -83,7 +82,7 @@ func (eu *EventUpdate) SetNillableOwnerID(id *int) *EventUpdate { return eu } -// SetOwner sets the owner edge to Alert. +// SetOwner sets the "owner" edge to the Alert entity. func (eu *EventUpdate) SetOwner(a *Alert) *EventUpdate { return eu.SetOwnerID(a.ID) } @@ -93,13 +92,13 @@ func (eu *EventUpdate) Mutation() *EventMutation { return eu.mutation } -// ClearOwner clears the "owner" edge to type Alert. +// ClearOwner clears the "owner" edge to the Alert entity. func (eu *EventUpdate) ClearOwner() *EventUpdate { eu.mutation.ClearOwner() return eu } -// Save executes the query and returns the number of rows/vertices matched by this operation. +// Save executes the query and returns the number of nodes affected by the update operation. func (eu *EventUpdate) Save(ctx context.Context) (int, error) { var ( err error @@ -177,7 +176,7 @@ func (eu *EventUpdate) sqlSave(ctx context.Context) (n int, err error) { }, }, } - if ps := eu.predicates; len(ps) > 0 { + if ps := eu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) @@ -265,13 +264,13 @@ type EventUpdateOne struct { mutation *EventMutation } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (euo *EventUpdateOne) SetCreatedAt(t time.Time) *EventUpdateOne { euo.mutation.SetCreatedAt(t) return euo } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (euo *EventUpdateOne) SetNillableCreatedAt(t *time.Time) *EventUpdateOne { if t != nil { euo.SetCreatedAt(*t) @@ -279,13 +278,13 @@ func (euo *EventUpdateOne) SetNillableCreatedAt(t *time.Time) *EventUpdateOne { return euo } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (euo *EventUpdateOne) SetUpdatedAt(t time.Time) *EventUpdateOne { euo.mutation.SetUpdatedAt(t) return euo } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (euo *EventUpdateOne) SetNillableUpdatedAt(t *time.Time) *EventUpdateOne { if t != nil { euo.SetUpdatedAt(*t) @@ -293,25 +292,25 @@ func (euo *EventUpdateOne) SetNillableUpdatedAt(t *time.Time) *EventUpdateOne { return euo } -// SetTime sets the time field. +// SetTime sets the "time" field. func (euo *EventUpdateOne) SetTime(t time.Time) *EventUpdateOne { euo.mutation.SetTime(t) return euo } -// SetSerialized sets the serialized field. +// SetSerialized sets the "serialized" field. func (euo *EventUpdateOne) SetSerialized(s string) *EventUpdateOne { euo.mutation.SetSerialized(s) return euo } -// SetOwnerID sets the owner edge to Alert by id. +// SetOwnerID sets the "owner" edge to the Alert entity by ID. func (euo *EventUpdateOne) SetOwnerID(id int) *EventUpdateOne { euo.mutation.SetOwnerID(id) return euo } -// SetNillableOwnerID sets the owner edge to Alert by id if the given value is not nil. +// SetNillableOwnerID sets the "owner" edge to the Alert entity by ID if the given value is not nil. func (euo *EventUpdateOne) SetNillableOwnerID(id *int) *EventUpdateOne { if id != nil { euo = euo.SetOwnerID(*id) @@ -319,7 +318,7 @@ func (euo *EventUpdateOne) SetNillableOwnerID(id *int) *EventUpdateOne { return euo } -// SetOwner sets the owner edge to Alert. +// SetOwner sets the "owner" edge to the Alert entity. func (euo *EventUpdateOne) SetOwner(a *Alert) *EventUpdateOne { return euo.SetOwnerID(a.ID) } @@ -329,13 +328,13 @@ func (euo *EventUpdateOne) Mutation() *EventMutation { return euo.mutation } -// ClearOwner clears the "owner" edge to type Alert. +// ClearOwner clears the "owner" edge to the Alert entity. func (euo *EventUpdateOne) ClearOwner() *EventUpdateOne { euo.mutation.ClearOwner() return euo } -// Save executes the query and returns the updated entity. +// Save executes the query and returns the updated Event entity. func (euo *EventUpdateOne) Save(ctx context.Context) (*Event, error) { var ( err error @@ -483,7 +482,7 @@ func (euo *EventUpdateOne) sqlSave(ctx context.Context) (_node *Event, err error } _node = &Event{config: euo.config} _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues() + _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, euo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{event.Label} diff --git a/pkg/database/ent/hook/hook.go b/pkg/database/ent/hook/hook.go index 964665d4c..ad5a2aec7 100644 --- a/pkg/database/ent/hook/hook.go +++ b/pkg/database/ent/hook/hook.go @@ -210,6 +210,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -219,11 +228,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/pkg/database/ent/machine.go b/pkg/database/ent/machine.go index 1efb9386f..2facfecfb 100644 --- a/pkg/database/ent/machine.go +++ b/pkg/database/ent/machine.go @@ -58,95 +58,112 @@ func (e MachineEdges) AlertsOrErr() ([]*Alert, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*Machine) scanValues() []interface{} { - return []interface{}{ - &sql.NullInt64{}, // id - &sql.NullTime{}, // created_at - &sql.NullTime{}, // updated_at - &sql.NullString{}, // machineId - &sql.NullString{}, // password - &sql.NullString{}, // ipAddress - &sql.NullString{}, // scenarios - &sql.NullString{}, // version - &sql.NullBool{}, // isValidated - &sql.NullString{}, // status +func (*Machine) scanValues(columns []string) ([]interface{}, error) { + values := make([]interface{}, len(columns)) + for i := range columns { + switch columns[i] { + case machine.FieldIsValidated: + values[i] = &sql.NullBool{} + case machine.FieldID: + values[i] = &sql.NullInt64{} + case machine.FieldMachineId, machine.FieldPassword, machine.FieldIpAddress, machine.FieldScenarios, machine.FieldVersion, machine.FieldStatus: + values[i] = &sql.NullString{} + case machine.FieldCreatedAt, machine.FieldUpdatedAt: + values[i] = &sql.NullTime{} + default: + return nil, fmt.Errorf("unexpected column %q for type Machine", columns[i]) + } } + return values, nil } // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Machine fields. -func (m *Machine) assignValues(values ...interface{}) error { - if m, n := len(values), len(machine.Columns); m < n { +func (m *Machine) 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) } - value, ok := values[0].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - m.ID = int(value.Int64) - values = values[1:] - if value, ok := values[0].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[0]) - } else if value.Valid { - m.CreatedAt = value.Time - } - if value, ok := values[1].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[1]) - } else if value.Valid { - m.UpdatedAt = value.Time - } - if value, ok := values[2].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field machineId", values[2]) - } else if value.Valid { - m.MachineId = value.String - } - if value, ok := values[3].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field password", values[3]) - } else if value.Valid { - m.Password = value.String - } - if value, ok := values[4].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field ipAddress", values[4]) - } else if value.Valid { - m.IpAddress = value.String - } - if value, ok := values[5].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field scenarios", values[5]) - } else if value.Valid { - m.Scenarios = value.String - } - if value, ok := values[6].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field version", values[6]) - } else if value.Valid { - m.Version = value.String - } - if value, ok := values[7].(*sql.NullBool); !ok { - return fmt.Errorf("unexpected type %T for field isValidated", values[7]) - } else if value.Valid { - m.IsValidated = value.Bool - } - if value, ok := values[8].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field status", values[8]) - } else if value.Valid { - m.Status = value.String + for i := range columns { + switch columns[i] { + case machine.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + m.ID = int(value.Int64) + case machine.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 { + m.CreatedAt = value.Time + } + case machine.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 { + m.UpdatedAt = value.Time + } + case machine.FieldMachineId: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field machineId", values[i]) + } else if value.Valid { + m.MachineId = value.String + } + case machine.FieldPassword: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field password", values[i]) + } else if value.Valid { + m.Password = value.String + } + case machine.FieldIpAddress: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field ipAddress", values[i]) + } else if value.Valid { + m.IpAddress = value.String + } + case machine.FieldScenarios: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field scenarios", values[i]) + } else if value.Valid { + m.Scenarios = value.String + } + case machine.FieldVersion: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field version", values[i]) + } else if value.Valid { + m.Version = value.String + } + case machine.FieldIsValidated: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field isValidated", values[i]) + } else if value.Valid { + m.IsValidated = value.Bool + } + case machine.FieldStatus: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field status", values[i]) + } else if value.Valid { + m.Status = value.String + } + } } return nil } -// QueryAlerts queries the alerts edge of the Machine. +// QueryAlerts queries the "alerts" edge of the Machine entity. func (m *Machine) QueryAlerts() *AlertQuery { return (&MachineClient{config: m.config}).QueryAlerts(m) } // Update returns a builder for updating this Machine. -// Note that, you need to call Machine.Unwrap() before calling this method, if this Machine +// Note that you need to call Machine.Unwrap() before calling this method if this Machine // was returned from a transaction, and the transaction was committed or rolled back. func (m *Machine) Update() *MachineUpdateOne { return (&MachineClient{config: m.config}).UpdateOne(m) } -// Unwrap unwraps the entity that was returned from a transaction after it was closed, -// so that all next queries will be executed through the driver which created the transaction. +// Unwrap unwraps the Machine 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 (m *Machine) Unwrap() *Machine { tx, ok := m.config.driver.(*txDriver) if !ok { diff --git a/pkg/database/ent/machine/machine.go b/pkg/database/ent/machine/machine.go index 472df83cc..1d984de8b 100644 --- a/pkg/database/ent/machine/machine.go +++ b/pkg/database/ent/machine/machine.go @@ -69,12 +69,12 @@ func ValidColumn(column string) bool { } var ( - // DefaultCreatedAt holds the default value on creation for the created_at field. + // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the updated_at field. + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. DefaultUpdatedAt func() time.Time // ScenariosValidator is a validator for the "scenarios" field. It is called by the builders before save. ScenariosValidator func(string) error - // DefaultIsValidated holds the default value on creation for the isValidated field. + // DefaultIsValidated holds the default value on creation for the "isValidated" field. DefaultIsValidated bool ) diff --git a/pkg/database/ent/machine/where.go b/pkg/database/ent/machine/where.go index e4533e9f0..a065f2307 100644 --- a/pkg/database/ent/machine/where.go +++ b/pkg/database/ent/machine/where.go @@ -10,7 +10,7 @@ import ( "github.com/facebook/ent/dialect/sql/sqlgraph" ) -// ID filters vertices based on their identifier. +// ID filters vertices based on their ID field. func ID(id int) predicate.Machine { return predicate.Machine(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldID), id)) @@ -1058,7 +1058,7 @@ func HasAlertsWith(preds ...predicate.Alert) predicate.Machine { }) } -// And groups list of predicates with the AND operator between them. +// And groups predicates with the AND operator between them. func And(predicates ...predicate.Machine) predicate.Machine { return predicate.Machine(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) @@ -1069,7 +1069,7 @@ func And(predicates ...predicate.Machine) predicate.Machine { }) } -// Or groups list of predicates with the OR operator between them. +// Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Machine) predicate.Machine { return predicate.Machine(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) diff --git a/pkg/database/ent/machine_create.go b/pkg/database/ent/machine_create.go index e81185109..c7c9563e1 100644 --- a/pkg/database/ent/machine_create.go +++ b/pkg/database/ent/machine_create.go @@ -21,13 +21,13 @@ type MachineCreate struct { hooks []Hook } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (mc *MachineCreate) SetCreatedAt(t time.Time) *MachineCreate { mc.mutation.SetCreatedAt(t) return mc } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (mc *MachineCreate) SetNillableCreatedAt(t *time.Time) *MachineCreate { if t != nil { mc.SetCreatedAt(*t) @@ -35,13 +35,13 @@ func (mc *MachineCreate) SetNillableCreatedAt(t *time.Time) *MachineCreate { return mc } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (mc *MachineCreate) SetUpdatedAt(t time.Time) *MachineCreate { mc.mutation.SetUpdatedAt(t) return mc } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (mc *MachineCreate) SetNillableUpdatedAt(t *time.Time) *MachineCreate { if t != nil { mc.SetUpdatedAt(*t) @@ -49,31 +49,31 @@ func (mc *MachineCreate) SetNillableUpdatedAt(t *time.Time) *MachineCreate { return mc } -// SetMachineId sets the machineId field. +// SetMachineId sets the "machineId" field. func (mc *MachineCreate) SetMachineId(s string) *MachineCreate { mc.mutation.SetMachineId(s) return mc } -// SetPassword sets the password field. +// SetPassword sets the "password" field. func (mc *MachineCreate) SetPassword(s string) *MachineCreate { mc.mutation.SetPassword(s) return mc } -// SetIpAddress sets the ipAddress field. +// SetIpAddress sets the "ipAddress" field. func (mc *MachineCreate) SetIpAddress(s string) *MachineCreate { mc.mutation.SetIpAddress(s) return mc } -// SetScenarios sets the scenarios field. +// SetScenarios sets the "scenarios" field. func (mc *MachineCreate) SetScenarios(s string) *MachineCreate { mc.mutation.SetScenarios(s) return mc } -// SetNillableScenarios sets the scenarios field if the given value is not nil. +// SetNillableScenarios sets the "scenarios" field if the given value is not nil. func (mc *MachineCreate) SetNillableScenarios(s *string) *MachineCreate { if s != nil { mc.SetScenarios(*s) @@ -81,13 +81,13 @@ func (mc *MachineCreate) SetNillableScenarios(s *string) *MachineCreate { return mc } -// SetVersion sets the version field. +// SetVersion sets the "version" field. func (mc *MachineCreate) SetVersion(s string) *MachineCreate { mc.mutation.SetVersion(s) return mc } -// SetNillableVersion sets the version field if the given value is not nil. +// SetNillableVersion sets the "version" field if the given value is not nil. func (mc *MachineCreate) SetNillableVersion(s *string) *MachineCreate { if s != nil { mc.SetVersion(*s) @@ -95,13 +95,13 @@ func (mc *MachineCreate) SetNillableVersion(s *string) *MachineCreate { return mc } -// SetIsValidated sets the isValidated field. +// SetIsValidated sets the "isValidated" field. func (mc *MachineCreate) SetIsValidated(b bool) *MachineCreate { mc.mutation.SetIsValidated(b) return mc } -// SetNillableIsValidated sets the isValidated field if the given value is not nil. +// SetNillableIsValidated sets the "isValidated" field if the given value is not nil. func (mc *MachineCreate) SetNillableIsValidated(b *bool) *MachineCreate { if b != nil { mc.SetIsValidated(*b) @@ -109,13 +109,13 @@ func (mc *MachineCreate) SetNillableIsValidated(b *bool) *MachineCreate { return mc } -// SetStatus sets the status field. +// SetStatus sets the "status" field. func (mc *MachineCreate) SetStatus(s string) *MachineCreate { mc.mutation.SetStatus(s) return mc } -// SetNillableStatus sets the status field if the given value is not nil. +// SetNillableStatus sets the "status" field if the given value is not nil. func (mc *MachineCreate) SetNillableStatus(s *string) *MachineCreate { if s != nil { mc.SetStatus(*s) @@ -123,13 +123,13 @@ func (mc *MachineCreate) SetNillableStatus(s *string) *MachineCreate { return mc } -// AddAlertIDs adds the alerts edge to Alert by ids. +// AddAlertIDs adds the "alerts" edge to the Alert entity by IDs. func (mc *MachineCreate) AddAlertIDs(ids ...int) *MachineCreate { mc.mutation.AddAlertIDs(ids...) return mc } -// AddAlerts adds the alerts edges to Alert. +// AddAlerts adds the "alerts" edges to the Alert entity. func (mc *MachineCreate) AddAlerts(a ...*Alert) *MachineCreate { ids := make([]int, len(a)) for i := range a { @@ -350,7 +350,7 @@ func (mc *MachineCreate) createSpec() (*Machine, *sqlgraph.CreateSpec) { return _node, _spec } -// MachineCreateBulk is the builder for creating a bulk of Machine entities. +// MachineCreateBulk is the builder for creating many Machine entities in bulk. type MachineCreateBulk struct { config builders []*MachineCreate @@ -408,7 +408,7 @@ func (mcb *MachineCreateBulk) Save(ctx context.Context) ([]*Machine, error) { return nodes, nil } -// SaveX calls Save and panics if Save returns an error. +// SaveX is like Save, but panics if an error occurs. func (mcb *MachineCreateBulk) SaveX(ctx context.Context) []*Machine { v, err := mcb.Save(ctx) if err != nil { diff --git a/pkg/database/ent/machine_delete.go b/pkg/database/ent/machine_delete.go index ecd2a79f1..3ee7cdd5e 100644 --- a/pkg/database/ent/machine_delete.go +++ b/pkg/database/ent/machine_delete.go @@ -16,14 +16,13 @@ import ( // MachineDelete is the builder for deleting a Machine entity. type MachineDelete struct { config - hooks []Hook - mutation *MachineMutation - predicates []predicate.Machine + hooks []Hook + mutation *MachineMutation } -// Where adds a new predicate to the delete builder. +// Where adds a new predicate to the MachineDelete builder. func (md *MachineDelete) Where(ps ...predicate.Machine) *MachineDelete { - md.predicates = append(md.predicates, ps...) + md.mutation.predicates = append(md.mutation.predicates, ps...) return md } @@ -75,7 +74,7 @@ func (md *MachineDelete) sqlExec(ctx context.Context) (int, error) { }, }, } - if ps := md.predicates; len(ps) > 0 { + if ps := md.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) diff --git a/pkg/database/ent/machine_query.go b/pkg/database/ent/machine_query.go index 96d950194..38b5a891f 100644 --- a/pkg/database/ent/machine_query.go +++ b/pkg/database/ent/machine_query.go @@ -23,7 +23,7 @@ type MachineQuery struct { limit *int offset *int order []OrderFunc - unique []string + fields []string predicates []predicate.Machine // eager-loading edges. withAlerts *AlertQuery @@ -32,7 +32,7 @@ type MachineQuery struct { path func(context.Context) (*sql.Selector, error) } -// Where adds a new predicate for the builder. +// Where adds a new predicate for the MachineQuery builder. func (mq *MachineQuery) Where(ps ...predicate.Machine) *MachineQuery { mq.predicates = append(mq.predicates, ps...) return mq @@ -56,7 +56,7 @@ func (mq *MachineQuery) Order(o ...OrderFunc) *MachineQuery { return mq } -// QueryAlerts chains the current query on the alerts edge. +// QueryAlerts chains the current query on the "alerts" edge. func (mq *MachineQuery) QueryAlerts() *AlertQuery { query := &AlertQuery{config: mq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { @@ -78,7 +78,8 @@ func (mq *MachineQuery) QueryAlerts() *AlertQuery { return query } -// First returns the first Machine entity in the query. Returns *NotFoundError when no machine was found. +// First returns the first Machine entity from the query. +// Returns a *NotFoundError when no Machine was found. func (mq *MachineQuery) First(ctx context.Context) (*Machine, error) { nodes, err := mq.Limit(1).All(ctx) if err != nil { @@ -99,7 +100,8 @@ func (mq *MachineQuery) FirstX(ctx context.Context) *Machine { return node } -// FirstID returns the first Machine id in the query. Returns *NotFoundError when no id was found. +// FirstID returns the first Machine ID from the query. +// Returns a *NotFoundError when no Machine ID was found. func (mq *MachineQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int if ids, err = mq.Limit(1).IDs(ctx); err != nil { @@ -112,8 +114,8 @@ func (mq *MachineQuery) FirstID(ctx context.Context) (id int, err error) { return ids[0], nil } -// FirstXID is like FirstID, but panics if an error occurs. -func (mq *MachineQuery) FirstXID(ctx context.Context) int { +// FirstIDX is like FirstID, but panics if an error occurs. +func (mq *MachineQuery) FirstIDX(ctx context.Context) int { id, err := mq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -121,7 +123,9 @@ func (mq *MachineQuery) FirstXID(ctx context.Context) int { return id } -// Only returns the only Machine entity in the query, returns an error if not exactly one entity was returned. +// Only returns a single Machine entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when exactly one Machine entity is not found. +// Returns a *NotFoundError when no Machine entities are found. func (mq *MachineQuery) Only(ctx context.Context) (*Machine, error) { nodes, err := mq.Limit(2).All(ctx) if err != nil { @@ -146,7 +150,9 @@ func (mq *MachineQuery) OnlyX(ctx context.Context) *Machine { return node } -// OnlyID returns the only Machine id in the query, returns an error if not exactly one id was returned. +// OnlyID is like Only, but returns the only Machine ID in the query. +// Returns a *NotSingularError when exactly one Machine ID is not found. +// Returns a *NotFoundError when no entities are found. func (mq *MachineQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int if ids, err = mq.Limit(2).IDs(ctx); err != nil { @@ -189,7 +195,7 @@ func (mq *MachineQuery) AllX(ctx context.Context) []*Machine { return nodes } -// IDs executes the query and returns a list of Machine ids. +// IDs executes the query and returns a list of Machine IDs. func (mq *MachineQuery) IDs(ctx context.Context) ([]int, error) { var ids []int if err := mq.Select(machine.FieldID).Scan(ctx, &ids); err != nil { @@ -241,24 +247,27 @@ func (mq *MachineQuery) ExistX(ctx context.Context) bool { return exist } -// Clone returns a duplicate of the query builder, including all associated steps. It can be +// Clone returns a duplicate of the MachineQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. func (mq *MachineQuery) Clone() *MachineQuery { + if mq == nil { + return nil + } return &MachineQuery{ config: mq.config, limit: mq.limit, offset: mq.offset, order: append([]OrderFunc{}, mq.order...), - unique: append([]string{}, mq.unique...), predicates: append([]predicate.Machine{}, mq.predicates...), + withAlerts: mq.withAlerts.Clone(), // clone intermediate query. sql: mq.sql.Clone(), path: mq.path, } } -// WithAlerts tells the query-builder to eager-loads the nodes that are connected to -// the "alerts" edge. The optional arguments used to configure the query builder of the edge. +// WithAlerts tells the query-builder to eager-load the nodes that are connected to +// the "alerts" edge. The optional arguments are used to configure the query builder of the edge. func (mq *MachineQuery) WithAlerts(opts ...func(*AlertQuery)) *MachineQuery { query := &AlertQuery{config: mq.config} for _, opt := range opts { @@ -268,7 +277,7 @@ func (mq *MachineQuery) WithAlerts(opts ...func(*AlertQuery)) *MachineQuery { return mq } -// GroupBy used to group vertices by one or more fields/columns. +// GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // // Example: @@ -295,7 +304,8 @@ func (mq *MachineQuery) GroupBy(field string, fields ...string) *MachineGroupBy return group } -// Select one or more fields from the given query. +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. // // Example: // @@ -308,18 +318,16 @@ func (mq *MachineQuery) GroupBy(field string, fields ...string) *MachineGroupBy // Scan(ctx, &v) // func (mq *MachineQuery) Select(field string, fields ...string) *MachineSelect { - selector := &MachineSelect{config: mq.config} - selector.fields = append([]string{field}, fields...) - selector.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := mq.prepareQuery(ctx); err != nil { - return nil, err - } - return mq.sqlQuery(), nil - } - return selector + mq.fields = append([]string{field}, fields...) + return &MachineSelect{MachineQuery: mq} } func (mq *MachineQuery) prepareQuery(ctx context.Context) error { + for _, f := range mq.fields { + if !machine.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } if mq.path != nil { prev, err := mq.path(ctx) if err != nil { @@ -338,19 +346,18 @@ func (mq *MachineQuery) sqlAll(ctx context.Context) ([]*Machine, error) { mq.withAlerts != nil, } ) - _spec.ScanValues = func() []interface{} { + _spec.ScanValues = func(columns []string) ([]interface{}, error) { node := &Machine{config: mq.config} nodes = append(nodes, node) - values := node.scanValues() - return values + return node.scanValues(columns) } - _spec.Assign = func(values ...interface{}) error { + _spec.Assign = func(columns []string, values []interface{}) error { if len(nodes) == 0 { return fmt.Errorf("ent: Assign called without calling ScanValues") } node := nodes[len(nodes)-1] node.Edges.loadedTypes = loadedTypes - return node.assignValues(values...) + return node.assignValues(columns, values) } if err := sqlgraph.QueryNodes(ctx, mq.driver, _spec); err != nil { return nil, err @@ -365,6 +372,7 @@ func (mq *MachineQuery) sqlAll(ctx context.Context) ([]*Machine, error) { for i := range nodes { fks = append(fks, nodes[i].ID) nodeids[nodes[i].ID] = nodes[i] + nodes[i].Edges.Alerts = []*Alert{} } query.withFKs = true query.Where(predicate.Alert(func(s *sql.Selector) { @@ -416,6 +424,15 @@ func (mq *MachineQuery) querySpec() *sqlgraph.QuerySpec { From: mq.sql, Unique: true, } + if fields := mq.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, machine.FieldID) + for i := range fields { + if fields[i] != machine.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } if ps := mq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -464,7 +481,7 @@ func (mq *MachineQuery) sqlQuery() *sql.Selector { return selector } -// MachineGroupBy is the builder for group-by Machine entities. +// MachineGroupBy is the group-by builder for Machine entities. type MachineGroupBy struct { config fields []string @@ -480,7 +497,7 @@ func (mgb *MachineGroupBy) Aggregate(fns ...AggregateFunc) *MachineGroupBy { return mgb } -// Scan applies the group-by query and scan the result into the given value. +// Scan applies the group-by query and scans the result into the given value. func (mgb *MachineGroupBy) Scan(ctx context.Context, v interface{}) error { query, err := mgb.path(ctx) if err != nil { @@ -497,7 +514,8 @@ func (mgb *MachineGroupBy) ScanX(ctx context.Context, v interface{}) { } } -// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field. +// Strings returns list of strings from group-by. +// It is only allowed when executing a group-by query with one field. func (mgb *MachineGroupBy) Strings(ctx context.Context) ([]string, error) { if len(mgb.fields) > 1 { return nil, errors.New("ent: MachineGroupBy.Strings is not achievable when grouping more than 1 field") @@ -518,7 +536,8 @@ func (mgb *MachineGroupBy) StringsX(ctx context.Context) []string { return v } -// String returns a single string from group-by. It is only allowed when querying group-by with one field. +// String returns a single string from a group-by query. +// It is only allowed when executing a group-by query with one field. func (mgb *MachineGroupBy) String(ctx context.Context) (_ string, err error) { var v []string if v, err = mgb.Strings(ctx); err != nil { @@ -544,7 +563,8 @@ func (mgb *MachineGroupBy) StringX(ctx context.Context) string { return v } -// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field. +// Ints returns list of ints from group-by. +// It is only allowed when executing a group-by query with one field. func (mgb *MachineGroupBy) Ints(ctx context.Context) ([]int, error) { if len(mgb.fields) > 1 { return nil, errors.New("ent: MachineGroupBy.Ints is not achievable when grouping more than 1 field") @@ -565,7 +585,8 @@ func (mgb *MachineGroupBy) IntsX(ctx context.Context) []int { return v } -// Int returns a single int from group-by. It is only allowed when querying group-by with one field. +// Int returns a single int from a group-by query. +// It is only allowed when executing a group-by query with one field. func (mgb *MachineGroupBy) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = mgb.Ints(ctx); err != nil { @@ -591,7 +612,8 @@ func (mgb *MachineGroupBy) IntX(ctx context.Context) int { return v } -// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field. +// Float64s returns list of float64s from group-by. +// It is only allowed when executing a group-by query with one field. func (mgb *MachineGroupBy) Float64s(ctx context.Context) ([]float64, error) { if len(mgb.fields) > 1 { return nil, errors.New("ent: MachineGroupBy.Float64s is not achievable when grouping more than 1 field") @@ -612,7 +634,8 @@ func (mgb *MachineGroupBy) Float64sX(ctx context.Context) []float64 { return v } -// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field. +// Float64 returns a single float64 from a group-by query. +// It is only allowed when executing a group-by query with one field. func (mgb *MachineGroupBy) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = mgb.Float64s(ctx); err != nil { @@ -638,7 +661,8 @@ func (mgb *MachineGroupBy) Float64X(ctx context.Context) float64 { return v } -// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field. +// Bools returns list of bools from group-by. +// It is only allowed when executing a group-by query with one field. func (mgb *MachineGroupBy) Bools(ctx context.Context) ([]bool, error) { if len(mgb.fields) > 1 { return nil, errors.New("ent: MachineGroupBy.Bools is not achievable when grouping more than 1 field") @@ -659,7 +683,8 @@ func (mgb *MachineGroupBy) BoolsX(ctx context.Context) []bool { return v } -// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field. +// Bool returns a single bool from a group-by query. +// It is only allowed when executing a group-by query with one field. func (mgb *MachineGroupBy) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = mgb.Bools(ctx); err != nil { @@ -714,22 +739,19 @@ func (mgb *MachineGroupBy) sqlQuery() *sql.Selector { return selector.Select(columns...).GroupBy(mgb.fields...) } -// MachineSelect is the builder for select fields of Machine entities. +// MachineSelect is the builder for selecting fields of Machine entities. type MachineSelect struct { - config - fields []string + *MachineQuery // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + sql *sql.Selector } -// Scan applies the selector query and scan the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (ms *MachineSelect) Scan(ctx context.Context, v interface{}) error { - query, err := ms.path(ctx) - if err != nil { + if err := ms.prepareQuery(ctx); err != nil { return err } - ms.sql = query + ms.sql = ms.MachineQuery.sqlQuery() return ms.sqlScan(ctx, v) } @@ -740,7 +762,7 @@ func (ms *MachineSelect) ScanX(ctx context.Context, v interface{}) { } } -// Strings returns list of strings from selector. It is only allowed when selecting one field. +// Strings returns list of strings from a selector. It is only allowed when selecting one field. func (ms *MachineSelect) Strings(ctx context.Context) ([]string, error) { if len(ms.fields) > 1 { return nil, errors.New("ent: MachineSelect.Strings is not achievable when selecting more than 1 field") @@ -761,7 +783,7 @@ func (ms *MachineSelect) StringsX(ctx context.Context) []string { return v } -// String returns a single string from selector. It is only allowed when selecting one field. +// String returns a single string from a selector. It is only allowed when selecting one field. func (ms *MachineSelect) String(ctx context.Context) (_ string, err error) { var v []string if v, err = ms.Strings(ctx); err != nil { @@ -787,7 +809,7 @@ func (ms *MachineSelect) StringX(ctx context.Context) string { return v } -// Ints returns list of ints from selector. It is only allowed when selecting one field. +// Ints returns list of ints from a selector. It is only allowed when selecting one field. func (ms *MachineSelect) Ints(ctx context.Context) ([]int, error) { if len(ms.fields) > 1 { return nil, errors.New("ent: MachineSelect.Ints is not achievable when selecting more than 1 field") @@ -808,7 +830,7 @@ func (ms *MachineSelect) IntsX(ctx context.Context) []int { return v } -// Int returns a single int from selector. It is only allowed when selecting one field. +// Int returns a single int from a selector. It is only allowed when selecting one field. func (ms *MachineSelect) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = ms.Ints(ctx); err != nil { @@ -834,7 +856,7 @@ func (ms *MachineSelect) IntX(ctx context.Context) int { return v } -// Float64s returns list of float64s from selector. It is only allowed when selecting one field. +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. func (ms *MachineSelect) Float64s(ctx context.Context) ([]float64, error) { if len(ms.fields) > 1 { return nil, errors.New("ent: MachineSelect.Float64s is not achievable when selecting more than 1 field") @@ -855,7 +877,7 @@ func (ms *MachineSelect) Float64sX(ctx context.Context) []float64 { return v } -// Float64 returns a single float64 from selector. It is only allowed when selecting one field. +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. func (ms *MachineSelect) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = ms.Float64s(ctx); err != nil { @@ -881,7 +903,7 @@ func (ms *MachineSelect) Float64X(ctx context.Context) float64 { return v } -// Bools returns list of bools from selector. It is only allowed when selecting one field. +// Bools returns list of bools from a selector. It is only allowed when selecting one field. func (ms *MachineSelect) Bools(ctx context.Context) ([]bool, error) { if len(ms.fields) > 1 { return nil, errors.New("ent: MachineSelect.Bools is not achievable when selecting more than 1 field") @@ -902,7 +924,7 @@ func (ms *MachineSelect) BoolsX(ctx context.Context) []bool { return v } -// Bool returns a single bool from selector. It is only allowed when selecting one field. +// Bool returns a single bool from a selector. It is only allowed when selecting one field. func (ms *MachineSelect) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = ms.Bools(ctx); err != nil { @@ -929,11 +951,6 @@ func (ms *MachineSelect) BoolX(ctx context.Context) bool { } func (ms *MachineSelect) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range ms.fields { - if !machine.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for selection", f)} - } - } rows := &sql.Rows{} query, args := ms.sqlQuery().Query() if err := ms.driver.Query(ctx, query, args, rows); err != nil { diff --git a/pkg/database/ent/machine_update.go b/pkg/database/ent/machine_update.go index fb7b99160..c3acaf34f 100644 --- a/pkg/database/ent/machine_update.go +++ b/pkg/database/ent/machine_update.go @@ -18,24 +18,23 @@ import ( // MachineUpdate is the builder for updating Machine entities. type MachineUpdate struct { config - hooks []Hook - mutation *MachineMutation - predicates []predicate.Machine + hooks []Hook + mutation *MachineMutation } -// Where adds a new predicate for the builder. +// Where adds a new predicate for the MachineUpdate builder. func (mu *MachineUpdate) Where(ps ...predicate.Machine) *MachineUpdate { - mu.predicates = append(mu.predicates, ps...) + mu.mutation.predicates = append(mu.mutation.predicates, ps...) return mu } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (mu *MachineUpdate) SetCreatedAt(t time.Time) *MachineUpdate { mu.mutation.SetCreatedAt(t) return mu } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (mu *MachineUpdate) SetNillableCreatedAt(t *time.Time) *MachineUpdate { if t != nil { mu.SetCreatedAt(*t) @@ -43,13 +42,13 @@ func (mu *MachineUpdate) SetNillableCreatedAt(t *time.Time) *MachineUpdate { return mu } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (mu *MachineUpdate) SetUpdatedAt(t time.Time) *MachineUpdate { mu.mutation.SetUpdatedAt(t) return mu } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (mu *MachineUpdate) SetNillableUpdatedAt(t *time.Time) *MachineUpdate { if t != nil { mu.SetUpdatedAt(*t) @@ -57,31 +56,31 @@ func (mu *MachineUpdate) SetNillableUpdatedAt(t *time.Time) *MachineUpdate { return mu } -// SetMachineId sets the machineId field. +// SetMachineId sets the "machineId" field. func (mu *MachineUpdate) SetMachineId(s string) *MachineUpdate { mu.mutation.SetMachineId(s) return mu } -// SetPassword sets the password field. +// SetPassword sets the "password" field. func (mu *MachineUpdate) SetPassword(s string) *MachineUpdate { mu.mutation.SetPassword(s) return mu } -// SetIpAddress sets the ipAddress field. +// SetIpAddress sets the "ipAddress" field. func (mu *MachineUpdate) SetIpAddress(s string) *MachineUpdate { mu.mutation.SetIpAddress(s) return mu } -// SetScenarios sets the scenarios field. +// SetScenarios sets the "scenarios" field. func (mu *MachineUpdate) SetScenarios(s string) *MachineUpdate { mu.mutation.SetScenarios(s) return mu } -// SetNillableScenarios sets the scenarios field if the given value is not nil. +// SetNillableScenarios sets the "scenarios" field if the given value is not nil. func (mu *MachineUpdate) SetNillableScenarios(s *string) *MachineUpdate { if s != nil { mu.SetScenarios(*s) @@ -89,19 +88,19 @@ func (mu *MachineUpdate) SetNillableScenarios(s *string) *MachineUpdate { return mu } -// ClearScenarios clears the value of scenarios. +// ClearScenarios clears the value of the "scenarios" field. func (mu *MachineUpdate) ClearScenarios() *MachineUpdate { mu.mutation.ClearScenarios() return mu } -// SetVersion sets the version field. +// SetVersion sets the "version" field. func (mu *MachineUpdate) SetVersion(s string) *MachineUpdate { mu.mutation.SetVersion(s) return mu } -// SetNillableVersion sets the version field if the given value is not nil. +// SetNillableVersion sets the "version" field if the given value is not nil. func (mu *MachineUpdate) SetNillableVersion(s *string) *MachineUpdate { if s != nil { mu.SetVersion(*s) @@ -109,19 +108,19 @@ func (mu *MachineUpdate) SetNillableVersion(s *string) *MachineUpdate { return mu } -// ClearVersion clears the value of version. +// ClearVersion clears the value of the "version" field. func (mu *MachineUpdate) ClearVersion() *MachineUpdate { mu.mutation.ClearVersion() return mu } -// SetIsValidated sets the isValidated field. +// SetIsValidated sets the "isValidated" field. func (mu *MachineUpdate) SetIsValidated(b bool) *MachineUpdate { mu.mutation.SetIsValidated(b) return mu } -// SetNillableIsValidated sets the isValidated field if the given value is not nil. +// SetNillableIsValidated sets the "isValidated" field if the given value is not nil. func (mu *MachineUpdate) SetNillableIsValidated(b *bool) *MachineUpdate { if b != nil { mu.SetIsValidated(*b) @@ -129,13 +128,13 @@ func (mu *MachineUpdate) SetNillableIsValidated(b *bool) *MachineUpdate { return mu } -// SetStatus sets the status field. +// SetStatus sets the "status" field. func (mu *MachineUpdate) SetStatus(s string) *MachineUpdate { mu.mutation.SetStatus(s) return mu } -// SetNillableStatus sets the status field if the given value is not nil. +// SetNillableStatus sets the "status" field if the given value is not nil. func (mu *MachineUpdate) SetNillableStatus(s *string) *MachineUpdate { if s != nil { mu.SetStatus(*s) @@ -143,19 +142,19 @@ func (mu *MachineUpdate) SetNillableStatus(s *string) *MachineUpdate { return mu } -// ClearStatus clears the value of status. +// ClearStatus clears the value of the "status" field. func (mu *MachineUpdate) ClearStatus() *MachineUpdate { mu.mutation.ClearStatus() return mu } -// AddAlertIDs adds the alerts edge to Alert by ids. +// AddAlertIDs adds the "alerts" edge to the Alert entity by IDs. func (mu *MachineUpdate) AddAlertIDs(ids ...int) *MachineUpdate { mu.mutation.AddAlertIDs(ids...) return mu } -// AddAlerts adds the alerts edges to Alert. +// AddAlerts adds the "alerts" edges to the Alert entity. func (mu *MachineUpdate) AddAlerts(a ...*Alert) *MachineUpdate { ids := make([]int, len(a)) for i := range a { @@ -169,19 +168,19 @@ func (mu *MachineUpdate) Mutation() *MachineMutation { return mu.mutation } -// ClearAlerts clears all "alerts" edges to type Alert. +// ClearAlerts clears all "alerts" edges to the Alert entity. func (mu *MachineUpdate) ClearAlerts() *MachineUpdate { mu.mutation.ClearAlerts() return mu } -// RemoveAlertIDs removes the alerts edge to Alert by ids. +// RemoveAlertIDs removes the "alerts" edge to Alert entities by IDs. func (mu *MachineUpdate) RemoveAlertIDs(ids ...int) *MachineUpdate { mu.mutation.RemoveAlertIDs(ids...) return mu } -// RemoveAlerts removes alerts edges to Alert. +// RemoveAlerts removes "alerts" edges to Alert entities. func (mu *MachineUpdate) RemoveAlerts(a ...*Alert) *MachineUpdate { ids := make([]int, len(a)) for i := range a { @@ -190,7 +189,7 @@ func (mu *MachineUpdate) RemoveAlerts(a ...*Alert) *MachineUpdate { return mu.RemoveAlertIDs(ids...) } -// Save executes the query and returns the number of rows/vertices matched by this operation. +// Save executes the query and returns the number of nodes affected by the update operation. func (mu *MachineUpdate) Save(ctx context.Context) (int, error) { var ( err error @@ -268,7 +267,7 @@ func (mu *MachineUpdate) sqlSave(ctx context.Context) (n int, err error) { }, }, } - if ps := mu.predicates; len(ps) > 0 { + if ps := mu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) @@ -428,13 +427,13 @@ type MachineUpdateOne struct { mutation *MachineMutation } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (muo *MachineUpdateOne) SetCreatedAt(t time.Time) *MachineUpdateOne { muo.mutation.SetCreatedAt(t) return muo } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (muo *MachineUpdateOne) SetNillableCreatedAt(t *time.Time) *MachineUpdateOne { if t != nil { muo.SetCreatedAt(*t) @@ -442,13 +441,13 @@ func (muo *MachineUpdateOne) SetNillableCreatedAt(t *time.Time) *MachineUpdateOn return muo } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (muo *MachineUpdateOne) SetUpdatedAt(t time.Time) *MachineUpdateOne { muo.mutation.SetUpdatedAt(t) return muo } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (muo *MachineUpdateOne) SetNillableUpdatedAt(t *time.Time) *MachineUpdateOne { if t != nil { muo.SetUpdatedAt(*t) @@ -456,31 +455,31 @@ func (muo *MachineUpdateOne) SetNillableUpdatedAt(t *time.Time) *MachineUpdateOn return muo } -// SetMachineId sets the machineId field. +// SetMachineId sets the "machineId" field. func (muo *MachineUpdateOne) SetMachineId(s string) *MachineUpdateOne { muo.mutation.SetMachineId(s) return muo } -// SetPassword sets the password field. +// SetPassword sets the "password" field. func (muo *MachineUpdateOne) SetPassword(s string) *MachineUpdateOne { muo.mutation.SetPassword(s) return muo } -// SetIpAddress sets the ipAddress field. +// SetIpAddress sets the "ipAddress" field. func (muo *MachineUpdateOne) SetIpAddress(s string) *MachineUpdateOne { muo.mutation.SetIpAddress(s) return muo } -// SetScenarios sets the scenarios field. +// SetScenarios sets the "scenarios" field. func (muo *MachineUpdateOne) SetScenarios(s string) *MachineUpdateOne { muo.mutation.SetScenarios(s) return muo } -// SetNillableScenarios sets the scenarios field if the given value is not nil. +// SetNillableScenarios sets the "scenarios" field if the given value is not nil. func (muo *MachineUpdateOne) SetNillableScenarios(s *string) *MachineUpdateOne { if s != nil { muo.SetScenarios(*s) @@ -488,19 +487,19 @@ func (muo *MachineUpdateOne) SetNillableScenarios(s *string) *MachineUpdateOne { return muo } -// ClearScenarios clears the value of scenarios. +// ClearScenarios clears the value of the "scenarios" field. func (muo *MachineUpdateOne) ClearScenarios() *MachineUpdateOne { muo.mutation.ClearScenarios() return muo } -// SetVersion sets the version field. +// SetVersion sets the "version" field. func (muo *MachineUpdateOne) SetVersion(s string) *MachineUpdateOne { muo.mutation.SetVersion(s) return muo } -// SetNillableVersion sets the version field if the given value is not nil. +// SetNillableVersion sets the "version" field if the given value is not nil. func (muo *MachineUpdateOne) SetNillableVersion(s *string) *MachineUpdateOne { if s != nil { muo.SetVersion(*s) @@ -508,19 +507,19 @@ func (muo *MachineUpdateOne) SetNillableVersion(s *string) *MachineUpdateOne { return muo } -// ClearVersion clears the value of version. +// ClearVersion clears the value of the "version" field. func (muo *MachineUpdateOne) ClearVersion() *MachineUpdateOne { muo.mutation.ClearVersion() return muo } -// SetIsValidated sets the isValidated field. +// SetIsValidated sets the "isValidated" field. func (muo *MachineUpdateOne) SetIsValidated(b bool) *MachineUpdateOne { muo.mutation.SetIsValidated(b) return muo } -// SetNillableIsValidated sets the isValidated field if the given value is not nil. +// SetNillableIsValidated sets the "isValidated" field if the given value is not nil. func (muo *MachineUpdateOne) SetNillableIsValidated(b *bool) *MachineUpdateOne { if b != nil { muo.SetIsValidated(*b) @@ -528,13 +527,13 @@ func (muo *MachineUpdateOne) SetNillableIsValidated(b *bool) *MachineUpdateOne { return muo } -// SetStatus sets the status field. +// SetStatus sets the "status" field. func (muo *MachineUpdateOne) SetStatus(s string) *MachineUpdateOne { muo.mutation.SetStatus(s) return muo } -// SetNillableStatus sets the status field if the given value is not nil. +// SetNillableStatus sets the "status" field if the given value is not nil. func (muo *MachineUpdateOne) SetNillableStatus(s *string) *MachineUpdateOne { if s != nil { muo.SetStatus(*s) @@ -542,19 +541,19 @@ func (muo *MachineUpdateOne) SetNillableStatus(s *string) *MachineUpdateOne { return muo } -// ClearStatus clears the value of status. +// ClearStatus clears the value of the "status" field. func (muo *MachineUpdateOne) ClearStatus() *MachineUpdateOne { muo.mutation.ClearStatus() return muo } -// AddAlertIDs adds the alerts edge to Alert by ids. +// AddAlertIDs adds the "alerts" edge to the Alert entity by IDs. func (muo *MachineUpdateOne) AddAlertIDs(ids ...int) *MachineUpdateOne { muo.mutation.AddAlertIDs(ids...) return muo } -// AddAlerts adds the alerts edges to Alert. +// AddAlerts adds the "alerts" edges to the Alert entity. func (muo *MachineUpdateOne) AddAlerts(a ...*Alert) *MachineUpdateOne { ids := make([]int, len(a)) for i := range a { @@ -568,19 +567,19 @@ func (muo *MachineUpdateOne) Mutation() *MachineMutation { return muo.mutation } -// ClearAlerts clears all "alerts" edges to type Alert. +// ClearAlerts clears all "alerts" edges to the Alert entity. func (muo *MachineUpdateOne) ClearAlerts() *MachineUpdateOne { muo.mutation.ClearAlerts() return muo } -// RemoveAlertIDs removes the alerts edge to Alert by ids. +// RemoveAlertIDs removes the "alerts" edge to Alert entities by IDs. func (muo *MachineUpdateOne) RemoveAlertIDs(ids ...int) *MachineUpdateOne { muo.mutation.RemoveAlertIDs(ids...) return muo } -// RemoveAlerts removes alerts edges to Alert. +// RemoveAlerts removes "alerts" edges to Alert entities. func (muo *MachineUpdateOne) RemoveAlerts(a ...*Alert) *MachineUpdateOne { ids := make([]int, len(a)) for i := range a { @@ -589,7 +588,7 @@ func (muo *MachineUpdateOne) RemoveAlerts(a ...*Alert) *MachineUpdateOne { return muo.RemoveAlertIDs(ids...) } -// Save executes the query and returns the updated entity. +// Save executes the query and returns the updated Machine entity. func (muo *MachineUpdateOne) Save(ctx context.Context) (*Machine, error) { var ( err error @@ -809,7 +808,7 @@ func (muo *MachineUpdateOne) sqlSave(ctx context.Context) (_node *Machine, err e } _node = &Machine{config: muo.config} _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues() + _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{machine.Label} diff --git a/pkg/database/ent/meta.go b/pkg/database/ent/meta.go index 257f59893..48bfc53c4 100644 --- a/pkg/database/ent/meta.go +++ b/pkg/database/ent/meta.go @@ -55,81 +55,89 @@ func (e MetaEdges) OwnerOrErr() (*Alert, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*Meta) scanValues() []interface{} { - return []interface{}{ - &sql.NullInt64{}, // id - &sql.NullTime{}, // created_at - &sql.NullTime{}, // updated_at - &sql.NullString{}, // key - &sql.NullString{}, // value - } -} - -// fkValues returns the types for scanning foreign-keys values from sql.Rows. -func (*Meta) fkValues() []interface{} { - return []interface{}{ - &sql.NullInt64{}, // alert_metas +func (*Meta) scanValues(columns []string) ([]interface{}, error) { + values := make([]interface{}, len(columns)) + for i := range columns { + switch columns[i] { + case meta.FieldID: + values[i] = &sql.NullInt64{} + case meta.FieldKey, meta.FieldValue: + values[i] = &sql.NullString{} + case meta.FieldCreatedAt, meta.FieldUpdatedAt: + values[i] = &sql.NullTime{} + case meta.ForeignKeys[0]: // alert_metas + values[i] = &sql.NullInt64{} + default: + return nil, fmt.Errorf("unexpected column %q for type Meta", columns[i]) + } } + return values, nil } // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Meta fields. -func (m *Meta) assignValues(values ...interface{}) error { - if m, n := len(values), len(meta.Columns); m < n { +func (m *Meta) 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) } - value, ok := values[0].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - m.ID = int(value.Int64) - values = values[1:] - if value, ok := values[0].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[0]) - } else if value.Valid { - m.CreatedAt = value.Time - } - if value, ok := values[1].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[1]) - } else if value.Valid { - m.UpdatedAt = value.Time - } - if value, ok := values[2].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field key", values[2]) - } else if value.Valid { - m.Key = value.String - } - if value, ok := values[3].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field value", values[3]) - } else if value.Valid { - m.Value = value.String - } - values = values[4:] - if len(values) == len(meta.ForeignKeys) { - if value, ok := values[0].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for edge-field alert_metas", value) - } else if value.Valid { - m.alert_metas = new(int) - *m.alert_metas = int(value.Int64) + for i := range columns { + switch columns[i] { + case meta.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + m.ID = int(value.Int64) + case meta.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 { + m.CreatedAt = value.Time + } + case meta.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 { + m.UpdatedAt = value.Time + } + case meta.FieldKey: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field key", values[i]) + } else if value.Valid { + m.Key = value.String + } + case meta.FieldValue: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field value", values[i]) + } else if value.Valid { + m.Value = value.String + } + case meta.ForeignKeys[0]: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for edge-field alert_metas", value) + } else if value.Valid { + m.alert_metas = new(int) + *m.alert_metas = int(value.Int64) + } } } return nil } -// QueryOwner queries the owner edge of the Meta. +// QueryOwner queries the "owner" edge of the Meta entity. func (m *Meta) QueryOwner() *AlertQuery { return (&MetaClient{config: m.config}).QueryOwner(m) } // Update returns a builder for updating this Meta. -// Note that, you need to call Meta.Unwrap() before calling this method, if this Meta +// Note that you need to call Meta.Unwrap() before calling this method if this Meta // was returned from a transaction, and the transaction was committed or rolled back. func (m *Meta) Update() *MetaUpdateOne { return (&MetaClient{config: m.config}).UpdateOne(m) } -// Unwrap unwraps the entity that was returned from a transaction after it was closed, -// so that all next queries will be executed through the driver which created the transaction. +// Unwrap unwraps the Meta 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 (m *Meta) Unwrap() *Meta { tx, ok := m.config.driver.(*txDriver) if !ok { diff --git a/pkg/database/ent/meta/meta.go b/pkg/database/ent/meta/meta.go index 7dd0a48ea..c003b1f1e 100644 --- a/pkg/database/ent/meta/meta.go +++ b/pkg/database/ent/meta/meta.go @@ -64,9 +64,9 @@ func ValidColumn(column string) bool { } var ( - // DefaultCreatedAt holds the default value on creation for the created_at field. + // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the updated_at field. + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. DefaultUpdatedAt func() time.Time // ValueValidator is a validator for the "value" field. It is called by the builders before save. ValueValidator func(string) error diff --git a/pkg/database/ent/meta/where.go b/pkg/database/ent/meta/where.go index 40a15d6fe..c416506ae 100644 --- a/pkg/database/ent/meta/where.go +++ b/pkg/database/ent/meta/where.go @@ -10,7 +10,7 @@ import ( "github.com/facebook/ent/dialect/sql/sqlgraph" ) -// ID filters vertices based on their identifier. +// ID filters vertices based on their ID field. func ID(id int) predicate.Meta { return predicate.Meta(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldID), id)) @@ -523,7 +523,7 @@ func HasOwnerWith(preds ...predicate.Alert) predicate.Meta { }) } -// And groups list of predicates with the AND operator between them. +// And groups predicates with the AND operator between them. func And(predicates ...predicate.Meta) predicate.Meta { return predicate.Meta(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) @@ -534,7 +534,7 @@ func And(predicates ...predicate.Meta) predicate.Meta { }) } -// Or groups list of predicates with the OR operator between them. +// Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Meta) predicate.Meta { return predicate.Meta(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) diff --git a/pkg/database/ent/meta_create.go b/pkg/database/ent/meta_create.go index 65129c119..a6fe832c0 100644 --- a/pkg/database/ent/meta_create.go +++ b/pkg/database/ent/meta_create.go @@ -21,13 +21,13 @@ type MetaCreate struct { hooks []Hook } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (mc *MetaCreate) SetCreatedAt(t time.Time) *MetaCreate { mc.mutation.SetCreatedAt(t) return mc } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (mc *MetaCreate) SetNillableCreatedAt(t *time.Time) *MetaCreate { if t != nil { mc.SetCreatedAt(*t) @@ -35,13 +35,13 @@ func (mc *MetaCreate) SetNillableCreatedAt(t *time.Time) *MetaCreate { return mc } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (mc *MetaCreate) SetUpdatedAt(t time.Time) *MetaCreate { mc.mutation.SetUpdatedAt(t) return mc } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (mc *MetaCreate) SetNillableUpdatedAt(t *time.Time) *MetaCreate { if t != nil { mc.SetUpdatedAt(*t) @@ -49,25 +49,25 @@ func (mc *MetaCreate) SetNillableUpdatedAt(t *time.Time) *MetaCreate { return mc } -// SetKey sets the key field. +// SetKey sets the "key" field. func (mc *MetaCreate) SetKey(s string) *MetaCreate { mc.mutation.SetKey(s) return mc } -// SetValue sets the value field. +// SetValue sets the "value" field. func (mc *MetaCreate) SetValue(s string) *MetaCreate { mc.mutation.SetValue(s) return mc } -// SetOwnerID sets the owner edge to Alert by id. +// SetOwnerID sets the "owner" edge to the Alert entity by ID. func (mc *MetaCreate) SetOwnerID(id int) *MetaCreate { mc.mutation.SetOwnerID(id) return mc } -// SetNillableOwnerID sets the owner edge to Alert by id if the given value is not nil. +// SetNillableOwnerID sets the "owner" edge to the Alert entity by ID if the given value is not nil. func (mc *MetaCreate) SetNillableOwnerID(id *int) *MetaCreate { if id != nil { mc = mc.SetOwnerID(*id) @@ -75,7 +75,7 @@ func (mc *MetaCreate) SetNillableOwnerID(id *int) *MetaCreate { return mc } -// SetOwner sets the owner edge to Alert. +// SetOwner sets the "owner" edge to the Alert entity. func (mc *MetaCreate) SetOwner(a *Alert) *MetaCreate { return mc.SetOwnerID(a.ID) } @@ -242,7 +242,7 @@ func (mc *MetaCreate) createSpec() (*Meta, *sqlgraph.CreateSpec) { return _node, _spec } -// MetaCreateBulk is the builder for creating a bulk of Meta entities. +// MetaCreateBulk is the builder for creating many Meta entities in bulk. type MetaCreateBulk struct { config builders []*MetaCreate @@ -300,7 +300,7 @@ func (mcb *MetaCreateBulk) Save(ctx context.Context) ([]*Meta, error) { return nodes, nil } -// SaveX calls Save and panics if Save returns an error. +// SaveX is like Save, but panics if an error occurs. func (mcb *MetaCreateBulk) SaveX(ctx context.Context) []*Meta { v, err := mcb.Save(ctx) if err != nil { diff --git a/pkg/database/ent/meta_delete.go b/pkg/database/ent/meta_delete.go index ec43e945b..2d5e7d634 100644 --- a/pkg/database/ent/meta_delete.go +++ b/pkg/database/ent/meta_delete.go @@ -16,14 +16,13 @@ import ( // MetaDelete is the builder for deleting a Meta entity. type MetaDelete struct { config - hooks []Hook - mutation *MetaMutation - predicates []predicate.Meta + hooks []Hook + mutation *MetaMutation } -// Where adds a new predicate to the delete builder. +// Where adds a new predicate to the MetaDelete builder. func (md *MetaDelete) Where(ps ...predicate.Meta) *MetaDelete { - md.predicates = append(md.predicates, ps...) + md.mutation.predicates = append(md.mutation.predicates, ps...) return md } @@ -75,7 +74,7 @@ func (md *MetaDelete) sqlExec(ctx context.Context) (int, error) { }, }, } - if ps := md.predicates; len(ps) > 0 { + if ps := md.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) diff --git a/pkg/database/ent/meta_query.go b/pkg/database/ent/meta_query.go index 2aa311854..47f40daaa 100644 --- a/pkg/database/ent/meta_query.go +++ b/pkg/database/ent/meta_query.go @@ -22,7 +22,7 @@ type MetaQuery struct { limit *int offset *int order []OrderFunc - unique []string + fields []string predicates []predicate.Meta // eager-loading edges. withOwner *AlertQuery @@ -32,7 +32,7 @@ type MetaQuery struct { path func(context.Context) (*sql.Selector, error) } -// Where adds a new predicate for the builder. +// Where adds a new predicate for the MetaQuery builder. func (mq *MetaQuery) Where(ps ...predicate.Meta) *MetaQuery { mq.predicates = append(mq.predicates, ps...) return mq @@ -56,7 +56,7 @@ func (mq *MetaQuery) Order(o ...OrderFunc) *MetaQuery { return mq } -// QueryOwner chains the current query on the owner edge. +// QueryOwner chains the current query on the "owner" edge. func (mq *MetaQuery) QueryOwner() *AlertQuery { query := &AlertQuery{config: mq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { @@ -78,7 +78,8 @@ func (mq *MetaQuery) QueryOwner() *AlertQuery { return query } -// First returns the first Meta entity in the query. Returns *NotFoundError when no meta was found. +// First returns the first Meta entity from the query. +// Returns a *NotFoundError when no Meta was found. func (mq *MetaQuery) First(ctx context.Context) (*Meta, error) { nodes, err := mq.Limit(1).All(ctx) if err != nil { @@ -99,7 +100,8 @@ func (mq *MetaQuery) FirstX(ctx context.Context) *Meta { return node } -// FirstID returns the first Meta id in the query. Returns *NotFoundError when no id was found. +// FirstID returns the first Meta ID from the query. +// Returns a *NotFoundError when no Meta ID was found. func (mq *MetaQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int if ids, err = mq.Limit(1).IDs(ctx); err != nil { @@ -112,8 +114,8 @@ func (mq *MetaQuery) FirstID(ctx context.Context) (id int, err error) { return ids[0], nil } -// FirstXID is like FirstID, but panics if an error occurs. -func (mq *MetaQuery) FirstXID(ctx context.Context) int { +// FirstIDX is like FirstID, but panics if an error occurs. +func (mq *MetaQuery) FirstIDX(ctx context.Context) int { id, err := mq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -121,7 +123,9 @@ func (mq *MetaQuery) FirstXID(ctx context.Context) int { return id } -// Only returns the only Meta entity in the query, returns an error if not exactly one entity was returned. +// Only returns a single Meta entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when exactly one Meta entity is not found. +// Returns a *NotFoundError when no Meta entities are found. func (mq *MetaQuery) Only(ctx context.Context) (*Meta, error) { nodes, err := mq.Limit(2).All(ctx) if err != nil { @@ -146,7 +150,9 @@ func (mq *MetaQuery) OnlyX(ctx context.Context) *Meta { return node } -// OnlyID returns the only Meta id in the query, returns an error if not exactly one id was returned. +// OnlyID is like Only, but returns the only Meta ID in the query. +// Returns a *NotSingularError when exactly one Meta ID is not found. +// Returns a *NotFoundError when no entities are found. func (mq *MetaQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int if ids, err = mq.Limit(2).IDs(ctx); err != nil { @@ -189,7 +195,7 @@ func (mq *MetaQuery) AllX(ctx context.Context) []*Meta { return nodes } -// IDs executes the query and returns a list of Meta ids. +// IDs executes the query and returns a list of Meta IDs. func (mq *MetaQuery) IDs(ctx context.Context) ([]int, error) { var ids []int if err := mq.Select(meta.FieldID).Scan(ctx, &ids); err != nil { @@ -241,24 +247,27 @@ func (mq *MetaQuery) ExistX(ctx context.Context) bool { return exist } -// Clone returns a duplicate of the query builder, including all associated steps. It can be +// Clone returns a duplicate of the MetaQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. func (mq *MetaQuery) Clone() *MetaQuery { + if mq == nil { + return nil + } return &MetaQuery{ config: mq.config, limit: mq.limit, offset: mq.offset, order: append([]OrderFunc{}, mq.order...), - unique: append([]string{}, mq.unique...), predicates: append([]predicate.Meta{}, mq.predicates...), + withOwner: mq.withOwner.Clone(), // clone intermediate query. sql: mq.sql.Clone(), path: mq.path, } } -// WithOwner tells the query-builder to eager-loads the nodes that are connected to -// the "owner" edge. The optional arguments used to configure the query builder of the edge. +// WithOwner tells the query-builder to eager-load the nodes that are connected to +// the "owner" edge. The optional arguments are used to configure the query builder of the edge. func (mq *MetaQuery) WithOwner(opts ...func(*AlertQuery)) *MetaQuery { query := &AlertQuery{config: mq.config} for _, opt := range opts { @@ -268,7 +277,7 @@ func (mq *MetaQuery) WithOwner(opts ...func(*AlertQuery)) *MetaQuery { return mq } -// GroupBy used to group vertices by one or more fields/columns. +// GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // // Example: @@ -295,7 +304,8 @@ func (mq *MetaQuery) GroupBy(field string, fields ...string) *MetaGroupBy { return group } -// Select one or more fields from the given query. +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. // // Example: // @@ -308,18 +318,16 @@ func (mq *MetaQuery) GroupBy(field string, fields ...string) *MetaGroupBy { // Scan(ctx, &v) // func (mq *MetaQuery) Select(field string, fields ...string) *MetaSelect { - selector := &MetaSelect{config: mq.config} - selector.fields = append([]string{field}, fields...) - selector.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := mq.prepareQuery(ctx); err != nil { - return nil, err - } - return mq.sqlQuery(), nil - } - return selector + mq.fields = append([]string{field}, fields...) + return &MetaSelect{MetaQuery: mq} } func (mq *MetaQuery) prepareQuery(ctx context.Context) error { + for _, f := range mq.fields { + if !meta.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } if mq.path != nil { prev, err := mq.path(ctx) if err != nil { @@ -345,22 +353,18 @@ func (mq *MetaQuery) sqlAll(ctx context.Context) ([]*Meta, error) { if withFKs { _spec.Node.Columns = append(_spec.Node.Columns, meta.ForeignKeys...) } - _spec.ScanValues = func() []interface{} { + _spec.ScanValues = func(columns []string) ([]interface{}, error) { node := &Meta{config: mq.config} nodes = append(nodes, node) - values := node.scanValues() - if withFKs { - values = append(values, node.fkValues()...) - } - return values + return node.scanValues(columns) } - _spec.Assign = func(values ...interface{}) error { + _spec.Assign = func(columns []string, values []interface{}) error { if len(nodes) == 0 { return fmt.Errorf("ent: Assign called without calling ScanValues") } node := nodes[len(nodes)-1] node.Edges.loadedTypes = loadedTypes - return node.assignValues(values...) + return node.assignValues(columns, values) } if err := sqlgraph.QueryNodes(ctx, mq.driver, _spec); err != nil { return nil, err @@ -423,6 +427,15 @@ func (mq *MetaQuery) querySpec() *sqlgraph.QuerySpec { From: mq.sql, Unique: true, } + if fields := mq.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, meta.FieldID) + for i := range fields { + if fields[i] != meta.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } if ps := mq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -471,7 +484,7 @@ func (mq *MetaQuery) sqlQuery() *sql.Selector { return selector } -// MetaGroupBy is the builder for group-by Meta entities. +// MetaGroupBy is the group-by builder for Meta entities. type MetaGroupBy struct { config fields []string @@ -487,7 +500,7 @@ func (mgb *MetaGroupBy) Aggregate(fns ...AggregateFunc) *MetaGroupBy { return mgb } -// Scan applies the group-by query and scan the result into the given value. +// Scan applies the group-by query and scans the result into the given value. func (mgb *MetaGroupBy) Scan(ctx context.Context, v interface{}) error { query, err := mgb.path(ctx) if err != nil { @@ -504,7 +517,8 @@ func (mgb *MetaGroupBy) ScanX(ctx context.Context, v interface{}) { } } -// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field. +// Strings returns list of strings from group-by. +// It is only allowed when executing a group-by query with one field. func (mgb *MetaGroupBy) Strings(ctx context.Context) ([]string, error) { if len(mgb.fields) > 1 { return nil, errors.New("ent: MetaGroupBy.Strings is not achievable when grouping more than 1 field") @@ -525,7 +539,8 @@ func (mgb *MetaGroupBy) StringsX(ctx context.Context) []string { return v } -// String returns a single string from group-by. It is only allowed when querying group-by with one field. +// String returns a single string from a group-by query. +// It is only allowed when executing a group-by query with one field. func (mgb *MetaGroupBy) String(ctx context.Context) (_ string, err error) { var v []string if v, err = mgb.Strings(ctx); err != nil { @@ -551,7 +566,8 @@ func (mgb *MetaGroupBy) StringX(ctx context.Context) string { return v } -// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field. +// Ints returns list of ints from group-by. +// It is only allowed when executing a group-by query with one field. func (mgb *MetaGroupBy) Ints(ctx context.Context) ([]int, error) { if len(mgb.fields) > 1 { return nil, errors.New("ent: MetaGroupBy.Ints is not achievable when grouping more than 1 field") @@ -572,7 +588,8 @@ func (mgb *MetaGroupBy) IntsX(ctx context.Context) []int { return v } -// Int returns a single int from group-by. It is only allowed when querying group-by with one field. +// Int returns a single int from a group-by query. +// It is only allowed when executing a group-by query with one field. func (mgb *MetaGroupBy) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = mgb.Ints(ctx); err != nil { @@ -598,7 +615,8 @@ func (mgb *MetaGroupBy) IntX(ctx context.Context) int { return v } -// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field. +// Float64s returns list of float64s from group-by. +// It is only allowed when executing a group-by query with one field. func (mgb *MetaGroupBy) Float64s(ctx context.Context) ([]float64, error) { if len(mgb.fields) > 1 { return nil, errors.New("ent: MetaGroupBy.Float64s is not achievable when grouping more than 1 field") @@ -619,7 +637,8 @@ func (mgb *MetaGroupBy) Float64sX(ctx context.Context) []float64 { return v } -// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field. +// Float64 returns a single float64 from a group-by query. +// It is only allowed when executing a group-by query with one field. func (mgb *MetaGroupBy) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = mgb.Float64s(ctx); err != nil { @@ -645,7 +664,8 @@ func (mgb *MetaGroupBy) Float64X(ctx context.Context) float64 { return v } -// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field. +// Bools returns list of bools from group-by. +// It is only allowed when executing a group-by query with one field. func (mgb *MetaGroupBy) Bools(ctx context.Context) ([]bool, error) { if len(mgb.fields) > 1 { return nil, errors.New("ent: MetaGroupBy.Bools is not achievable when grouping more than 1 field") @@ -666,7 +686,8 @@ func (mgb *MetaGroupBy) BoolsX(ctx context.Context) []bool { return v } -// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field. +// Bool returns a single bool from a group-by query. +// It is only allowed when executing a group-by query with one field. func (mgb *MetaGroupBy) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = mgb.Bools(ctx); err != nil { @@ -721,22 +742,19 @@ func (mgb *MetaGroupBy) sqlQuery() *sql.Selector { return selector.Select(columns...).GroupBy(mgb.fields...) } -// MetaSelect is the builder for select fields of Meta entities. +// MetaSelect is the builder for selecting fields of Meta entities. type MetaSelect struct { - config - fields []string + *MetaQuery // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + sql *sql.Selector } -// Scan applies the selector query and scan the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (ms *MetaSelect) Scan(ctx context.Context, v interface{}) error { - query, err := ms.path(ctx) - if err != nil { + if err := ms.prepareQuery(ctx); err != nil { return err } - ms.sql = query + ms.sql = ms.MetaQuery.sqlQuery() return ms.sqlScan(ctx, v) } @@ -747,7 +765,7 @@ func (ms *MetaSelect) ScanX(ctx context.Context, v interface{}) { } } -// Strings returns list of strings from selector. It is only allowed when selecting one field. +// Strings returns list of strings from a selector. It is only allowed when selecting one field. func (ms *MetaSelect) Strings(ctx context.Context) ([]string, error) { if len(ms.fields) > 1 { return nil, errors.New("ent: MetaSelect.Strings is not achievable when selecting more than 1 field") @@ -768,7 +786,7 @@ func (ms *MetaSelect) StringsX(ctx context.Context) []string { return v } -// String returns a single string from selector. It is only allowed when selecting one field. +// String returns a single string from a selector. It is only allowed when selecting one field. func (ms *MetaSelect) String(ctx context.Context) (_ string, err error) { var v []string if v, err = ms.Strings(ctx); err != nil { @@ -794,7 +812,7 @@ func (ms *MetaSelect) StringX(ctx context.Context) string { return v } -// Ints returns list of ints from selector. It is only allowed when selecting one field. +// Ints returns list of ints from a selector. It is only allowed when selecting one field. func (ms *MetaSelect) Ints(ctx context.Context) ([]int, error) { if len(ms.fields) > 1 { return nil, errors.New("ent: MetaSelect.Ints is not achievable when selecting more than 1 field") @@ -815,7 +833,7 @@ func (ms *MetaSelect) IntsX(ctx context.Context) []int { return v } -// Int returns a single int from selector. It is only allowed when selecting one field. +// Int returns a single int from a selector. It is only allowed when selecting one field. func (ms *MetaSelect) Int(ctx context.Context) (_ int, err error) { var v []int if v, err = ms.Ints(ctx); err != nil { @@ -841,7 +859,7 @@ func (ms *MetaSelect) IntX(ctx context.Context) int { return v } -// Float64s returns list of float64s from selector. It is only allowed when selecting one field. +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. func (ms *MetaSelect) Float64s(ctx context.Context) ([]float64, error) { if len(ms.fields) > 1 { return nil, errors.New("ent: MetaSelect.Float64s is not achievable when selecting more than 1 field") @@ -862,7 +880,7 @@ func (ms *MetaSelect) Float64sX(ctx context.Context) []float64 { return v } -// Float64 returns a single float64 from selector. It is only allowed when selecting one field. +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. func (ms *MetaSelect) Float64(ctx context.Context) (_ float64, err error) { var v []float64 if v, err = ms.Float64s(ctx); err != nil { @@ -888,7 +906,7 @@ func (ms *MetaSelect) Float64X(ctx context.Context) float64 { return v } -// Bools returns list of bools from selector. It is only allowed when selecting one field. +// Bools returns list of bools from a selector. It is only allowed when selecting one field. func (ms *MetaSelect) Bools(ctx context.Context) ([]bool, error) { if len(ms.fields) > 1 { return nil, errors.New("ent: MetaSelect.Bools is not achievable when selecting more than 1 field") @@ -909,7 +927,7 @@ func (ms *MetaSelect) BoolsX(ctx context.Context) []bool { return v } -// Bool returns a single bool from selector. It is only allowed when selecting one field. +// Bool returns a single bool from a selector. It is only allowed when selecting one field. func (ms *MetaSelect) Bool(ctx context.Context) (_ bool, err error) { var v []bool if v, err = ms.Bools(ctx); err != nil { @@ -936,11 +954,6 @@ func (ms *MetaSelect) BoolX(ctx context.Context) bool { } func (ms *MetaSelect) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range ms.fields { - if !meta.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for selection", f)} - } - } rows := &sql.Rows{} query, args := ms.sqlQuery().Query() if err := ms.driver.Query(ctx, query, args, rows); err != nil { diff --git a/pkg/database/ent/meta_update.go b/pkg/database/ent/meta_update.go index da5bf973d..5a2eaf610 100644 --- a/pkg/database/ent/meta_update.go +++ b/pkg/database/ent/meta_update.go @@ -18,24 +18,23 @@ import ( // MetaUpdate is the builder for updating Meta entities. type MetaUpdate struct { config - hooks []Hook - mutation *MetaMutation - predicates []predicate.Meta + hooks []Hook + mutation *MetaMutation } -// Where adds a new predicate for the builder. +// Where adds a new predicate for the MetaUpdate builder. func (mu *MetaUpdate) Where(ps ...predicate.Meta) *MetaUpdate { - mu.predicates = append(mu.predicates, ps...) + mu.mutation.predicates = append(mu.mutation.predicates, ps...) return mu } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (mu *MetaUpdate) SetCreatedAt(t time.Time) *MetaUpdate { mu.mutation.SetCreatedAt(t) return mu } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (mu *MetaUpdate) SetNillableCreatedAt(t *time.Time) *MetaUpdate { if t != nil { mu.SetCreatedAt(*t) @@ -43,13 +42,13 @@ func (mu *MetaUpdate) SetNillableCreatedAt(t *time.Time) *MetaUpdate { return mu } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (mu *MetaUpdate) SetUpdatedAt(t time.Time) *MetaUpdate { mu.mutation.SetUpdatedAt(t) return mu } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (mu *MetaUpdate) SetNillableUpdatedAt(t *time.Time) *MetaUpdate { if t != nil { mu.SetUpdatedAt(*t) @@ -57,25 +56,25 @@ func (mu *MetaUpdate) SetNillableUpdatedAt(t *time.Time) *MetaUpdate { return mu } -// SetKey sets the key field. +// SetKey sets the "key" field. func (mu *MetaUpdate) SetKey(s string) *MetaUpdate { mu.mutation.SetKey(s) return mu } -// SetValue sets the value field. +// SetValue sets the "value" field. func (mu *MetaUpdate) SetValue(s string) *MetaUpdate { mu.mutation.SetValue(s) return mu } -// SetOwnerID sets the owner edge to Alert by id. +// SetOwnerID sets the "owner" edge to the Alert entity by ID. func (mu *MetaUpdate) SetOwnerID(id int) *MetaUpdate { mu.mutation.SetOwnerID(id) return mu } -// SetNillableOwnerID sets the owner edge to Alert by id if the given value is not nil. +// SetNillableOwnerID sets the "owner" edge to the Alert entity by ID if the given value is not nil. func (mu *MetaUpdate) SetNillableOwnerID(id *int) *MetaUpdate { if id != nil { mu = mu.SetOwnerID(*id) @@ -83,7 +82,7 @@ func (mu *MetaUpdate) SetNillableOwnerID(id *int) *MetaUpdate { return mu } -// SetOwner sets the owner edge to Alert. +// SetOwner sets the "owner" edge to the Alert entity. func (mu *MetaUpdate) SetOwner(a *Alert) *MetaUpdate { return mu.SetOwnerID(a.ID) } @@ -93,13 +92,13 @@ func (mu *MetaUpdate) Mutation() *MetaMutation { return mu.mutation } -// ClearOwner clears the "owner" edge to type Alert. +// ClearOwner clears the "owner" edge to the Alert entity. func (mu *MetaUpdate) ClearOwner() *MetaUpdate { mu.mutation.ClearOwner() return mu } -// Save executes the query and returns the number of rows/vertices matched by this operation. +// Save executes the query and returns the number of nodes affected by the update operation. func (mu *MetaUpdate) Save(ctx context.Context) (int, error) { var ( err error @@ -177,7 +176,7 @@ func (mu *MetaUpdate) sqlSave(ctx context.Context) (n int, err error) { }, }, } - if ps := mu.predicates; len(ps) > 0 { + if ps := mu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) @@ -265,13 +264,13 @@ type MetaUpdateOne struct { mutation *MetaMutation } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (muo *MetaUpdateOne) SetCreatedAt(t time.Time) *MetaUpdateOne { muo.mutation.SetCreatedAt(t) return muo } -// SetNillableCreatedAt sets the created_at field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (muo *MetaUpdateOne) SetNillableCreatedAt(t *time.Time) *MetaUpdateOne { if t != nil { muo.SetCreatedAt(*t) @@ -279,13 +278,13 @@ func (muo *MetaUpdateOne) SetNillableCreatedAt(t *time.Time) *MetaUpdateOne { return muo } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (muo *MetaUpdateOne) SetUpdatedAt(t time.Time) *MetaUpdateOne { muo.mutation.SetUpdatedAt(t) return muo } -// SetNillableUpdatedAt sets the updated_at field if the given value is not nil. +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (muo *MetaUpdateOne) SetNillableUpdatedAt(t *time.Time) *MetaUpdateOne { if t != nil { muo.SetUpdatedAt(*t) @@ -293,25 +292,25 @@ func (muo *MetaUpdateOne) SetNillableUpdatedAt(t *time.Time) *MetaUpdateOne { return muo } -// SetKey sets the key field. +// SetKey sets the "key" field. func (muo *MetaUpdateOne) SetKey(s string) *MetaUpdateOne { muo.mutation.SetKey(s) return muo } -// SetValue sets the value field. +// SetValue sets the "value" field. func (muo *MetaUpdateOne) SetValue(s string) *MetaUpdateOne { muo.mutation.SetValue(s) return muo } -// SetOwnerID sets the owner edge to Alert by id. +// SetOwnerID sets the "owner" edge to the Alert entity by ID. func (muo *MetaUpdateOne) SetOwnerID(id int) *MetaUpdateOne { muo.mutation.SetOwnerID(id) return muo } -// SetNillableOwnerID sets the owner edge to Alert by id if the given value is not nil. +// SetNillableOwnerID sets the "owner" edge to the Alert entity by ID if the given value is not nil. func (muo *MetaUpdateOne) SetNillableOwnerID(id *int) *MetaUpdateOne { if id != nil { muo = muo.SetOwnerID(*id) @@ -319,7 +318,7 @@ func (muo *MetaUpdateOne) SetNillableOwnerID(id *int) *MetaUpdateOne { return muo } -// SetOwner sets the owner edge to Alert. +// SetOwner sets the "owner" edge to the Alert entity. func (muo *MetaUpdateOne) SetOwner(a *Alert) *MetaUpdateOne { return muo.SetOwnerID(a.ID) } @@ -329,13 +328,13 @@ func (muo *MetaUpdateOne) Mutation() *MetaMutation { return muo.mutation } -// ClearOwner clears the "owner" edge to type Alert. +// ClearOwner clears the "owner" edge to the Alert entity. func (muo *MetaUpdateOne) ClearOwner() *MetaUpdateOne { muo.mutation.ClearOwner() return muo } -// Save executes the query and returns the updated entity. +// Save executes the query and returns the updated Meta entity. func (muo *MetaUpdateOne) Save(ctx context.Context) (*Meta, error) { var ( err error @@ -483,7 +482,7 @@ func (muo *MetaUpdateOne) sqlSave(ctx context.Context) (_node *Meta, err error) } _node = &Meta{config: muo.config} _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues() + _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{meta.Label} diff --git a/pkg/database/ent/migrate/migrate.go b/pkg/database/ent/migrate/migrate.go index 7e1d225b9..e9867dd13 100644 --- a/pkg/database/ent/migrate/migrate.go +++ b/pkg/database/ent/migrate/migrate.go @@ -31,6 +31,8 @@ var ( // WithFixture sets the foreign-key renaming option to the migration when upgrading // ent from v0.1.0 (issue-#285). Defaults to false. WithFixture = schema.WithFixture + // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. + WithForeignKeys = schema.WithForeignKeys ) // Schema is the API for creating, migrating and dropping a schema. diff --git a/pkg/database/ent/migrate/schema.go b/pkg/database/ent/migrate/schema.go index cea75ced2..e58446214 100644 --- a/pkg/database/ent/migrate/schema.go +++ b/pkg/database/ent/migrate/schema.go @@ -81,6 +81,9 @@ var ( {Name: "type", Type: field.TypeString}, {Name: "start_ip", Type: field.TypeInt64, Nullable: true}, {Name: "end_ip", Type: field.TypeInt64, Nullable: true}, + {Name: "start_suffix", Type: field.TypeInt64, Nullable: true}, + {Name: "end_suffix", Type: field.TypeInt64, Nullable: true}, + {Name: "ip_size", Type: field.TypeInt64, Nullable: true}, {Name: "scope", Type: field.TypeString}, {Name: "value", Type: field.TypeString}, {Name: "origin", Type: field.TypeString}, @@ -95,7 +98,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "decisions_alerts_decisions", - Columns: []*schema.Column{DecisionsColumns[12]}, + Columns: []*schema.Column{DecisionsColumns[15]}, RefColumns: []*schema.Column{AlertsColumns[0]}, OnDelete: schema.SetNull, diff --git a/pkg/database/ent/mutation.go b/pkg/database/ent/mutation.go index 059d7d738..25811c04b 100644 --- a/pkg/database/ent/mutation.go +++ b/pkg/database/ent/mutation.go @@ -14,6 +14,7 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/database/ent/event" "github.com/crowdsecurity/crowdsec/pkg/database/ent/machine" "github.com/crowdsecurity/crowdsec/pkg/database/ent/meta" + "github.com/crowdsecurity/crowdsec/pkg/database/ent/predicate" "github.com/facebook/ent" ) @@ -35,8 +36,7 @@ const ( TypeMeta = "Meta" ) -// AlertMutation represents an operation that mutate the Alerts -// nodes in the graph. +// AlertMutation represents an operation that mutates the Alert nodes in the graph. type AlertMutation struct { config op Op @@ -82,14 +82,15 @@ type AlertMutation struct { clearedmetas bool done bool oldValue func(context.Context) (*Alert, error) + predicates []predicate.Alert } var _ ent.Mutation = (*AlertMutation)(nil) -// alertOption allows to manage the mutation configuration using functional options. +// alertOption allows management of the mutation configuration using functional options. type alertOption func(*AlertMutation) -// newAlertMutation creates new mutation for $n.Name. +// newAlertMutation creates new mutation for the Alert entity. func newAlertMutation(c config, op Op, opts ...alertOption) *AlertMutation { m := &AlertMutation{ config: c, @@ -103,7 +104,7 @@ func newAlertMutation(c config, op Op, opts ...alertOption) *AlertMutation { return m } -// withAlertID sets the id field of the mutation. +// withAlertID sets the ID field of the mutation. func withAlertID(id int) alertOption { return func(m *AlertMutation) { var ( @@ -154,8 +155,8 @@ func (m AlertMutation) Tx() (*Tx, error) { return tx, nil } -// ID returns the id value in the mutation. Note that, the id -// is available only if it was provided to the builder. +// ID returns the ID value in the mutation. Note that the ID +// is only available if it was provided to the builder. func (m *AlertMutation) ID() (id int, exists bool) { if m.id == nil { return @@ -163,12 +164,12 @@ func (m *AlertMutation) ID() (id int, exists bool) { return *m.id, true } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (m *AlertMutation) SetCreatedAt(t time.Time) { m.created_at = &t } -// CreatedAt returns the created_at value in the mutation. +// CreatedAt returns the value of the "created_at" field in the mutation. func (m *AlertMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { @@ -177,13 +178,12 @@ func (m *AlertMutation) CreatedAt() (r time.Time, exists bool) { return *v, true } -// OldCreatedAt returns the old created_at value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldCreatedAt returns the old "created_at" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") @@ -195,17 +195,17 @@ func (m *AlertMutation) OldCreatedAt(ctx context.Context) (v time.Time, err erro return oldValue.CreatedAt, nil } -// ResetCreatedAt reset all changes of the "created_at" field. +// ResetCreatedAt resets all changes to the "created_at" field. func (m *AlertMutation) ResetCreatedAt() { m.created_at = nil } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (m *AlertMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } -// UpdatedAt returns the updated_at value in the mutation. +// UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *AlertMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { @@ -214,13 +214,12 @@ func (m *AlertMutation) UpdatedAt() (r time.Time, exists bool) { return *v, true } -// OldUpdatedAt returns the old updated_at value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldUpdatedAt returns the old "updated_at" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") @@ -232,17 +231,17 @@ func (m *AlertMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err erro return oldValue.UpdatedAt, nil } -// ResetUpdatedAt reset all changes of the "updated_at" field. +// ResetUpdatedAt resets all changes to the "updated_at" field. func (m *AlertMutation) ResetUpdatedAt() { m.updated_at = nil } -// SetScenario sets the scenario field. +// SetScenario sets the "scenario" field. func (m *AlertMutation) SetScenario(s string) { m.scenario = &s } -// Scenario returns the scenario value in the mutation. +// Scenario returns the value of the "scenario" field in the mutation. func (m *AlertMutation) Scenario() (r string, exists bool) { v := m.scenario if v == nil { @@ -251,13 +250,12 @@ func (m *AlertMutation) Scenario() (r string, exists bool) { return *v, true } -// OldScenario returns the old scenario value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldScenario returns the old "scenario" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldScenario(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldScenario is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldScenario is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldScenario requires an ID field in the mutation") @@ -269,17 +267,17 @@ func (m *AlertMutation) OldScenario(ctx context.Context) (v string, err error) { return oldValue.Scenario, nil } -// ResetScenario reset all changes of the "scenario" field. +// ResetScenario resets all changes to the "scenario" field. func (m *AlertMutation) ResetScenario() { m.scenario = nil } -// SetBucketId sets the bucketId field. +// SetBucketId sets the "bucketId" field. func (m *AlertMutation) SetBucketId(s string) { m.bucketId = &s } -// BucketId returns the bucketId value in the mutation. +// BucketId returns the value of the "bucketId" field in the mutation. func (m *AlertMutation) BucketId() (r string, exists bool) { v := m.bucketId if v == nil { @@ -288,13 +286,12 @@ func (m *AlertMutation) BucketId() (r string, exists bool) { return *v, true } -// OldBucketId returns the old bucketId value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldBucketId returns the old "bucketId" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldBucketId(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldBucketId is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldBucketId is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldBucketId requires an ID field in the mutation") @@ -306,30 +303,30 @@ func (m *AlertMutation) OldBucketId(ctx context.Context) (v string, err error) { return oldValue.BucketId, nil } -// ClearBucketId clears the value of bucketId. +// ClearBucketId clears the value of the "bucketId" field. func (m *AlertMutation) ClearBucketId() { m.bucketId = nil m.clearedFields[alert.FieldBucketId] = struct{}{} } -// BucketIdCleared returns if the field bucketId was cleared in this mutation. +// BucketIdCleared returns if the "bucketId" field was cleared in this mutation. func (m *AlertMutation) BucketIdCleared() bool { _, ok := m.clearedFields[alert.FieldBucketId] return ok } -// ResetBucketId reset all changes of the "bucketId" field. +// ResetBucketId resets all changes to the "bucketId" field. func (m *AlertMutation) ResetBucketId() { m.bucketId = nil delete(m.clearedFields, alert.FieldBucketId) } -// SetMessage sets the message field. +// SetMessage sets the "message" field. func (m *AlertMutation) SetMessage(s string) { m.message = &s } -// Message returns the message value in the mutation. +// Message returns the value of the "message" field in the mutation. func (m *AlertMutation) Message() (r string, exists bool) { v := m.message if v == nil { @@ -338,13 +335,12 @@ func (m *AlertMutation) Message() (r string, exists bool) { return *v, true } -// OldMessage returns the old message value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldMessage returns the old "message" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldMessage(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldMessage is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldMessage is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldMessage requires an ID field in the mutation") @@ -356,31 +352,31 @@ func (m *AlertMutation) OldMessage(ctx context.Context) (v string, err error) { return oldValue.Message, nil } -// ClearMessage clears the value of message. +// ClearMessage clears the value of the "message" field. func (m *AlertMutation) ClearMessage() { m.message = nil m.clearedFields[alert.FieldMessage] = struct{}{} } -// MessageCleared returns if the field message was cleared in this mutation. +// MessageCleared returns if the "message" field was cleared in this mutation. func (m *AlertMutation) MessageCleared() bool { _, ok := m.clearedFields[alert.FieldMessage] return ok } -// ResetMessage reset all changes of the "message" field. +// ResetMessage resets all changes to the "message" field. func (m *AlertMutation) ResetMessage() { m.message = nil delete(m.clearedFields, alert.FieldMessage) } -// SetEventsCount sets the eventsCount field. +// SetEventsCount sets the "eventsCount" field. func (m *AlertMutation) SetEventsCount(i int32) { m.eventsCount = &i m.addeventsCount = nil } -// EventsCount returns the eventsCount value in the mutation. +// EventsCount returns the value of the "eventsCount" field in the mutation. func (m *AlertMutation) EventsCount() (r int32, exists bool) { v := m.eventsCount if v == nil { @@ -389,13 +385,12 @@ func (m *AlertMutation) EventsCount() (r int32, exists bool) { return *v, true } -// OldEventsCount returns the old eventsCount value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldEventsCount returns the old "eventsCount" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldEventsCount(ctx context.Context) (v int32, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldEventsCount is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldEventsCount is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldEventsCount requires an ID field in the mutation") @@ -407,7 +402,7 @@ func (m *AlertMutation) OldEventsCount(ctx context.Context) (v int32, err error) return oldValue.EventsCount, nil } -// AddEventsCount adds i to eventsCount. +// AddEventsCount adds i to the "eventsCount" field. func (m *AlertMutation) AddEventsCount(i int32) { if m.addeventsCount != nil { *m.addeventsCount += i @@ -416,7 +411,7 @@ func (m *AlertMutation) AddEventsCount(i int32) { } } -// AddedEventsCount returns the value that was added to the eventsCount field in this mutation. +// AddedEventsCount returns the value that was added to the "eventsCount" field in this mutation. func (m *AlertMutation) AddedEventsCount() (r int32, exists bool) { v := m.addeventsCount if v == nil { @@ -425,32 +420,32 @@ func (m *AlertMutation) AddedEventsCount() (r int32, exists bool) { return *v, true } -// ClearEventsCount clears the value of eventsCount. +// ClearEventsCount clears the value of the "eventsCount" field. func (m *AlertMutation) ClearEventsCount() { m.eventsCount = nil m.addeventsCount = nil m.clearedFields[alert.FieldEventsCount] = struct{}{} } -// EventsCountCleared returns if the field eventsCount was cleared in this mutation. +// EventsCountCleared returns if the "eventsCount" field was cleared in this mutation. func (m *AlertMutation) EventsCountCleared() bool { _, ok := m.clearedFields[alert.FieldEventsCount] return ok } -// ResetEventsCount reset all changes of the "eventsCount" field. +// ResetEventsCount resets all changes to the "eventsCount" field. func (m *AlertMutation) ResetEventsCount() { m.eventsCount = nil m.addeventsCount = nil delete(m.clearedFields, alert.FieldEventsCount) } -// SetStartedAt sets the startedAt field. +// SetStartedAt sets the "startedAt" field. func (m *AlertMutation) SetStartedAt(t time.Time) { m.startedAt = &t } -// StartedAt returns the startedAt value in the mutation. +// StartedAt returns the value of the "startedAt" field in the mutation. func (m *AlertMutation) StartedAt() (r time.Time, exists bool) { v := m.startedAt if v == nil { @@ -459,13 +454,12 @@ func (m *AlertMutation) StartedAt() (r time.Time, exists bool) { return *v, true } -// OldStartedAt returns the old startedAt value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldStartedAt returns the old "startedAt" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldStartedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldStartedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldStartedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldStartedAt requires an ID field in the mutation") @@ -477,30 +471,30 @@ func (m *AlertMutation) OldStartedAt(ctx context.Context) (v time.Time, err erro return oldValue.StartedAt, nil } -// ClearStartedAt clears the value of startedAt. +// ClearStartedAt clears the value of the "startedAt" field. func (m *AlertMutation) ClearStartedAt() { m.startedAt = nil m.clearedFields[alert.FieldStartedAt] = struct{}{} } -// StartedAtCleared returns if the field startedAt was cleared in this mutation. +// StartedAtCleared returns if the "startedAt" field was cleared in this mutation. func (m *AlertMutation) StartedAtCleared() bool { _, ok := m.clearedFields[alert.FieldStartedAt] return ok } -// ResetStartedAt reset all changes of the "startedAt" field. +// ResetStartedAt resets all changes to the "startedAt" field. func (m *AlertMutation) ResetStartedAt() { m.startedAt = nil delete(m.clearedFields, alert.FieldStartedAt) } -// SetStoppedAt sets the stoppedAt field. +// SetStoppedAt sets the "stoppedAt" field. func (m *AlertMutation) SetStoppedAt(t time.Time) { m.stoppedAt = &t } -// StoppedAt returns the stoppedAt value in the mutation. +// StoppedAt returns the value of the "stoppedAt" field in the mutation. func (m *AlertMutation) StoppedAt() (r time.Time, exists bool) { v := m.stoppedAt if v == nil { @@ -509,13 +503,12 @@ func (m *AlertMutation) StoppedAt() (r time.Time, exists bool) { return *v, true } -// OldStoppedAt returns the old stoppedAt value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldStoppedAt returns the old "stoppedAt" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldStoppedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldStoppedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldStoppedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldStoppedAt requires an ID field in the mutation") @@ -527,30 +520,30 @@ func (m *AlertMutation) OldStoppedAt(ctx context.Context) (v time.Time, err erro return oldValue.StoppedAt, nil } -// ClearStoppedAt clears the value of stoppedAt. +// ClearStoppedAt clears the value of the "stoppedAt" field. func (m *AlertMutation) ClearStoppedAt() { m.stoppedAt = nil m.clearedFields[alert.FieldStoppedAt] = struct{}{} } -// StoppedAtCleared returns if the field stoppedAt was cleared in this mutation. +// StoppedAtCleared returns if the "stoppedAt" field was cleared in this mutation. func (m *AlertMutation) StoppedAtCleared() bool { _, ok := m.clearedFields[alert.FieldStoppedAt] return ok } -// ResetStoppedAt reset all changes of the "stoppedAt" field. +// ResetStoppedAt resets all changes to the "stoppedAt" field. func (m *AlertMutation) ResetStoppedAt() { m.stoppedAt = nil delete(m.clearedFields, alert.FieldStoppedAt) } -// SetSourceIp sets the sourceIp field. +// SetSourceIp sets the "sourceIp" field. func (m *AlertMutation) SetSourceIp(s string) { m.sourceIp = &s } -// SourceIp returns the sourceIp value in the mutation. +// SourceIp returns the value of the "sourceIp" field in the mutation. func (m *AlertMutation) SourceIp() (r string, exists bool) { v := m.sourceIp if v == nil { @@ -559,13 +552,12 @@ func (m *AlertMutation) SourceIp() (r string, exists bool) { return *v, true } -// OldSourceIp returns the old sourceIp value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldSourceIp returns the old "sourceIp" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldSourceIp(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSourceIp is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldSourceIp is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldSourceIp requires an ID field in the mutation") @@ -577,30 +569,30 @@ func (m *AlertMutation) OldSourceIp(ctx context.Context) (v string, err error) { return oldValue.SourceIp, nil } -// ClearSourceIp clears the value of sourceIp. +// ClearSourceIp clears the value of the "sourceIp" field. func (m *AlertMutation) ClearSourceIp() { m.sourceIp = nil m.clearedFields[alert.FieldSourceIp] = struct{}{} } -// SourceIpCleared returns if the field sourceIp was cleared in this mutation. +// SourceIpCleared returns if the "sourceIp" field was cleared in this mutation. func (m *AlertMutation) SourceIpCleared() bool { _, ok := m.clearedFields[alert.FieldSourceIp] return ok } -// ResetSourceIp reset all changes of the "sourceIp" field. +// ResetSourceIp resets all changes to the "sourceIp" field. func (m *AlertMutation) ResetSourceIp() { m.sourceIp = nil delete(m.clearedFields, alert.FieldSourceIp) } -// SetSourceRange sets the sourceRange field. +// SetSourceRange sets the "sourceRange" field. func (m *AlertMutation) SetSourceRange(s string) { m.sourceRange = &s } -// SourceRange returns the sourceRange value in the mutation. +// SourceRange returns the value of the "sourceRange" field in the mutation. func (m *AlertMutation) SourceRange() (r string, exists bool) { v := m.sourceRange if v == nil { @@ -609,13 +601,12 @@ func (m *AlertMutation) SourceRange() (r string, exists bool) { return *v, true } -// OldSourceRange returns the old sourceRange value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldSourceRange returns the old "sourceRange" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldSourceRange(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSourceRange is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldSourceRange is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldSourceRange requires an ID field in the mutation") @@ -627,30 +618,30 @@ func (m *AlertMutation) OldSourceRange(ctx context.Context) (v string, err error return oldValue.SourceRange, nil } -// ClearSourceRange clears the value of sourceRange. +// ClearSourceRange clears the value of the "sourceRange" field. func (m *AlertMutation) ClearSourceRange() { m.sourceRange = nil m.clearedFields[alert.FieldSourceRange] = struct{}{} } -// SourceRangeCleared returns if the field sourceRange was cleared in this mutation. +// SourceRangeCleared returns if the "sourceRange" field was cleared in this mutation. func (m *AlertMutation) SourceRangeCleared() bool { _, ok := m.clearedFields[alert.FieldSourceRange] return ok } -// ResetSourceRange reset all changes of the "sourceRange" field. +// ResetSourceRange resets all changes to the "sourceRange" field. func (m *AlertMutation) ResetSourceRange() { m.sourceRange = nil delete(m.clearedFields, alert.FieldSourceRange) } -// SetSourceAsNumber sets the sourceAsNumber field. +// SetSourceAsNumber sets the "sourceAsNumber" field. func (m *AlertMutation) SetSourceAsNumber(s string) { m.sourceAsNumber = &s } -// SourceAsNumber returns the sourceAsNumber value in the mutation. +// SourceAsNumber returns the value of the "sourceAsNumber" field in the mutation. func (m *AlertMutation) SourceAsNumber() (r string, exists bool) { v := m.sourceAsNumber if v == nil { @@ -659,13 +650,12 @@ func (m *AlertMutation) SourceAsNumber() (r string, exists bool) { return *v, true } -// OldSourceAsNumber returns the old sourceAsNumber value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldSourceAsNumber returns the old "sourceAsNumber" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldSourceAsNumber(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSourceAsNumber is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldSourceAsNumber is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldSourceAsNumber requires an ID field in the mutation") @@ -677,30 +667,30 @@ func (m *AlertMutation) OldSourceAsNumber(ctx context.Context) (v string, err er return oldValue.SourceAsNumber, nil } -// ClearSourceAsNumber clears the value of sourceAsNumber. +// ClearSourceAsNumber clears the value of the "sourceAsNumber" field. func (m *AlertMutation) ClearSourceAsNumber() { m.sourceAsNumber = nil m.clearedFields[alert.FieldSourceAsNumber] = struct{}{} } -// SourceAsNumberCleared returns if the field sourceAsNumber was cleared in this mutation. +// SourceAsNumberCleared returns if the "sourceAsNumber" field was cleared in this mutation. func (m *AlertMutation) SourceAsNumberCleared() bool { _, ok := m.clearedFields[alert.FieldSourceAsNumber] return ok } -// ResetSourceAsNumber reset all changes of the "sourceAsNumber" field. +// ResetSourceAsNumber resets all changes to the "sourceAsNumber" field. func (m *AlertMutation) ResetSourceAsNumber() { m.sourceAsNumber = nil delete(m.clearedFields, alert.FieldSourceAsNumber) } -// SetSourceAsName sets the sourceAsName field. +// SetSourceAsName sets the "sourceAsName" field. func (m *AlertMutation) SetSourceAsName(s string) { m.sourceAsName = &s } -// SourceAsName returns the sourceAsName value in the mutation. +// SourceAsName returns the value of the "sourceAsName" field in the mutation. func (m *AlertMutation) SourceAsName() (r string, exists bool) { v := m.sourceAsName if v == nil { @@ -709,13 +699,12 @@ func (m *AlertMutation) SourceAsName() (r string, exists bool) { return *v, true } -// OldSourceAsName returns the old sourceAsName value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldSourceAsName returns the old "sourceAsName" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldSourceAsName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSourceAsName is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldSourceAsName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldSourceAsName requires an ID field in the mutation") @@ -727,30 +716,30 @@ func (m *AlertMutation) OldSourceAsName(ctx context.Context) (v string, err erro return oldValue.SourceAsName, nil } -// ClearSourceAsName clears the value of sourceAsName. +// ClearSourceAsName clears the value of the "sourceAsName" field. func (m *AlertMutation) ClearSourceAsName() { m.sourceAsName = nil m.clearedFields[alert.FieldSourceAsName] = struct{}{} } -// SourceAsNameCleared returns if the field sourceAsName was cleared in this mutation. +// SourceAsNameCleared returns if the "sourceAsName" field was cleared in this mutation. func (m *AlertMutation) SourceAsNameCleared() bool { _, ok := m.clearedFields[alert.FieldSourceAsName] return ok } -// ResetSourceAsName reset all changes of the "sourceAsName" field. +// ResetSourceAsName resets all changes to the "sourceAsName" field. func (m *AlertMutation) ResetSourceAsName() { m.sourceAsName = nil delete(m.clearedFields, alert.FieldSourceAsName) } -// SetSourceCountry sets the sourceCountry field. +// SetSourceCountry sets the "sourceCountry" field. func (m *AlertMutation) SetSourceCountry(s string) { m.sourceCountry = &s } -// SourceCountry returns the sourceCountry value in the mutation. +// SourceCountry returns the value of the "sourceCountry" field in the mutation. func (m *AlertMutation) SourceCountry() (r string, exists bool) { v := m.sourceCountry if v == nil { @@ -759,13 +748,12 @@ func (m *AlertMutation) SourceCountry() (r string, exists bool) { return *v, true } -// OldSourceCountry returns the old sourceCountry value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldSourceCountry returns the old "sourceCountry" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldSourceCountry(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSourceCountry is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldSourceCountry is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldSourceCountry requires an ID field in the mutation") @@ -777,31 +765,31 @@ func (m *AlertMutation) OldSourceCountry(ctx context.Context) (v string, err err return oldValue.SourceCountry, nil } -// ClearSourceCountry clears the value of sourceCountry. +// ClearSourceCountry clears the value of the "sourceCountry" field. func (m *AlertMutation) ClearSourceCountry() { m.sourceCountry = nil m.clearedFields[alert.FieldSourceCountry] = struct{}{} } -// SourceCountryCleared returns if the field sourceCountry was cleared in this mutation. +// SourceCountryCleared returns if the "sourceCountry" field was cleared in this mutation. func (m *AlertMutation) SourceCountryCleared() bool { _, ok := m.clearedFields[alert.FieldSourceCountry] return ok } -// ResetSourceCountry reset all changes of the "sourceCountry" field. +// ResetSourceCountry resets all changes to the "sourceCountry" field. func (m *AlertMutation) ResetSourceCountry() { m.sourceCountry = nil delete(m.clearedFields, alert.FieldSourceCountry) } -// SetSourceLatitude sets the sourceLatitude field. +// SetSourceLatitude sets the "sourceLatitude" field. func (m *AlertMutation) SetSourceLatitude(f float32) { m.sourceLatitude = &f m.addsourceLatitude = nil } -// SourceLatitude returns the sourceLatitude value in the mutation. +// SourceLatitude returns the value of the "sourceLatitude" field in the mutation. func (m *AlertMutation) SourceLatitude() (r float32, exists bool) { v := m.sourceLatitude if v == nil { @@ -810,13 +798,12 @@ func (m *AlertMutation) SourceLatitude() (r float32, exists bool) { return *v, true } -// OldSourceLatitude returns the old sourceLatitude value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldSourceLatitude returns the old "sourceLatitude" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldSourceLatitude(ctx context.Context) (v float32, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSourceLatitude is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldSourceLatitude is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldSourceLatitude requires an ID field in the mutation") @@ -828,7 +815,7 @@ func (m *AlertMutation) OldSourceLatitude(ctx context.Context) (v float32, err e return oldValue.SourceLatitude, nil } -// AddSourceLatitude adds f to sourceLatitude. +// AddSourceLatitude adds f to the "sourceLatitude" field. func (m *AlertMutation) AddSourceLatitude(f float32) { if m.addsourceLatitude != nil { *m.addsourceLatitude += f @@ -837,7 +824,7 @@ func (m *AlertMutation) AddSourceLatitude(f float32) { } } -// AddedSourceLatitude returns the value that was added to the sourceLatitude field in this mutation. +// AddedSourceLatitude returns the value that was added to the "sourceLatitude" field in this mutation. func (m *AlertMutation) AddedSourceLatitude() (r float32, exists bool) { v := m.addsourceLatitude if v == nil { @@ -846,33 +833,33 @@ func (m *AlertMutation) AddedSourceLatitude() (r float32, exists bool) { return *v, true } -// ClearSourceLatitude clears the value of sourceLatitude. +// ClearSourceLatitude clears the value of the "sourceLatitude" field. func (m *AlertMutation) ClearSourceLatitude() { m.sourceLatitude = nil m.addsourceLatitude = nil m.clearedFields[alert.FieldSourceLatitude] = struct{}{} } -// SourceLatitudeCleared returns if the field sourceLatitude was cleared in this mutation. +// SourceLatitudeCleared returns if the "sourceLatitude" field was cleared in this mutation. func (m *AlertMutation) SourceLatitudeCleared() bool { _, ok := m.clearedFields[alert.FieldSourceLatitude] return ok } -// ResetSourceLatitude reset all changes of the "sourceLatitude" field. +// ResetSourceLatitude resets all changes to the "sourceLatitude" field. func (m *AlertMutation) ResetSourceLatitude() { m.sourceLatitude = nil m.addsourceLatitude = nil delete(m.clearedFields, alert.FieldSourceLatitude) } -// SetSourceLongitude sets the sourceLongitude field. +// SetSourceLongitude sets the "sourceLongitude" field. func (m *AlertMutation) SetSourceLongitude(f float32) { m.sourceLongitude = &f m.addsourceLongitude = nil } -// SourceLongitude returns the sourceLongitude value in the mutation. +// SourceLongitude returns the value of the "sourceLongitude" field in the mutation. func (m *AlertMutation) SourceLongitude() (r float32, exists bool) { v := m.sourceLongitude if v == nil { @@ -881,13 +868,12 @@ func (m *AlertMutation) SourceLongitude() (r float32, exists bool) { return *v, true } -// OldSourceLongitude returns the old sourceLongitude value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldSourceLongitude returns the old "sourceLongitude" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldSourceLongitude(ctx context.Context) (v float32, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSourceLongitude is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldSourceLongitude is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldSourceLongitude requires an ID field in the mutation") @@ -899,7 +885,7 @@ func (m *AlertMutation) OldSourceLongitude(ctx context.Context) (v float32, err return oldValue.SourceLongitude, nil } -// AddSourceLongitude adds f to sourceLongitude. +// AddSourceLongitude adds f to the "sourceLongitude" field. func (m *AlertMutation) AddSourceLongitude(f float32) { if m.addsourceLongitude != nil { *m.addsourceLongitude += f @@ -908,7 +894,7 @@ func (m *AlertMutation) AddSourceLongitude(f float32) { } } -// AddedSourceLongitude returns the value that was added to the sourceLongitude field in this mutation. +// AddedSourceLongitude returns the value that was added to the "sourceLongitude" field in this mutation. func (m *AlertMutation) AddedSourceLongitude() (r float32, exists bool) { v := m.addsourceLongitude if v == nil { @@ -917,32 +903,32 @@ func (m *AlertMutation) AddedSourceLongitude() (r float32, exists bool) { return *v, true } -// ClearSourceLongitude clears the value of sourceLongitude. +// ClearSourceLongitude clears the value of the "sourceLongitude" field. func (m *AlertMutation) ClearSourceLongitude() { m.sourceLongitude = nil m.addsourceLongitude = nil m.clearedFields[alert.FieldSourceLongitude] = struct{}{} } -// SourceLongitudeCleared returns if the field sourceLongitude was cleared in this mutation. +// SourceLongitudeCleared returns if the "sourceLongitude" field was cleared in this mutation. func (m *AlertMutation) SourceLongitudeCleared() bool { _, ok := m.clearedFields[alert.FieldSourceLongitude] return ok } -// ResetSourceLongitude reset all changes of the "sourceLongitude" field. +// ResetSourceLongitude resets all changes to the "sourceLongitude" field. func (m *AlertMutation) ResetSourceLongitude() { m.sourceLongitude = nil m.addsourceLongitude = nil delete(m.clearedFields, alert.FieldSourceLongitude) } -// SetSourceScope sets the sourceScope field. +// SetSourceScope sets the "sourceScope" field. func (m *AlertMutation) SetSourceScope(s string) { m.sourceScope = &s } -// SourceScope returns the sourceScope value in the mutation. +// SourceScope returns the value of the "sourceScope" field in the mutation. func (m *AlertMutation) SourceScope() (r string, exists bool) { v := m.sourceScope if v == nil { @@ -951,13 +937,12 @@ func (m *AlertMutation) SourceScope() (r string, exists bool) { return *v, true } -// OldSourceScope returns the old sourceScope value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldSourceScope returns the old "sourceScope" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldSourceScope(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSourceScope is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldSourceScope is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldSourceScope requires an ID field in the mutation") @@ -969,30 +954,30 @@ func (m *AlertMutation) OldSourceScope(ctx context.Context) (v string, err error return oldValue.SourceScope, nil } -// ClearSourceScope clears the value of sourceScope. +// ClearSourceScope clears the value of the "sourceScope" field. func (m *AlertMutation) ClearSourceScope() { m.sourceScope = nil m.clearedFields[alert.FieldSourceScope] = struct{}{} } -// SourceScopeCleared returns if the field sourceScope was cleared in this mutation. +// SourceScopeCleared returns if the "sourceScope" field was cleared in this mutation. func (m *AlertMutation) SourceScopeCleared() bool { _, ok := m.clearedFields[alert.FieldSourceScope] return ok } -// ResetSourceScope reset all changes of the "sourceScope" field. +// ResetSourceScope resets all changes to the "sourceScope" field. func (m *AlertMutation) ResetSourceScope() { m.sourceScope = nil delete(m.clearedFields, alert.FieldSourceScope) } -// SetSourceValue sets the sourceValue field. +// SetSourceValue sets the "sourceValue" field. func (m *AlertMutation) SetSourceValue(s string) { m.sourceValue = &s } -// SourceValue returns the sourceValue value in the mutation. +// SourceValue returns the value of the "sourceValue" field in the mutation. func (m *AlertMutation) SourceValue() (r string, exists bool) { v := m.sourceValue if v == nil { @@ -1001,13 +986,12 @@ func (m *AlertMutation) SourceValue() (r string, exists bool) { return *v, true } -// OldSourceValue returns the old sourceValue value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldSourceValue returns the old "sourceValue" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldSourceValue(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSourceValue is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldSourceValue is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldSourceValue requires an ID field in the mutation") @@ -1019,31 +1003,31 @@ func (m *AlertMutation) OldSourceValue(ctx context.Context) (v string, err error return oldValue.SourceValue, nil } -// ClearSourceValue clears the value of sourceValue. +// ClearSourceValue clears the value of the "sourceValue" field. func (m *AlertMutation) ClearSourceValue() { m.sourceValue = nil m.clearedFields[alert.FieldSourceValue] = struct{}{} } -// SourceValueCleared returns if the field sourceValue was cleared in this mutation. +// SourceValueCleared returns if the "sourceValue" field was cleared in this mutation. func (m *AlertMutation) SourceValueCleared() bool { _, ok := m.clearedFields[alert.FieldSourceValue] return ok } -// ResetSourceValue reset all changes of the "sourceValue" field. +// ResetSourceValue resets all changes to the "sourceValue" field. func (m *AlertMutation) ResetSourceValue() { m.sourceValue = nil delete(m.clearedFields, alert.FieldSourceValue) } -// SetCapacity sets the capacity field. +// SetCapacity sets the "capacity" field. func (m *AlertMutation) SetCapacity(i int32) { m.capacity = &i m.addcapacity = nil } -// Capacity returns the capacity value in the mutation. +// Capacity returns the value of the "capacity" field in the mutation. func (m *AlertMutation) Capacity() (r int32, exists bool) { v := m.capacity if v == nil { @@ -1052,13 +1036,12 @@ func (m *AlertMutation) Capacity() (r int32, exists bool) { return *v, true } -// OldCapacity returns the old capacity value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldCapacity returns the old "capacity" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldCapacity(ctx context.Context) (v int32, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCapacity is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldCapacity is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldCapacity requires an ID field in the mutation") @@ -1070,7 +1053,7 @@ func (m *AlertMutation) OldCapacity(ctx context.Context) (v int32, err error) { return oldValue.Capacity, nil } -// AddCapacity adds i to capacity. +// AddCapacity adds i to the "capacity" field. func (m *AlertMutation) AddCapacity(i int32) { if m.addcapacity != nil { *m.addcapacity += i @@ -1079,7 +1062,7 @@ func (m *AlertMutation) AddCapacity(i int32) { } } -// AddedCapacity returns the value that was added to the capacity field in this mutation. +// AddedCapacity returns the value that was added to the "capacity" field in this mutation. func (m *AlertMutation) AddedCapacity() (r int32, exists bool) { v := m.addcapacity if v == nil { @@ -1088,32 +1071,32 @@ func (m *AlertMutation) AddedCapacity() (r int32, exists bool) { return *v, true } -// ClearCapacity clears the value of capacity. +// ClearCapacity clears the value of the "capacity" field. func (m *AlertMutation) ClearCapacity() { m.capacity = nil m.addcapacity = nil m.clearedFields[alert.FieldCapacity] = struct{}{} } -// CapacityCleared returns if the field capacity was cleared in this mutation. +// CapacityCleared returns if the "capacity" field was cleared in this mutation. func (m *AlertMutation) CapacityCleared() bool { _, ok := m.clearedFields[alert.FieldCapacity] return ok } -// ResetCapacity reset all changes of the "capacity" field. +// ResetCapacity resets all changes to the "capacity" field. func (m *AlertMutation) ResetCapacity() { m.capacity = nil m.addcapacity = nil delete(m.clearedFields, alert.FieldCapacity) } -// SetLeakSpeed sets the leakSpeed field. +// SetLeakSpeed sets the "leakSpeed" field. func (m *AlertMutation) SetLeakSpeed(s string) { m.leakSpeed = &s } -// LeakSpeed returns the leakSpeed value in the mutation. +// LeakSpeed returns the value of the "leakSpeed" field in the mutation. func (m *AlertMutation) LeakSpeed() (r string, exists bool) { v := m.leakSpeed if v == nil { @@ -1122,13 +1105,12 @@ func (m *AlertMutation) LeakSpeed() (r string, exists bool) { return *v, true } -// OldLeakSpeed returns the old leakSpeed value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldLeakSpeed returns the old "leakSpeed" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldLeakSpeed(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldLeakSpeed is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldLeakSpeed is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldLeakSpeed requires an ID field in the mutation") @@ -1140,30 +1122,30 @@ func (m *AlertMutation) OldLeakSpeed(ctx context.Context) (v string, err error) return oldValue.LeakSpeed, nil } -// ClearLeakSpeed clears the value of leakSpeed. +// ClearLeakSpeed clears the value of the "leakSpeed" field. func (m *AlertMutation) ClearLeakSpeed() { m.leakSpeed = nil m.clearedFields[alert.FieldLeakSpeed] = struct{}{} } -// LeakSpeedCleared returns if the field leakSpeed was cleared in this mutation. +// LeakSpeedCleared returns if the "leakSpeed" field was cleared in this mutation. func (m *AlertMutation) LeakSpeedCleared() bool { _, ok := m.clearedFields[alert.FieldLeakSpeed] return ok } -// ResetLeakSpeed reset all changes of the "leakSpeed" field. +// ResetLeakSpeed resets all changes to the "leakSpeed" field. func (m *AlertMutation) ResetLeakSpeed() { m.leakSpeed = nil delete(m.clearedFields, alert.FieldLeakSpeed) } -// SetScenarioVersion sets the scenarioVersion field. +// SetScenarioVersion sets the "scenarioVersion" field. func (m *AlertMutation) SetScenarioVersion(s string) { m.scenarioVersion = &s } -// ScenarioVersion returns the scenarioVersion value in the mutation. +// ScenarioVersion returns the value of the "scenarioVersion" field in the mutation. func (m *AlertMutation) ScenarioVersion() (r string, exists bool) { v := m.scenarioVersion if v == nil { @@ -1172,13 +1154,12 @@ func (m *AlertMutation) ScenarioVersion() (r string, exists bool) { return *v, true } -// OldScenarioVersion returns the old scenarioVersion value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldScenarioVersion returns the old "scenarioVersion" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldScenarioVersion(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldScenarioVersion is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldScenarioVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldScenarioVersion requires an ID field in the mutation") @@ -1190,30 +1171,30 @@ func (m *AlertMutation) OldScenarioVersion(ctx context.Context) (v string, err e return oldValue.ScenarioVersion, nil } -// ClearScenarioVersion clears the value of scenarioVersion. +// ClearScenarioVersion clears the value of the "scenarioVersion" field. func (m *AlertMutation) ClearScenarioVersion() { m.scenarioVersion = nil m.clearedFields[alert.FieldScenarioVersion] = struct{}{} } -// ScenarioVersionCleared returns if the field scenarioVersion was cleared in this mutation. +// ScenarioVersionCleared returns if the "scenarioVersion" field was cleared in this mutation. func (m *AlertMutation) ScenarioVersionCleared() bool { _, ok := m.clearedFields[alert.FieldScenarioVersion] return ok } -// ResetScenarioVersion reset all changes of the "scenarioVersion" field. +// ResetScenarioVersion resets all changes to the "scenarioVersion" field. func (m *AlertMutation) ResetScenarioVersion() { m.scenarioVersion = nil delete(m.clearedFields, alert.FieldScenarioVersion) } -// SetScenarioHash sets the scenarioHash field. +// SetScenarioHash sets the "scenarioHash" field. func (m *AlertMutation) SetScenarioHash(s string) { m.scenarioHash = &s } -// ScenarioHash returns the scenarioHash value in the mutation. +// ScenarioHash returns the value of the "scenarioHash" field in the mutation. func (m *AlertMutation) ScenarioHash() (r string, exists bool) { v := m.scenarioHash if v == nil { @@ -1222,13 +1203,12 @@ func (m *AlertMutation) ScenarioHash() (r string, exists bool) { return *v, true } -// OldScenarioHash returns the old scenarioHash value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldScenarioHash returns the old "scenarioHash" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldScenarioHash(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldScenarioHash is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldScenarioHash is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldScenarioHash requires an ID field in the mutation") @@ -1240,30 +1220,30 @@ func (m *AlertMutation) OldScenarioHash(ctx context.Context) (v string, err erro return oldValue.ScenarioHash, nil } -// ClearScenarioHash clears the value of scenarioHash. +// ClearScenarioHash clears the value of the "scenarioHash" field. func (m *AlertMutation) ClearScenarioHash() { m.scenarioHash = nil m.clearedFields[alert.FieldScenarioHash] = struct{}{} } -// ScenarioHashCleared returns if the field scenarioHash was cleared in this mutation. +// ScenarioHashCleared returns if the "scenarioHash" field was cleared in this mutation. func (m *AlertMutation) ScenarioHashCleared() bool { _, ok := m.clearedFields[alert.FieldScenarioHash] return ok } -// ResetScenarioHash reset all changes of the "scenarioHash" field. +// ResetScenarioHash resets all changes to the "scenarioHash" field. func (m *AlertMutation) ResetScenarioHash() { m.scenarioHash = nil delete(m.clearedFields, alert.FieldScenarioHash) } -// SetSimulated sets the simulated field. +// SetSimulated sets the "simulated" field. func (m *AlertMutation) SetSimulated(b bool) { m.simulated = &b } -// Simulated returns the simulated value in the mutation. +// Simulated returns the value of the "simulated" field in the mutation. func (m *AlertMutation) Simulated() (r bool, exists bool) { v := m.simulated if v == nil { @@ -1272,13 +1252,12 @@ func (m *AlertMutation) Simulated() (r bool, exists bool) { return *v, true } -// OldSimulated returns the old simulated value of the Alert. -// If the Alert object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldSimulated returns the old "simulated" field's value of the Alert entity. +// If the Alert object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AlertMutation) OldSimulated(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSimulated is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldSimulated is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldSimulated requires an ID field in the mutation") @@ -1290,27 +1269,27 @@ func (m *AlertMutation) OldSimulated(ctx context.Context) (v bool, err error) { return oldValue.Simulated, nil } -// ResetSimulated reset all changes of the "simulated" field. +// ResetSimulated resets all changes to the "simulated" field. func (m *AlertMutation) ResetSimulated() { m.simulated = nil } -// SetOwnerID sets the owner edge to Machine by id. +// SetOwnerID sets the "owner" edge to the Machine entity by id. func (m *AlertMutation) SetOwnerID(id int) { m.owner = &id } -// ClearOwner clears the owner edge to Machine. +// ClearOwner clears the "owner" edge to the Machine entity. func (m *AlertMutation) ClearOwner() { m.clearedowner = true } -// OwnerCleared returns if the edge owner was cleared. +// OwnerCleared returns if the "owner" edge to the Machine entity was cleared. func (m *AlertMutation) OwnerCleared() bool { return m.clearedowner } -// OwnerID returns the owner id in the mutation. +// OwnerID returns the "owner" edge ID in the mutation. func (m *AlertMutation) OwnerID() (id int, exists bool) { if m.owner != nil { return *m.owner, true @@ -1318,8 +1297,8 @@ func (m *AlertMutation) OwnerID() (id int, exists bool) { return } -// OwnerIDs returns the owner ids in the mutation. -// Note that ids always returns len(ids) <= 1 for unique edges, and you should use +// OwnerIDs returns the "owner" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // OwnerID instead. It exists only for internal usage by the builders. func (m *AlertMutation) OwnerIDs() (ids []int) { if id := m.owner; id != nil { @@ -1328,13 +1307,13 @@ func (m *AlertMutation) OwnerIDs() (ids []int) { return } -// ResetOwner reset all changes of the "owner" edge. +// ResetOwner resets all changes to the "owner" edge. func (m *AlertMutation) ResetOwner() { m.owner = nil m.clearedowner = false } -// AddDecisionIDs adds the decisions edge to Decision by ids. +// AddDecisionIDs adds the "decisions" edge to the Decision entity by ids. func (m *AlertMutation) AddDecisionIDs(ids ...int) { if m.decisions == nil { m.decisions = make(map[int]struct{}) @@ -1344,17 +1323,17 @@ func (m *AlertMutation) AddDecisionIDs(ids ...int) { } } -// ClearDecisions clears the decisions edge to Decision. +// ClearDecisions clears the "decisions" edge to the Decision entity. func (m *AlertMutation) ClearDecisions() { m.cleareddecisions = true } -// DecisionsCleared returns if the edge decisions was cleared. +// DecisionsCleared returns if the "decisions" edge to the Decision entity was cleared. func (m *AlertMutation) DecisionsCleared() bool { return m.cleareddecisions } -// RemoveDecisionIDs removes the decisions edge to Decision by ids. +// RemoveDecisionIDs removes the "decisions" edge to the Decision entity by IDs. func (m *AlertMutation) RemoveDecisionIDs(ids ...int) { if m.removeddecisions == nil { m.removeddecisions = make(map[int]struct{}) @@ -1364,7 +1343,7 @@ func (m *AlertMutation) RemoveDecisionIDs(ids ...int) { } } -// RemovedDecisions returns the removed ids of decisions. +// RemovedDecisions returns the removed IDs of the "decisions" edge to the Decision entity. func (m *AlertMutation) RemovedDecisionsIDs() (ids []int) { for id := range m.removeddecisions { ids = append(ids, id) @@ -1372,7 +1351,7 @@ func (m *AlertMutation) RemovedDecisionsIDs() (ids []int) { return } -// DecisionsIDs returns the decisions ids in the mutation. +// DecisionsIDs returns the "decisions" edge IDs in the mutation. func (m *AlertMutation) DecisionsIDs() (ids []int) { for id := range m.decisions { ids = append(ids, id) @@ -1380,14 +1359,14 @@ func (m *AlertMutation) DecisionsIDs() (ids []int) { return } -// ResetDecisions reset all changes of the "decisions" edge. +// ResetDecisions resets all changes to the "decisions" edge. func (m *AlertMutation) ResetDecisions() { m.decisions = nil m.cleareddecisions = false m.removeddecisions = nil } -// AddEventIDs adds the events edge to Event by ids. +// AddEventIDs adds the "events" edge to the Event entity by ids. func (m *AlertMutation) AddEventIDs(ids ...int) { if m.events == nil { m.events = make(map[int]struct{}) @@ -1397,17 +1376,17 @@ func (m *AlertMutation) AddEventIDs(ids ...int) { } } -// ClearEvents clears the events edge to Event. +// ClearEvents clears the "events" edge to the Event entity. func (m *AlertMutation) ClearEvents() { m.clearedevents = true } -// EventsCleared returns if the edge events was cleared. +// EventsCleared returns if the "events" edge to the Event entity was cleared. func (m *AlertMutation) EventsCleared() bool { return m.clearedevents } -// RemoveEventIDs removes the events edge to Event by ids. +// RemoveEventIDs removes the "events" edge to the Event entity by IDs. func (m *AlertMutation) RemoveEventIDs(ids ...int) { if m.removedevents == nil { m.removedevents = make(map[int]struct{}) @@ -1417,7 +1396,7 @@ func (m *AlertMutation) RemoveEventIDs(ids ...int) { } } -// RemovedEvents returns the removed ids of events. +// RemovedEvents returns the removed IDs of the "events" edge to the Event entity. func (m *AlertMutation) RemovedEventsIDs() (ids []int) { for id := range m.removedevents { ids = append(ids, id) @@ -1425,7 +1404,7 @@ func (m *AlertMutation) RemovedEventsIDs() (ids []int) { return } -// EventsIDs returns the events ids in the mutation. +// EventsIDs returns the "events" edge IDs in the mutation. func (m *AlertMutation) EventsIDs() (ids []int) { for id := range m.events { ids = append(ids, id) @@ -1433,14 +1412,14 @@ func (m *AlertMutation) EventsIDs() (ids []int) { return } -// ResetEvents reset all changes of the "events" edge. +// ResetEvents resets all changes to the "events" edge. func (m *AlertMutation) ResetEvents() { m.events = nil m.clearedevents = false m.removedevents = nil } -// AddMetaIDs adds the metas edge to Meta by ids. +// AddMetaIDs adds the "metas" edge to the Meta entity by ids. func (m *AlertMutation) AddMetaIDs(ids ...int) { if m.metas == nil { m.metas = make(map[int]struct{}) @@ -1450,17 +1429,17 @@ func (m *AlertMutation) AddMetaIDs(ids ...int) { } } -// ClearMetas clears the metas edge to Meta. +// ClearMetas clears the "metas" edge to the Meta entity. func (m *AlertMutation) ClearMetas() { m.clearedmetas = true } -// MetasCleared returns if the edge metas was cleared. +// MetasCleared returns if the "metas" edge to the Meta entity was cleared. func (m *AlertMutation) MetasCleared() bool { return m.clearedmetas } -// RemoveMetaIDs removes the metas edge to Meta by ids. +// RemoveMetaIDs removes the "metas" edge to the Meta entity by IDs. func (m *AlertMutation) RemoveMetaIDs(ids ...int) { if m.removedmetas == nil { m.removedmetas = make(map[int]struct{}) @@ -1470,7 +1449,7 @@ func (m *AlertMutation) RemoveMetaIDs(ids ...int) { } } -// RemovedMetas returns the removed ids of metas. +// RemovedMetas returns the removed IDs of the "metas" edge to the Meta entity. func (m *AlertMutation) RemovedMetasIDs() (ids []int) { for id := range m.removedmetas { ids = append(ids, id) @@ -1478,7 +1457,7 @@ func (m *AlertMutation) RemovedMetasIDs() (ids []int) { return } -// MetasIDs returns the metas ids in the mutation. +// MetasIDs returns the "metas" edge IDs in the mutation. func (m *AlertMutation) MetasIDs() (ids []int) { for id := range m.metas { ids = append(ids, id) @@ -1486,7 +1465,7 @@ func (m *AlertMutation) MetasIDs() (ids []int) { return } -// ResetMetas reset all changes of the "metas" edge. +// ResetMetas resets all changes to the "metas" edge. func (m *AlertMutation) ResetMetas() { m.metas = nil m.clearedmetas = false @@ -1503,9 +1482,9 @@ func (m *AlertMutation) Type() string { return m.typ } -// Fields returns all fields that were changed during -// this mutation. Note that, in order to get all numeric -// fields that were in/decremented, call AddedFields(). +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). func (m *AlertMutation) Fields() []string { fields := make([]string, 0, 22) if m.created_at != nil { @@ -1577,9 +1556,9 @@ func (m *AlertMutation) Fields() []string { return fields } -// Field returns the value of a field with the given name. -// The second boolean value indicates that this field was -// not set, or was not define in the schema. +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. func (m *AlertMutation) Field(name string) (ent.Value, bool) { switch name { case alert.FieldCreatedAt: @@ -1630,9 +1609,9 @@ func (m *AlertMutation) Field(name string) (ent.Value, bool) { return nil, false } -// OldField returns the old value of the field from the database. -// An error is returned if the mutation operation is not UpdateOne, -// or the query to the database was failed. +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. func (m *AlertMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case alert.FieldCreatedAt: @@ -1683,9 +1662,9 @@ func (m *AlertMutation) OldField(ctx context.Context, name string) (ent.Value, e return nil, fmt.Errorf("unknown Alert field %s", name) } -// SetField sets the value for the given name. It returns an -// error if the field is not defined in the schema, or if the -// type mismatch the field type. +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. func (m *AlertMutation) SetField(name string, value ent.Value) error { switch name { case alert.FieldCreatedAt: @@ -1846,8 +1825,8 @@ func (m *AlertMutation) SetField(name string, value ent.Value) error { return fmt.Errorf("unknown Alert field %s", name) } -// AddedFields returns all numeric fields that were incremented -// or decremented during this mutation. +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. func (m *AlertMutation) AddedFields() []string { var fields []string if m.addeventsCount != nil { @@ -1865,9 +1844,9 @@ func (m *AlertMutation) AddedFields() []string { return fields } -// AddedField returns the numeric value that was in/decremented -// from a field with the given name. The second value indicates -// that this field was not set, or was not define in the schema. +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. func (m *AlertMutation) AddedField(name string) (ent.Value, bool) { switch name { case alert.FieldEventsCount: @@ -1882,9 +1861,9 @@ func (m *AlertMutation) AddedField(name string) (ent.Value, bool) { return nil, false } -// AddField adds the value for the given name. It returns an -// error if the field is not defined in the schema, or if the -// type mismatch the field type. +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. func (m *AlertMutation) AddField(name string, value ent.Value) error { switch name { case alert.FieldEventsCount: @@ -1919,8 +1898,8 @@ func (m *AlertMutation) AddField(name string, value ent.Value) error { return fmt.Errorf("unknown Alert numeric field %s", name) } -// ClearedFields returns all nullable fields that were cleared -// during this mutation. +// ClearedFields returns all nullable fields that were cleared during this +// mutation. func (m *AlertMutation) ClearedFields() []string { var fields []string if m.FieldCleared(alert.FieldBucketId) { @@ -1980,14 +1959,14 @@ func (m *AlertMutation) ClearedFields() []string { return fields } -// FieldCleared returns a boolean indicates if this field was +// FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *AlertMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } -// ClearField clears the value for the given name. It returns an +// ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *AlertMutation) ClearField(name string) error { switch name { @@ -2049,9 +2028,8 @@ func (m *AlertMutation) ClearField(name string) error { return fmt.Errorf("unknown Alert nullable field %s", name) } -// ResetField resets all changes in the mutation regarding the -// given field name. It returns an error if the field is not -// defined in the schema. +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. func (m *AlertMutation) ResetField(name string) error { switch name { case alert.FieldCreatedAt: @@ -2124,8 +2102,7 @@ func (m *AlertMutation) ResetField(name string) error { return fmt.Errorf("unknown Alert field %s", name) } -// AddedEdges returns all edge names that were set/added in this -// mutation. +// AddedEdges returns all edge names that were set/added in this mutation. func (m *AlertMutation) AddedEdges() []string { edges := make([]string, 0, 4) if m.owner != nil { @@ -2143,8 +2120,8 @@ func (m *AlertMutation) AddedEdges() []string { return edges } -// AddedIDs returns all ids (to other nodes) that were added for -// the given edge name. +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. func (m *AlertMutation) AddedIDs(name string) []ent.Value { switch name { case alert.EdgeOwner: @@ -2173,8 +2150,7 @@ func (m *AlertMutation) AddedIDs(name string) []ent.Value { return nil } -// RemovedEdges returns all edge names that were removed in this -// mutation. +// RemovedEdges returns all edge names that were removed in this mutation. func (m *AlertMutation) RemovedEdges() []string { edges := make([]string, 0, 4) if m.removeddecisions != nil { @@ -2189,8 +2165,8 @@ func (m *AlertMutation) RemovedEdges() []string { return edges } -// RemovedIDs returns all ids (to other nodes) that were removed for -// the given edge name. +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. func (m *AlertMutation) RemovedIDs(name string) []ent.Value { switch name { case alert.EdgeDecisions: @@ -2215,8 +2191,7 @@ func (m *AlertMutation) RemovedIDs(name string) []ent.Value { return nil } -// ClearedEdges returns all edge names that were cleared in this -// mutation. +// ClearedEdges returns all edge names that were cleared in this mutation. func (m *AlertMutation) ClearedEdges() []string { edges := make([]string, 0, 4) if m.clearedowner { @@ -2234,8 +2209,8 @@ func (m *AlertMutation) ClearedEdges() []string { return edges } -// EdgeCleared returns a boolean indicates if this edge was -// cleared in this mutation. +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. func (m *AlertMutation) EdgeCleared(name string) bool { switch name { case alert.EdgeOwner: @@ -2250,8 +2225,8 @@ func (m *AlertMutation) EdgeCleared(name string) bool { return false } -// ClearEdge clears the value for the given name. It returns an -// error if the edge name is not defined in the schema. +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. func (m *AlertMutation) ClearEdge(name string) error { switch name { case alert.EdgeOwner: @@ -2261,9 +2236,8 @@ func (m *AlertMutation) ClearEdge(name string) error { return fmt.Errorf("unknown Alert unique edge %s", name) } -// ResetEdge resets all changes in the mutation regarding the -// given edge name. It returns an error if the edge is not -// defined in the schema. +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. func (m *AlertMutation) ResetEdge(name string) error { switch name { case alert.EdgeOwner: @@ -2282,8 +2256,7 @@ func (m *AlertMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Alert edge %s", name) } -// BouncerMutation represents an operation that mutate the Bouncers -// nodes in the graph. +// BouncerMutation represents an operation that mutates the Bouncer nodes in the graph. type BouncerMutation struct { config op Op @@ -2302,14 +2275,15 @@ type BouncerMutation struct { clearedFields map[string]struct{} done bool oldValue func(context.Context) (*Bouncer, error) + predicates []predicate.Bouncer } var _ ent.Mutation = (*BouncerMutation)(nil) -// bouncerOption allows to manage the mutation configuration using functional options. +// bouncerOption allows management of the mutation configuration using functional options. type bouncerOption func(*BouncerMutation) -// newBouncerMutation creates new mutation for $n.Name. +// newBouncerMutation creates new mutation for the Bouncer entity. func newBouncerMutation(c config, op Op, opts ...bouncerOption) *BouncerMutation { m := &BouncerMutation{ config: c, @@ -2323,7 +2297,7 @@ func newBouncerMutation(c config, op Op, opts ...bouncerOption) *BouncerMutation return m } -// withBouncerID sets the id field of the mutation. +// withBouncerID sets the ID field of the mutation. func withBouncerID(id int) bouncerOption { return func(m *BouncerMutation) { var ( @@ -2374,8 +2348,8 @@ func (m BouncerMutation) Tx() (*Tx, error) { return tx, nil } -// ID returns the id value in the mutation. Note that, the id -// is available only if it was provided to the builder. +// ID returns the ID value in the mutation. Note that the ID +// is only available if it was provided to the builder. func (m *BouncerMutation) ID() (id int, exists bool) { if m.id == nil { return @@ -2383,12 +2357,12 @@ func (m *BouncerMutation) ID() (id int, exists bool) { return *m.id, true } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (m *BouncerMutation) SetCreatedAt(t time.Time) { m.created_at = &t } -// CreatedAt returns the created_at value in the mutation. +// CreatedAt returns the value of the "created_at" field in the mutation. func (m *BouncerMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { @@ -2397,13 +2371,12 @@ func (m *BouncerMutation) CreatedAt() (r time.Time, exists bool) { return *v, true } -// OldCreatedAt returns the old created_at value of the Bouncer. -// If the Bouncer object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldCreatedAt returns the old "created_at" field's value of the Bouncer entity. +// If the Bouncer object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BouncerMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") @@ -2415,17 +2388,17 @@ func (m *BouncerMutation) OldCreatedAt(ctx context.Context) (v time.Time, err er return oldValue.CreatedAt, nil } -// ResetCreatedAt reset all changes of the "created_at" field. +// ResetCreatedAt resets all changes to the "created_at" field. func (m *BouncerMutation) ResetCreatedAt() { m.created_at = nil } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (m *BouncerMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } -// UpdatedAt returns the updated_at value in the mutation. +// UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *BouncerMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { @@ -2434,13 +2407,12 @@ func (m *BouncerMutation) UpdatedAt() (r time.Time, exists bool) { return *v, true } -// OldUpdatedAt returns the old updated_at value of the Bouncer. -// If the Bouncer object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldUpdatedAt returns the old "updated_at" field's value of the Bouncer entity. +// If the Bouncer object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BouncerMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") @@ -2452,17 +2424,17 @@ func (m *BouncerMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err er return oldValue.UpdatedAt, nil } -// ResetUpdatedAt reset all changes of the "updated_at" field. +// ResetUpdatedAt resets all changes to the "updated_at" field. func (m *BouncerMutation) ResetUpdatedAt() { m.updated_at = nil } -// SetName sets the name field. +// SetName sets the "name" field. func (m *BouncerMutation) SetName(s string) { m.name = &s } -// Name returns the name value in the mutation. +// Name returns the value of the "name" field in the mutation. func (m *BouncerMutation) Name() (r string, exists bool) { v := m.name if v == nil { @@ -2471,13 +2443,12 @@ func (m *BouncerMutation) Name() (r string, exists bool) { return *v, true } -// OldName returns the old name value of the Bouncer. -// If the Bouncer object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldName returns the old "name" field's value of the Bouncer entity. +// If the Bouncer object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BouncerMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldName is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldName requires an ID field in the mutation") @@ -2489,17 +2460,17 @@ func (m *BouncerMutation) OldName(ctx context.Context) (v string, err error) { return oldValue.Name, nil } -// ResetName reset all changes of the "name" field. +// ResetName resets all changes to the "name" field. func (m *BouncerMutation) ResetName() { m.name = nil } -// SetAPIKey sets the api_key field. +// SetAPIKey sets the "api_key" field. func (m *BouncerMutation) SetAPIKey(s string) { m.api_key = &s } -// APIKey returns the api_key value in the mutation. +// APIKey returns the value of the "api_key" field in the mutation. func (m *BouncerMutation) APIKey() (r string, exists bool) { v := m.api_key if v == nil { @@ -2508,13 +2479,12 @@ func (m *BouncerMutation) APIKey() (r string, exists bool) { return *v, true } -// OldAPIKey returns the old api_key value of the Bouncer. -// If the Bouncer object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldAPIKey returns the old "api_key" field's value of the Bouncer entity. +// If the Bouncer object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BouncerMutation) OldAPIKey(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldAPIKey is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldAPIKey is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldAPIKey requires an ID field in the mutation") @@ -2526,17 +2496,17 @@ func (m *BouncerMutation) OldAPIKey(ctx context.Context) (v string, err error) { return oldValue.APIKey, nil } -// ResetAPIKey reset all changes of the "api_key" field. +// ResetAPIKey resets all changes to the "api_key" field. func (m *BouncerMutation) ResetAPIKey() { m.api_key = nil } -// SetRevoked sets the revoked field. +// SetRevoked sets the "revoked" field. func (m *BouncerMutation) SetRevoked(b bool) { m.revoked = &b } -// Revoked returns the revoked value in the mutation. +// Revoked returns the value of the "revoked" field in the mutation. func (m *BouncerMutation) Revoked() (r bool, exists bool) { v := m.revoked if v == nil { @@ -2545,13 +2515,12 @@ func (m *BouncerMutation) Revoked() (r bool, exists bool) { return *v, true } -// OldRevoked returns the old revoked value of the Bouncer. -// If the Bouncer object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldRevoked returns the old "revoked" field's value of the Bouncer entity. +// If the Bouncer object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BouncerMutation) OldRevoked(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRevoked is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldRevoked is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldRevoked requires an ID field in the mutation") @@ -2563,17 +2532,17 @@ func (m *BouncerMutation) OldRevoked(ctx context.Context) (v bool, err error) { return oldValue.Revoked, nil } -// ResetRevoked reset all changes of the "revoked" field. +// ResetRevoked resets all changes to the "revoked" field. func (m *BouncerMutation) ResetRevoked() { m.revoked = nil } -// SetIPAddress sets the ip_address field. +// SetIPAddress sets the "ip_address" field. func (m *BouncerMutation) SetIPAddress(s string) { m.ip_address = &s } -// IPAddress returns the ip_address value in the mutation. +// IPAddress returns the value of the "ip_address" field in the mutation. func (m *BouncerMutation) IPAddress() (r string, exists bool) { v := m.ip_address if v == nil { @@ -2582,13 +2551,12 @@ func (m *BouncerMutation) IPAddress() (r string, exists bool) { return *v, true } -// OldIPAddress returns the old ip_address value of the Bouncer. -// If the Bouncer object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldIPAddress returns the old "ip_address" field's value of the Bouncer entity. +// If the Bouncer object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BouncerMutation) OldIPAddress(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldIPAddress is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldIPAddress is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldIPAddress requires an ID field in the mutation") @@ -2600,30 +2568,30 @@ func (m *BouncerMutation) OldIPAddress(ctx context.Context) (v string, err error return oldValue.IPAddress, nil } -// ClearIPAddress clears the value of ip_address. +// ClearIPAddress clears the value of the "ip_address" field. func (m *BouncerMutation) ClearIPAddress() { m.ip_address = nil m.clearedFields[bouncer.FieldIPAddress] = struct{}{} } -// IPAddressCleared returns if the field ip_address was cleared in this mutation. +// IPAddressCleared returns if the "ip_address" field was cleared in this mutation. func (m *BouncerMutation) IPAddressCleared() bool { _, ok := m.clearedFields[bouncer.FieldIPAddress] return ok } -// ResetIPAddress reset all changes of the "ip_address" field. +// ResetIPAddress resets all changes to the "ip_address" field. func (m *BouncerMutation) ResetIPAddress() { m.ip_address = nil delete(m.clearedFields, bouncer.FieldIPAddress) } -// SetType sets the type field. +// SetType sets the "type" field. func (m *BouncerMutation) SetType(s string) { m._type = &s } -// GetType returns the type value in the mutation. +// GetType returns the value of the "type" field in the mutation. func (m *BouncerMutation) GetType() (r string, exists bool) { v := m._type if v == nil { @@ -2632,13 +2600,12 @@ func (m *BouncerMutation) GetType() (r string, exists bool) { return *v, true } -// OldType returns the old type value of the Bouncer. -// If the Bouncer object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldType returns the old "type" field's value of the Bouncer entity. +// If the Bouncer object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BouncerMutation) OldType(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldType is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldType requires an ID field in the mutation") @@ -2650,30 +2617,30 @@ func (m *BouncerMutation) OldType(ctx context.Context) (v string, err error) { return oldValue.Type, nil } -// ClearType clears the value of type. +// ClearType clears the value of the "type" field. func (m *BouncerMutation) ClearType() { m._type = nil m.clearedFields[bouncer.FieldType] = struct{}{} } -// TypeCleared returns if the field type was cleared in this mutation. +// TypeCleared returns if the "type" field was cleared in this mutation. func (m *BouncerMutation) TypeCleared() bool { _, ok := m.clearedFields[bouncer.FieldType] return ok } -// ResetType reset all changes of the "type" field. +// ResetType resets all changes to the "type" field. func (m *BouncerMutation) ResetType() { m._type = nil delete(m.clearedFields, bouncer.FieldType) } -// SetVersion sets the version field. +// SetVersion sets the "version" field. func (m *BouncerMutation) SetVersion(s string) { m.version = &s } -// Version returns the version value in the mutation. +// Version returns the value of the "version" field in the mutation. func (m *BouncerMutation) Version() (r string, exists bool) { v := m.version if v == nil { @@ -2682,13 +2649,12 @@ func (m *BouncerMutation) Version() (r string, exists bool) { return *v, true } -// OldVersion returns the old version value of the Bouncer. -// If the Bouncer object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldVersion returns the old "version" field's value of the Bouncer entity. +// If the Bouncer object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BouncerMutation) OldVersion(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldVersion is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldVersion requires an ID field in the mutation") @@ -2700,30 +2666,30 @@ func (m *BouncerMutation) OldVersion(ctx context.Context) (v string, err error) return oldValue.Version, nil } -// ClearVersion clears the value of version. +// ClearVersion clears the value of the "version" field. func (m *BouncerMutation) ClearVersion() { m.version = nil m.clearedFields[bouncer.FieldVersion] = struct{}{} } -// VersionCleared returns if the field version was cleared in this mutation. +// VersionCleared returns if the "version" field was cleared in this mutation. func (m *BouncerMutation) VersionCleared() bool { _, ok := m.clearedFields[bouncer.FieldVersion] return ok } -// ResetVersion reset all changes of the "version" field. +// ResetVersion resets all changes to the "version" field. func (m *BouncerMutation) ResetVersion() { m.version = nil delete(m.clearedFields, bouncer.FieldVersion) } -// SetUntil sets the until field. +// SetUntil sets the "until" field. func (m *BouncerMutation) SetUntil(t time.Time) { m.until = &t } -// Until returns the until value in the mutation. +// Until returns the value of the "until" field in the mutation. func (m *BouncerMutation) Until() (r time.Time, exists bool) { v := m.until if v == nil { @@ -2732,13 +2698,12 @@ func (m *BouncerMutation) Until() (r time.Time, exists bool) { return *v, true } -// OldUntil returns the old until value of the Bouncer. -// If the Bouncer object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldUntil returns the old "until" field's value of the Bouncer entity. +// If the Bouncer object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BouncerMutation) OldUntil(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUntil is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldUntil is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldUntil requires an ID field in the mutation") @@ -2750,30 +2715,30 @@ func (m *BouncerMutation) OldUntil(ctx context.Context) (v time.Time, err error) return oldValue.Until, nil } -// ClearUntil clears the value of until. +// ClearUntil clears the value of the "until" field. func (m *BouncerMutation) ClearUntil() { m.until = nil m.clearedFields[bouncer.FieldUntil] = struct{}{} } -// UntilCleared returns if the field until was cleared in this mutation. +// UntilCleared returns if the "until" field was cleared in this mutation. func (m *BouncerMutation) UntilCleared() bool { _, ok := m.clearedFields[bouncer.FieldUntil] return ok } -// ResetUntil reset all changes of the "until" field. +// ResetUntil resets all changes to the "until" field. func (m *BouncerMutation) ResetUntil() { m.until = nil delete(m.clearedFields, bouncer.FieldUntil) } -// SetLastPull sets the last_pull field. +// SetLastPull sets the "last_pull" field. func (m *BouncerMutation) SetLastPull(t time.Time) { m.last_pull = &t } -// LastPull returns the last_pull value in the mutation. +// LastPull returns the value of the "last_pull" field in the mutation. func (m *BouncerMutation) LastPull() (r time.Time, exists bool) { v := m.last_pull if v == nil { @@ -2782,13 +2747,12 @@ func (m *BouncerMutation) LastPull() (r time.Time, exists bool) { return *v, true } -// OldLastPull returns the old last_pull value of the Bouncer. -// If the Bouncer object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldLastPull returns the old "last_pull" field's value of the Bouncer entity. +// If the Bouncer object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *BouncerMutation) OldLastPull(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldLastPull is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldLastPull is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldLastPull requires an ID field in the mutation") @@ -2800,7 +2764,7 @@ func (m *BouncerMutation) OldLastPull(ctx context.Context) (v time.Time, err err return oldValue.LastPull, nil } -// ResetLastPull reset all changes of the "last_pull" field. +// ResetLastPull resets all changes to the "last_pull" field. func (m *BouncerMutation) ResetLastPull() { m.last_pull = nil } @@ -2815,9 +2779,9 @@ func (m *BouncerMutation) Type() string { return m.typ } -// Fields returns all fields that were changed during -// this mutation. Note that, in order to get all numeric -// fields that were in/decremented, call AddedFields(). +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). func (m *BouncerMutation) Fields() []string { fields := make([]string, 0, 10) if m.created_at != nil { @@ -2853,9 +2817,9 @@ func (m *BouncerMutation) Fields() []string { return fields } -// Field returns the value of a field with the given name. -// The second boolean value indicates that this field was -// not set, or was not define in the schema. +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. func (m *BouncerMutation) Field(name string) (ent.Value, bool) { switch name { case bouncer.FieldCreatedAt: @@ -2882,9 +2846,9 @@ func (m *BouncerMutation) Field(name string) (ent.Value, bool) { return nil, false } -// OldField returns the old value of the field from the database. -// An error is returned if the mutation operation is not UpdateOne, -// or the query to the database was failed. +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. func (m *BouncerMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case bouncer.FieldCreatedAt: @@ -2911,9 +2875,9 @@ func (m *BouncerMutation) OldField(ctx context.Context, name string) (ent.Value, return nil, fmt.Errorf("unknown Bouncer field %s", name) } -// SetField sets the value for the given name. It returns an -// error if the field is not defined in the schema, or if the -// type mismatch the field type. +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. func (m *BouncerMutation) SetField(name string, value ent.Value) error { switch name { case bouncer.FieldCreatedAt: @@ -2990,30 +2954,30 @@ func (m *BouncerMutation) SetField(name string, value ent.Value) error { return fmt.Errorf("unknown Bouncer field %s", name) } -// AddedFields returns all numeric fields that were incremented -// or decremented during this mutation. +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. func (m *BouncerMutation) AddedFields() []string { return nil } -// AddedField returns the numeric value that was in/decremented -// from a field with the given name. The second value indicates -// that this field was not set, or was not define in the schema. +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. func (m *BouncerMutation) AddedField(name string) (ent.Value, bool) { return nil, false } -// AddField adds the value for the given name. It returns an -// error if the field is not defined in the schema, or if the -// type mismatch the field type. +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. func (m *BouncerMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Bouncer numeric field %s", name) } -// ClearedFields returns all nullable fields that were cleared -// during this mutation. +// ClearedFields returns all nullable fields that were cleared during this +// mutation. func (m *BouncerMutation) ClearedFields() []string { var fields []string if m.FieldCleared(bouncer.FieldIPAddress) { @@ -3031,14 +2995,14 @@ func (m *BouncerMutation) ClearedFields() []string { return fields } -// FieldCleared returns a boolean indicates if this field was +// FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *BouncerMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } -// ClearField clears the value for the given name. It returns an +// ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *BouncerMutation) ClearField(name string) error { switch name { @@ -3058,9 +3022,8 @@ func (m *BouncerMutation) ClearField(name string) error { return fmt.Errorf("unknown Bouncer nullable field %s", name) } -// ResetField resets all changes in the mutation regarding the -// given field name. It returns an error if the field is not -// defined in the schema. +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. func (m *BouncerMutation) ResetField(name string) error { switch name { case bouncer.FieldCreatedAt: @@ -3097,91 +3060,93 @@ func (m *BouncerMutation) ResetField(name string) error { return fmt.Errorf("unknown Bouncer field %s", name) } -// AddedEdges returns all edge names that were set/added in this -// mutation. +// AddedEdges returns all edge names that were set/added in this mutation. func (m *BouncerMutation) AddedEdges() []string { edges := make([]string, 0, 0) return edges } -// AddedIDs returns all ids (to other nodes) that were added for -// the given edge name. +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. func (m *BouncerMutation) AddedIDs(name string) []ent.Value { return nil } -// RemovedEdges returns all edge names that were removed in this -// mutation. +// RemovedEdges returns all edge names that were removed in this mutation. func (m *BouncerMutation) RemovedEdges() []string { edges := make([]string, 0, 0) return edges } -// RemovedIDs returns all ids (to other nodes) that were removed for -// the given edge name. +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. func (m *BouncerMutation) RemovedIDs(name string) []ent.Value { return nil } -// ClearedEdges returns all edge names that were cleared in this -// mutation. +// ClearedEdges returns all edge names that were cleared in this mutation. func (m *BouncerMutation) ClearedEdges() []string { edges := make([]string, 0, 0) return edges } -// EdgeCleared returns a boolean indicates if this edge was -// cleared in this mutation. +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. func (m *BouncerMutation) EdgeCleared(name string) bool { return false } -// ClearEdge clears the value for the given name. It returns an -// error if the edge name is not defined in the schema. +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. func (m *BouncerMutation) ClearEdge(name string) error { return fmt.Errorf("unknown Bouncer unique edge %s", name) } -// ResetEdge resets all changes in the mutation regarding the -// given edge name. It returns an error if the edge is not -// defined in the schema. +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. func (m *BouncerMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Bouncer edge %s", name) } -// DecisionMutation represents an operation that mutate the Decisions -// nodes in the graph. +// DecisionMutation represents an operation that mutates the Decision nodes in the graph. type DecisionMutation struct { config - op Op - typ string - id *int - created_at *time.Time - updated_at *time.Time - until *time.Time - scenario *string - _type *string - start_ip *int64 - addstart_ip *int64 - end_ip *int64 - addend_ip *int64 - scope *string - value *string - origin *string - simulated *bool - clearedFields map[string]struct{} - owner *int - clearedowner bool - done bool - oldValue func(context.Context) (*Decision, error) + op Op + typ string + id *int + created_at *time.Time + updated_at *time.Time + until *time.Time + scenario *string + _type *string + start_ip *int64 + addstart_ip *int64 + end_ip *int64 + addend_ip *int64 + start_suffix *int64 + addstart_suffix *int64 + end_suffix *int64 + addend_suffix *int64 + ip_size *int64 + addip_size *int64 + scope *string + value *string + origin *string + simulated *bool + clearedFields map[string]struct{} + owner *int + clearedowner bool + done bool + oldValue func(context.Context) (*Decision, error) + predicates []predicate.Decision } var _ ent.Mutation = (*DecisionMutation)(nil) -// decisionOption allows to manage the mutation configuration using functional options. +// decisionOption allows management of the mutation configuration using functional options. type decisionOption func(*DecisionMutation) -// newDecisionMutation creates new mutation for $n.Name. +// newDecisionMutation creates new mutation for the Decision entity. func newDecisionMutation(c config, op Op, opts ...decisionOption) *DecisionMutation { m := &DecisionMutation{ config: c, @@ -3195,7 +3160,7 @@ func newDecisionMutation(c config, op Op, opts ...decisionOption) *DecisionMutat return m } -// withDecisionID sets the id field of the mutation. +// withDecisionID sets the ID field of the mutation. func withDecisionID(id int) decisionOption { return func(m *DecisionMutation) { var ( @@ -3246,8 +3211,8 @@ func (m DecisionMutation) Tx() (*Tx, error) { return tx, nil } -// ID returns the id value in the mutation. Note that, the id -// is available only if it was provided to the builder. +// ID returns the ID value in the mutation. Note that the ID +// is only available if it was provided to the builder. func (m *DecisionMutation) ID() (id int, exists bool) { if m.id == nil { return @@ -3255,12 +3220,12 @@ func (m *DecisionMutation) ID() (id int, exists bool) { return *m.id, true } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (m *DecisionMutation) SetCreatedAt(t time.Time) { m.created_at = &t } -// CreatedAt returns the created_at value in the mutation. +// CreatedAt returns the value of the "created_at" field in the mutation. func (m *DecisionMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { @@ -3269,13 +3234,12 @@ func (m *DecisionMutation) CreatedAt() (r time.Time, exists bool) { return *v, true } -// OldCreatedAt returns the old created_at value of the Decision. -// If the Decision object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldCreatedAt returns the old "created_at" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DecisionMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") @@ -3287,17 +3251,17 @@ func (m *DecisionMutation) OldCreatedAt(ctx context.Context) (v time.Time, err e return oldValue.CreatedAt, nil } -// ResetCreatedAt reset all changes of the "created_at" field. +// ResetCreatedAt resets all changes to the "created_at" field. func (m *DecisionMutation) ResetCreatedAt() { m.created_at = nil } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (m *DecisionMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } -// UpdatedAt returns the updated_at value in the mutation. +// UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *DecisionMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { @@ -3306,13 +3270,12 @@ func (m *DecisionMutation) UpdatedAt() (r time.Time, exists bool) { return *v, true } -// OldUpdatedAt returns the old updated_at value of the Decision. -// If the Decision object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldUpdatedAt returns the old "updated_at" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DecisionMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") @@ -3324,17 +3287,17 @@ func (m *DecisionMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err e return oldValue.UpdatedAt, nil } -// ResetUpdatedAt reset all changes of the "updated_at" field. +// ResetUpdatedAt resets all changes to the "updated_at" field. func (m *DecisionMutation) ResetUpdatedAt() { m.updated_at = nil } -// SetUntil sets the until field. +// SetUntil sets the "until" field. func (m *DecisionMutation) SetUntil(t time.Time) { m.until = &t } -// Until returns the until value in the mutation. +// Until returns the value of the "until" field in the mutation. func (m *DecisionMutation) Until() (r time.Time, exists bool) { v := m.until if v == nil { @@ -3343,13 +3306,12 @@ func (m *DecisionMutation) Until() (r time.Time, exists bool) { return *v, true } -// OldUntil returns the old until value of the Decision. -// If the Decision object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldUntil returns the old "until" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DecisionMutation) OldUntil(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUntil is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldUntil is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldUntil requires an ID field in the mutation") @@ -3361,17 +3323,17 @@ func (m *DecisionMutation) OldUntil(ctx context.Context) (v time.Time, err error return oldValue.Until, nil } -// ResetUntil reset all changes of the "until" field. +// ResetUntil resets all changes to the "until" field. func (m *DecisionMutation) ResetUntil() { m.until = nil } -// SetScenario sets the scenario field. +// SetScenario sets the "scenario" field. func (m *DecisionMutation) SetScenario(s string) { m.scenario = &s } -// Scenario returns the scenario value in the mutation. +// Scenario returns the value of the "scenario" field in the mutation. func (m *DecisionMutation) Scenario() (r string, exists bool) { v := m.scenario if v == nil { @@ -3380,13 +3342,12 @@ func (m *DecisionMutation) Scenario() (r string, exists bool) { return *v, true } -// OldScenario returns the old scenario value of the Decision. -// If the Decision object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldScenario returns the old "scenario" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DecisionMutation) OldScenario(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldScenario is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldScenario is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldScenario requires an ID field in the mutation") @@ -3398,17 +3359,17 @@ func (m *DecisionMutation) OldScenario(ctx context.Context) (v string, err error return oldValue.Scenario, nil } -// ResetScenario reset all changes of the "scenario" field. +// ResetScenario resets all changes to the "scenario" field. func (m *DecisionMutation) ResetScenario() { m.scenario = nil } -// SetType sets the type field. +// SetType sets the "type" field. func (m *DecisionMutation) SetType(s string) { m._type = &s } -// GetType returns the type value in the mutation. +// GetType returns the value of the "type" field in the mutation. func (m *DecisionMutation) GetType() (r string, exists bool) { v := m._type if v == nil { @@ -3417,13 +3378,12 @@ func (m *DecisionMutation) GetType() (r string, exists bool) { return *v, true } -// OldType returns the old type value of the Decision. -// If the Decision object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldType returns the old "type" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DecisionMutation) OldType(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldType is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldType requires an ID field in the mutation") @@ -3435,18 +3395,18 @@ func (m *DecisionMutation) OldType(ctx context.Context) (v string, err error) { return oldValue.Type, nil } -// ResetType reset all changes of the "type" field. +// ResetType resets all changes to the "type" field. func (m *DecisionMutation) ResetType() { m._type = nil } -// SetStartIP sets the start_ip field. +// SetStartIP sets the "start_ip" field. func (m *DecisionMutation) SetStartIP(i int64) { m.start_ip = &i m.addstart_ip = nil } -// StartIP returns the start_ip value in the mutation. +// StartIP returns the value of the "start_ip" field in the mutation. func (m *DecisionMutation) StartIP() (r int64, exists bool) { v := m.start_ip if v == nil { @@ -3455,13 +3415,12 @@ func (m *DecisionMutation) StartIP() (r int64, exists bool) { return *v, true } -// OldStartIP returns the old start_ip value of the Decision. -// If the Decision object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldStartIP returns the old "start_ip" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DecisionMutation) OldStartIP(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldStartIP is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldStartIP is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldStartIP requires an ID field in the mutation") @@ -3473,7 +3432,7 @@ func (m *DecisionMutation) OldStartIP(ctx context.Context) (v int64, err error) return oldValue.StartIP, nil } -// AddStartIP adds i to start_ip. +// AddStartIP adds i to the "start_ip" field. func (m *DecisionMutation) AddStartIP(i int64) { if m.addstart_ip != nil { *m.addstart_ip += i @@ -3482,7 +3441,7 @@ func (m *DecisionMutation) AddStartIP(i int64) { } } -// AddedStartIP returns the value that was added to the start_ip field in this mutation. +// AddedStartIP returns the value that was added to the "start_ip" field in this mutation. func (m *DecisionMutation) AddedStartIP() (r int64, exists bool) { v := m.addstart_ip if v == nil { @@ -3491,33 +3450,33 @@ func (m *DecisionMutation) AddedStartIP() (r int64, exists bool) { return *v, true } -// ClearStartIP clears the value of start_ip. +// ClearStartIP clears the value of the "start_ip" field. func (m *DecisionMutation) ClearStartIP() { m.start_ip = nil m.addstart_ip = nil m.clearedFields[decision.FieldStartIP] = struct{}{} } -// StartIPCleared returns if the field start_ip was cleared in this mutation. +// StartIPCleared returns if the "start_ip" field was cleared in this mutation. func (m *DecisionMutation) StartIPCleared() bool { _, ok := m.clearedFields[decision.FieldStartIP] return ok } -// ResetStartIP reset all changes of the "start_ip" field. +// ResetStartIP resets all changes to the "start_ip" field. func (m *DecisionMutation) ResetStartIP() { m.start_ip = nil m.addstart_ip = nil delete(m.clearedFields, decision.FieldStartIP) } -// SetEndIP sets the end_ip field. +// SetEndIP sets the "end_ip" field. func (m *DecisionMutation) SetEndIP(i int64) { m.end_ip = &i m.addend_ip = nil } -// EndIP returns the end_ip value in the mutation. +// EndIP returns the value of the "end_ip" field in the mutation. func (m *DecisionMutation) EndIP() (r int64, exists bool) { v := m.end_ip if v == nil { @@ -3526,13 +3485,12 @@ func (m *DecisionMutation) EndIP() (r int64, exists bool) { return *v, true } -// OldEndIP returns the old end_ip value of the Decision. -// If the Decision object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldEndIP returns the old "end_ip" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DecisionMutation) OldEndIP(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldEndIP is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldEndIP is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldEndIP requires an ID field in the mutation") @@ -3544,7 +3502,7 @@ func (m *DecisionMutation) OldEndIP(ctx context.Context) (v int64, err error) { return oldValue.EndIP, nil } -// AddEndIP adds i to end_ip. +// AddEndIP adds i to the "end_ip" field. func (m *DecisionMutation) AddEndIP(i int64) { if m.addend_ip != nil { *m.addend_ip += i @@ -3553,7 +3511,7 @@ func (m *DecisionMutation) AddEndIP(i int64) { } } -// AddedEndIP returns the value that was added to the end_ip field in this mutation. +// AddedEndIP returns the value that was added to the "end_ip" field in this mutation. func (m *DecisionMutation) AddedEndIP() (r int64, exists bool) { v := m.addend_ip if v == nil { @@ -3562,32 +3520,242 @@ func (m *DecisionMutation) AddedEndIP() (r int64, exists bool) { return *v, true } -// ClearEndIP clears the value of end_ip. +// ClearEndIP clears the value of the "end_ip" field. func (m *DecisionMutation) ClearEndIP() { m.end_ip = nil m.addend_ip = nil m.clearedFields[decision.FieldEndIP] = struct{}{} } -// EndIPCleared returns if the field end_ip was cleared in this mutation. +// EndIPCleared returns if the "end_ip" field was cleared in this mutation. func (m *DecisionMutation) EndIPCleared() bool { _, ok := m.clearedFields[decision.FieldEndIP] return ok } -// ResetEndIP reset all changes of the "end_ip" field. +// ResetEndIP resets all changes to the "end_ip" field. func (m *DecisionMutation) ResetEndIP() { m.end_ip = nil m.addend_ip = nil delete(m.clearedFields, decision.FieldEndIP) } -// SetScope sets the scope field. +// SetStartSuffix sets the "start_suffix" field. +func (m *DecisionMutation) SetStartSuffix(i int64) { + m.start_suffix = &i + m.addstart_suffix = nil +} + +// StartSuffix returns the value of the "start_suffix" field in the mutation. +func (m *DecisionMutation) StartSuffix() (r int64, exists bool) { + v := m.start_suffix + if v == nil { + return + } + return *v, true +} + +// OldStartSuffix returns the old "start_suffix" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *DecisionMutation) OldStartSuffix(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldStartSuffix is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldStartSuffix requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStartSuffix: %w", err) + } + return oldValue.StartSuffix, nil +} + +// AddStartSuffix adds i to the "start_suffix" field. +func (m *DecisionMutation) AddStartSuffix(i int64) { + if m.addstart_suffix != nil { + *m.addstart_suffix += i + } else { + m.addstart_suffix = &i + } +} + +// AddedStartSuffix returns the value that was added to the "start_suffix" field in this mutation. +func (m *DecisionMutation) AddedStartSuffix() (r int64, exists bool) { + v := m.addstart_suffix + if v == nil { + return + } + return *v, true +} + +// ClearStartSuffix clears the value of the "start_suffix" field. +func (m *DecisionMutation) ClearStartSuffix() { + m.start_suffix = nil + m.addstart_suffix = nil + m.clearedFields[decision.FieldStartSuffix] = struct{}{} +} + +// StartSuffixCleared returns if the "start_suffix" field was cleared in this mutation. +func (m *DecisionMutation) StartSuffixCleared() bool { + _, ok := m.clearedFields[decision.FieldStartSuffix] + return ok +} + +// ResetStartSuffix resets all changes to the "start_suffix" field. +func (m *DecisionMutation) ResetStartSuffix() { + m.start_suffix = nil + m.addstart_suffix = nil + delete(m.clearedFields, decision.FieldStartSuffix) +} + +// SetEndSuffix sets the "end_suffix" field. +func (m *DecisionMutation) SetEndSuffix(i int64) { + m.end_suffix = &i + m.addend_suffix = nil +} + +// EndSuffix returns the value of the "end_suffix" field in the mutation. +func (m *DecisionMutation) EndSuffix() (r int64, exists bool) { + v := m.end_suffix + if v == nil { + return + } + return *v, true +} + +// OldEndSuffix returns the old "end_suffix" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *DecisionMutation) OldEndSuffix(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldEndSuffix is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldEndSuffix requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldEndSuffix: %w", err) + } + return oldValue.EndSuffix, nil +} + +// AddEndSuffix adds i to the "end_suffix" field. +func (m *DecisionMutation) AddEndSuffix(i int64) { + if m.addend_suffix != nil { + *m.addend_suffix += i + } else { + m.addend_suffix = &i + } +} + +// AddedEndSuffix returns the value that was added to the "end_suffix" field in this mutation. +func (m *DecisionMutation) AddedEndSuffix() (r int64, exists bool) { + v := m.addend_suffix + if v == nil { + return + } + return *v, true +} + +// ClearEndSuffix clears the value of the "end_suffix" field. +func (m *DecisionMutation) ClearEndSuffix() { + m.end_suffix = nil + m.addend_suffix = nil + m.clearedFields[decision.FieldEndSuffix] = struct{}{} +} + +// EndSuffixCleared returns if the "end_suffix" field was cleared in this mutation. +func (m *DecisionMutation) EndSuffixCleared() bool { + _, ok := m.clearedFields[decision.FieldEndSuffix] + return ok +} + +// ResetEndSuffix resets all changes to the "end_suffix" field. +func (m *DecisionMutation) ResetEndSuffix() { + m.end_suffix = nil + m.addend_suffix = nil + delete(m.clearedFields, decision.FieldEndSuffix) +} + +// SetIPSize sets the "ip_size" field. +func (m *DecisionMutation) SetIPSize(i int64) { + m.ip_size = &i + m.addip_size = nil +} + +// IPSize returns the value of the "ip_size" field in the mutation. +func (m *DecisionMutation) IPSize() (r int64, exists bool) { + v := m.ip_size + if v == nil { + return + } + return *v, true +} + +// OldIPSize returns the old "ip_size" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *DecisionMutation) OldIPSize(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldIPSize is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldIPSize requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIPSize: %w", err) + } + return oldValue.IPSize, nil +} + +// AddIPSize adds i to the "ip_size" field. +func (m *DecisionMutation) AddIPSize(i int64) { + if m.addip_size != nil { + *m.addip_size += i + } else { + m.addip_size = &i + } +} + +// AddedIPSize returns the value that was added to the "ip_size" field in this mutation. +func (m *DecisionMutation) AddedIPSize() (r int64, exists bool) { + v := m.addip_size + if v == nil { + return + } + return *v, true +} + +// ClearIPSize clears the value of the "ip_size" field. +func (m *DecisionMutation) ClearIPSize() { + m.ip_size = nil + m.addip_size = nil + m.clearedFields[decision.FieldIPSize] = struct{}{} +} + +// IPSizeCleared returns if the "ip_size" field was cleared in this mutation. +func (m *DecisionMutation) IPSizeCleared() bool { + _, ok := m.clearedFields[decision.FieldIPSize] + return ok +} + +// ResetIPSize resets all changes to the "ip_size" field. +func (m *DecisionMutation) ResetIPSize() { + m.ip_size = nil + m.addip_size = nil + delete(m.clearedFields, decision.FieldIPSize) +} + +// SetScope sets the "scope" field. func (m *DecisionMutation) SetScope(s string) { m.scope = &s } -// Scope returns the scope value in the mutation. +// Scope returns the value of the "scope" field in the mutation. func (m *DecisionMutation) Scope() (r string, exists bool) { v := m.scope if v == nil { @@ -3596,13 +3764,12 @@ func (m *DecisionMutation) Scope() (r string, exists bool) { return *v, true } -// OldScope returns the old scope value of the Decision. -// If the Decision object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldScope returns the old "scope" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DecisionMutation) OldScope(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldScope is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldScope is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldScope requires an ID field in the mutation") @@ -3614,17 +3781,17 @@ func (m *DecisionMutation) OldScope(ctx context.Context) (v string, err error) { return oldValue.Scope, nil } -// ResetScope reset all changes of the "scope" field. +// ResetScope resets all changes to the "scope" field. func (m *DecisionMutation) ResetScope() { m.scope = nil } -// SetValue sets the value field. +// SetValue sets the "value" field. func (m *DecisionMutation) SetValue(s string) { m.value = &s } -// Value returns the value value in the mutation. +// Value returns the value of the "value" field in the mutation. func (m *DecisionMutation) Value() (r string, exists bool) { v := m.value if v == nil { @@ -3633,13 +3800,12 @@ func (m *DecisionMutation) Value() (r string, exists bool) { return *v, true } -// OldValue returns the old value value of the Decision. -// If the Decision object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldValue returns the old "value" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DecisionMutation) OldValue(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldValue is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldValue is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldValue requires an ID field in the mutation") @@ -3651,17 +3817,17 @@ func (m *DecisionMutation) OldValue(ctx context.Context) (v string, err error) { return oldValue.Value, nil } -// ResetValue reset all changes of the "value" field. +// ResetValue resets all changes to the "value" field. func (m *DecisionMutation) ResetValue() { m.value = nil } -// SetOrigin sets the origin field. +// SetOrigin sets the "origin" field. func (m *DecisionMutation) SetOrigin(s string) { m.origin = &s } -// Origin returns the origin value in the mutation. +// Origin returns the value of the "origin" field in the mutation. func (m *DecisionMutation) Origin() (r string, exists bool) { v := m.origin if v == nil { @@ -3670,13 +3836,12 @@ func (m *DecisionMutation) Origin() (r string, exists bool) { return *v, true } -// OldOrigin returns the old origin value of the Decision. -// If the Decision object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldOrigin returns the old "origin" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DecisionMutation) OldOrigin(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldOrigin is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldOrigin is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldOrigin requires an ID field in the mutation") @@ -3688,17 +3853,17 @@ func (m *DecisionMutation) OldOrigin(ctx context.Context) (v string, err error) return oldValue.Origin, nil } -// ResetOrigin reset all changes of the "origin" field. +// ResetOrigin resets all changes to the "origin" field. func (m *DecisionMutation) ResetOrigin() { m.origin = nil } -// SetSimulated sets the simulated field. +// SetSimulated sets the "simulated" field. func (m *DecisionMutation) SetSimulated(b bool) { m.simulated = &b } -// Simulated returns the simulated value in the mutation. +// Simulated returns the value of the "simulated" field in the mutation. func (m *DecisionMutation) Simulated() (r bool, exists bool) { v := m.simulated if v == nil { @@ -3707,13 +3872,12 @@ func (m *DecisionMutation) Simulated() (r bool, exists bool) { return *v, true } -// OldSimulated returns the old simulated value of the Decision. -// If the Decision object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldSimulated returns the old "simulated" field's value of the Decision entity. +// If the Decision object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DecisionMutation) OldSimulated(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSimulated is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldSimulated is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldSimulated requires an ID field in the mutation") @@ -3725,27 +3889,27 @@ func (m *DecisionMutation) OldSimulated(ctx context.Context) (v bool, err error) return oldValue.Simulated, nil } -// ResetSimulated reset all changes of the "simulated" field. +// ResetSimulated resets all changes to the "simulated" field. func (m *DecisionMutation) ResetSimulated() { m.simulated = nil } -// SetOwnerID sets the owner edge to Alert by id. +// SetOwnerID sets the "owner" edge to the Alert entity by id. func (m *DecisionMutation) SetOwnerID(id int) { m.owner = &id } -// ClearOwner clears the owner edge to Alert. +// ClearOwner clears the "owner" edge to the Alert entity. func (m *DecisionMutation) ClearOwner() { m.clearedowner = true } -// OwnerCleared returns if the edge owner was cleared. +// OwnerCleared returns if the "owner" edge to the Alert entity was cleared. func (m *DecisionMutation) OwnerCleared() bool { return m.clearedowner } -// OwnerID returns the owner id in the mutation. +// OwnerID returns the "owner" edge ID in the mutation. func (m *DecisionMutation) OwnerID() (id int, exists bool) { if m.owner != nil { return *m.owner, true @@ -3753,8 +3917,8 @@ func (m *DecisionMutation) OwnerID() (id int, exists bool) { return } -// OwnerIDs returns the owner ids in the mutation. -// Note that ids always returns len(ids) <= 1 for unique edges, and you should use +// OwnerIDs returns the "owner" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // OwnerID instead. It exists only for internal usage by the builders. func (m *DecisionMutation) OwnerIDs() (ids []int) { if id := m.owner; id != nil { @@ -3763,7 +3927,7 @@ func (m *DecisionMutation) OwnerIDs() (ids []int) { return } -// ResetOwner reset all changes of the "owner" edge. +// ResetOwner resets all changes to the "owner" edge. func (m *DecisionMutation) ResetOwner() { m.owner = nil m.clearedowner = false @@ -3779,11 +3943,11 @@ func (m *DecisionMutation) Type() string { return m.typ } -// Fields returns all fields that were changed during -// this mutation. Note that, in order to get all numeric -// fields that were in/decremented, call AddedFields(). +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). func (m *DecisionMutation) Fields() []string { - fields := make([]string, 0, 11) + fields := make([]string, 0, 14) if m.created_at != nil { fields = append(fields, decision.FieldCreatedAt) } @@ -3805,6 +3969,15 @@ func (m *DecisionMutation) Fields() []string { if m.end_ip != nil { fields = append(fields, decision.FieldEndIP) } + if m.start_suffix != nil { + fields = append(fields, decision.FieldStartSuffix) + } + if m.end_suffix != nil { + fields = append(fields, decision.FieldEndSuffix) + } + if m.ip_size != nil { + fields = append(fields, decision.FieldIPSize) + } if m.scope != nil { fields = append(fields, decision.FieldScope) } @@ -3820,9 +3993,9 @@ func (m *DecisionMutation) Fields() []string { return fields } -// Field returns the value of a field with the given name. -// The second boolean value indicates that this field was -// not set, or was not define in the schema. +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. func (m *DecisionMutation) Field(name string) (ent.Value, bool) { switch name { case decision.FieldCreatedAt: @@ -3839,6 +4012,12 @@ func (m *DecisionMutation) Field(name string) (ent.Value, bool) { return m.StartIP() case decision.FieldEndIP: return m.EndIP() + case decision.FieldStartSuffix: + return m.StartSuffix() + case decision.FieldEndSuffix: + return m.EndSuffix() + case decision.FieldIPSize: + return m.IPSize() case decision.FieldScope: return m.Scope() case decision.FieldValue: @@ -3851,9 +4030,9 @@ func (m *DecisionMutation) Field(name string) (ent.Value, bool) { return nil, false } -// OldField returns the old value of the field from the database. -// An error is returned if the mutation operation is not UpdateOne, -// or the query to the database was failed. +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. func (m *DecisionMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case decision.FieldCreatedAt: @@ -3870,6 +4049,12 @@ func (m *DecisionMutation) OldField(ctx context.Context, name string) (ent.Value return m.OldStartIP(ctx) case decision.FieldEndIP: return m.OldEndIP(ctx) + case decision.FieldStartSuffix: + return m.OldStartSuffix(ctx) + case decision.FieldEndSuffix: + return m.OldEndSuffix(ctx) + case decision.FieldIPSize: + return m.OldIPSize(ctx) case decision.FieldScope: return m.OldScope(ctx) case decision.FieldValue: @@ -3882,9 +4067,9 @@ func (m *DecisionMutation) OldField(ctx context.Context, name string) (ent.Value return nil, fmt.Errorf("unknown Decision field %s", name) } -// SetField sets the value for the given name. It returns an -// error if the field is not defined in the schema, or if the -// type mismatch the field type. +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. func (m *DecisionMutation) SetField(name string, value ent.Value) error { switch name { case decision.FieldCreatedAt: @@ -3936,6 +4121,27 @@ func (m *DecisionMutation) SetField(name string, value ent.Value) error { } m.SetEndIP(v) return nil + case decision.FieldStartSuffix: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStartSuffix(v) + return nil + case decision.FieldEndSuffix: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEndSuffix(v) + return nil + case decision.FieldIPSize: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIPSize(v) + return nil case decision.FieldScope: v, ok := value.(string) if !ok { @@ -3968,8 +4174,8 @@ func (m *DecisionMutation) SetField(name string, value ent.Value) error { return fmt.Errorf("unknown Decision field %s", name) } -// AddedFields returns all numeric fields that were incremented -// or decremented during this mutation. +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. func (m *DecisionMutation) AddedFields() []string { var fields []string if m.addstart_ip != nil { @@ -3978,25 +4184,40 @@ func (m *DecisionMutation) AddedFields() []string { if m.addend_ip != nil { fields = append(fields, decision.FieldEndIP) } + if m.addstart_suffix != nil { + fields = append(fields, decision.FieldStartSuffix) + } + if m.addend_suffix != nil { + fields = append(fields, decision.FieldEndSuffix) + } + if m.addip_size != nil { + fields = append(fields, decision.FieldIPSize) + } return fields } -// AddedField returns the numeric value that was in/decremented -// from a field with the given name. The second value indicates -// that this field was not set, or was not define in the schema. +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. func (m *DecisionMutation) AddedField(name string) (ent.Value, bool) { switch name { case decision.FieldStartIP: return m.AddedStartIP() case decision.FieldEndIP: return m.AddedEndIP() + case decision.FieldStartSuffix: + return m.AddedStartSuffix() + case decision.FieldEndSuffix: + return m.AddedEndSuffix() + case decision.FieldIPSize: + return m.AddedIPSize() } return nil, false } -// AddField adds the value for the given name. It returns an -// error if the field is not defined in the schema, or if the -// type mismatch the field type. +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. func (m *DecisionMutation) AddField(name string, value ent.Value) error { switch name { case decision.FieldStartIP: @@ -4013,12 +4234,33 @@ func (m *DecisionMutation) AddField(name string, value ent.Value) error { } m.AddEndIP(v) return nil + case decision.FieldStartSuffix: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddStartSuffix(v) + return nil + case decision.FieldEndSuffix: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddEndSuffix(v) + return nil + case decision.FieldIPSize: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddIPSize(v) + return nil } return fmt.Errorf("unknown Decision numeric field %s", name) } -// ClearedFields returns all nullable fields that were cleared -// during this mutation. +// ClearedFields returns all nullable fields that were cleared during this +// mutation. func (m *DecisionMutation) ClearedFields() []string { var fields []string if m.FieldCleared(decision.FieldStartIP) { @@ -4027,17 +4269,26 @@ func (m *DecisionMutation) ClearedFields() []string { if m.FieldCleared(decision.FieldEndIP) { fields = append(fields, decision.FieldEndIP) } + if m.FieldCleared(decision.FieldStartSuffix) { + fields = append(fields, decision.FieldStartSuffix) + } + if m.FieldCleared(decision.FieldEndSuffix) { + fields = append(fields, decision.FieldEndSuffix) + } + if m.FieldCleared(decision.FieldIPSize) { + fields = append(fields, decision.FieldIPSize) + } return fields } -// FieldCleared returns a boolean indicates if this field was +// FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *DecisionMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } -// ClearField clears the value for the given name. It returns an +// ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *DecisionMutation) ClearField(name string) error { switch name { @@ -4047,13 +4298,21 @@ func (m *DecisionMutation) ClearField(name string) error { case decision.FieldEndIP: m.ClearEndIP() return nil + case decision.FieldStartSuffix: + m.ClearStartSuffix() + return nil + case decision.FieldEndSuffix: + m.ClearEndSuffix() + return nil + case decision.FieldIPSize: + m.ClearIPSize() + return nil } return fmt.Errorf("unknown Decision nullable field %s", name) } -// ResetField resets all changes in the mutation regarding the -// given field name. It returns an error if the field is not -// defined in the schema. +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. func (m *DecisionMutation) ResetField(name string) error { switch name { case decision.FieldCreatedAt: @@ -4077,6 +4336,15 @@ func (m *DecisionMutation) ResetField(name string) error { case decision.FieldEndIP: m.ResetEndIP() return nil + case decision.FieldStartSuffix: + m.ResetStartSuffix() + return nil + case decision.FieldEndSuffix: + m.ResetEndSuffix() + return nil + case decision.FieldIPSize: + m.ResetIPSize() + return nil case decision.FieldScope: m.ResetScope() return nil @@ -4093,8 +4361,7 @@ func (m *DecisionMutation) ResetField(name string) error { return fmt.Errorf("unknown Decision field %s", name) } -// AddedEdges returns all edge names that were set/added in this -// mutation. +// AddedEdges returns all edge names that were set/added in this mutation. func (m *DecisionMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.owner != nil { @@ -4103,8 +4370,8 @@ func (m *DecisionMutation) AddedEdges() []string { return edges } -// AddedIDs returns all ids (to other nodes) that were added for -// the given edge name. +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. func (m *DecisionMutation) AddedIDs(name string) []ent.Value { switch name { case decision.EdgeOwner: @@ -4115,23 +4382,21 @@ func (m *DecisionMutation) AddedIDs(name string) []ent.Value { return nil } -// RemovedEdges returns all edge names that were removed in this -// mutation. +// RemovedEdges returns all edge names that were removed in this mutation. func (m *DecisionMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } -// RemovedIDs returns all ids (to other nodes) that were removed for -// the given edge name. +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. func (m *DecisionMutation) RemovedIDs(name string) []ent.Value { switch name { } return nil } -// ClearedEdges returns all edge names that were cleared in this -// mutation. +// ClearedEdges returns all edge names that were cleared in this mutation. func (m *DecisionMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedowner { @@ -4140,8 +4405,8 @@ func (m *DecisionMutation) ClearedEdges() []string { return edges } -// EdgeCleared returns a boolean indicates if this edge was -// cleared in this mutation. +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. func (m *DecisionMutation) EdgeCleared(name string) bool { switch name { case decision.EdgeOwner: @@ -4150,8 +4415,8 @@ func (m *DecisionMutation) EdgeCleared(name string) bool { return false } -// ClearEdge clears the value for the given name. It returns an -// error if the edge name is not defined in the schema. +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. func (m *DecisionMutation) ClearEdge(name string) error { switch name { case decision.EdgeOwner: @@ -4161,9 +4426,8 @@ func (m *DecisionMutation) ClearEdge(name string) error { return fmt.Errorf("unknown Decision unique edge %s", name) } -// ResetEdge resets all changes in the mutation regarding the -// given edge name. It returns an error if the edge is not -// defined in the schema. +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. func (m *DecisionMutation) ResetEdge(name string) error { switch name { case decision.EdgeOwner: @@ -4173,8 +4437,7 @@ func (m *DecisionMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Decision edge %s", name) } -// EventMutation represents an operation that mutate the Events -// nodes in the graph. +// EventMutation represents an operation that mutates the Event nodes in the graph. type EventMutation struct { config op Op @@ -4189,14 +4452,15 @@ type EventMutation struct { clearedowner bool done bool oldValue func(context.Context) (*Event, error) + predicates []predicate.Event } var _ ent.Mutation = (*EventMutation)(nil) -// eventOption allows to manage the mutation configuration using functional options. +// eventOption allows management of the mutation configuration using functional options. type eventOption func(*EventMutation) -// newEventMutation creates new mutation for $n.Name. +// newEventMutation creates new mutation for the Event entity. func newEventMutation(c config, op Op, opts ...eventOption) *EventMutation { m := &EventMutation{ config: c, @@ -4210,7 +4474,7 @@ func newEventMutation(c config, op Op, opts ...eventOption) *EventMutation { return m } -// withEventID sets the id field of the mutation. +// withEventID sets the ID field of the mutation. func withEventID(id int) eventOption { return func(m *EventMutation) { var ( @@ -4261,8 +4525,8 @@ func (m EventMutation) Tx() (*Tx, error) { return tx, nil } -// ID returns the id value in the mutation. Note that, the id -// is available only if it was provided to the builder. +// ID returns the ID value in the mutation. Note that the ID +// is only available if it was provided to the builder. func (m *EventMutation) ID() (id int, exists bool) { if m.id == nil { return @@ -4270,12 +4534,12 @@ func (m *EventMutation) ID() (id int, exists bool) { return *m.id, true } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (m *EventMutation) SetCreatedAt(t time.Time) { m.created_at = &t } -// CreatedAt returns the created_at value in the mutation. +// CreatedAt returns the value of the "created_at" field in the mutation. func (m *EventMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { @@ -4284,13 +4548,12 @@ func (m *EventMutation) CreatedAt() (r time.Time, exists bool) { return *v, true } -// OldCreatedAt returns the old created_at value of the Event. -// If the Event object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldCreatedAt returns the old "created_at" field's value of the Event entity. +// If the Event object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *EventMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") @@ -4302,17 +4565,17 @@ func (m *EventMutation) OldCreatedAt(ctx context.Context) (v time.Time, err erro return oldValue.CreatedAt, nil } -// ResetCreatedAt reset all changes of the "created_at" field. +// ResetCreatedAt resets all changes to the "created_at" field. func (m *EventMutation) ResetCreatedAt() { m.created_at = nil } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (m *EventMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } -// UpdatedAt returns the updated_at value in the mutation. +// UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *EventMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { @@ -4321,13 +4584,12 @@ func (m *EventMutation) UpdatedAt() (r time.Time, exists bool) { return *v, true } -// OldUpdatedAt returns the old updated_at value of the Event. -// If the Event object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldUpdatedAt returns the old "updated_at" field's value of the Event entity. +// If the Event object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *EventMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") @@ -4339,17 +4601,17 @@ func (m *EventMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err erro return oldValue.UpdatedAt, nil } -// ResetUpdatedAt reset all changes of the "updated_at" field. +// ResetUpdatedAt resets all changes to the "updated_at" field. func (m *EventMutation) ResetUpdatedAt() { m.updated_at = nil } -// SetTime sets the time field. +// SetTime sets the "time" field. func (m *EventMutation) SetTime(t time.Time) { m.time = &t } -// Time returns the time value in the mutation. +// Time returns the value of the "time" field in the mutation. func (m *EventMutation) Time() (r time.Time, exists bool) { v := m.time if v == nil { @@ -4358,13 +4620,12 @@ func (m *EventMutation) Time() (r time.Time, exists bool) { return *v, true } -// OldTime returns the old time value of the Event. -// If the Event object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldTime returns the old "time" field's value of the Event entity. +// If the Event object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *EventMutation) OldTime(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldTime is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldTime is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldTime requires an ID field in the mutation") @@ -4376,17 +4637,17 @@ func (m *EventMutation) OldTime(ctx context.Context) (v time.Time, err error) { return oldValue.Time, nil } -// ResetTime reset all changes of the "time" field. +// ResetTime resets all changes to the "time" field. func (m *EventMutation) ResetTime() { m.time = nil } -// SetSerialized sets the serialized field. +// SetSerialized sets the "serialized" field. func (m *EventMutation) SetSerialized(s string) { m.serialized = &s } -// Serialized returns the serialized value in the mutation. +// Serialized returns the value of the "serialized" field in the mutation. func (m *EventMutation) Serialized() (r string, exists bool) { v := m.serialized if v == nil { @@ -4395,13 +4656,12 @@ func (m *EventMutation) Serialized() (r string, exists bool) { return *v, true } -// OldSerialized returns the old serialized value of the Event. -// If the Event object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldSerialized returns the old "serialized" field's value of the Event entity. +// If the Event object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *EventMutation) OldSerialized(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSerialized is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldSerialized is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldSerialized requires an ID field in the mutation") @@ -4413,27 +4673,27 @@ func (m *EventMutation) OldSerialized(ctx context.Context) (v string, err error) return oldValue.Serialized, nil } -// ResetSerialized reset all changes of the "serialized" field. +// ResetSerialized resets all changes to the "serialized" field. func (m *EventMutation) ResetSerialized() { m.serialized = nil } -// SetOwnerID sets the owner edge to Alert by id. +// SetOwnerID sets the "owner" edge to the Alert entity by id. func (m *EventMutation) SetOwnerID(id int) { m.owner = &id } -// ClearOwner clears the owner edge to Alert. +// ClearOwner clears the "owner" edge to the Alert entity. func (m *EventMutation) ClearOwner() { m.clearedowner = true } -// OwnerCleared returns if the edge owner was cleared. +// OwnerCleared returns if the "owner" edge to the Alert entity was cleared. func (m *EventMutation) OwnerCleared() bool { return m.clearedowner } -// OwnerID returns the owner id in the mutation. +// OwnerID returns the "owner" edge ID in the mutation. func (m *EventMutation) OwnerID() (id int, exists bool) { if m.owner != nil { return *m.owner, true @@ -4441,8 +4701,8 @@ func (m *EventMutation) OwnerID() (id int, exists bool) { return } -// OwnerIDs returns the owner ids in the mutation. -// Note that ids always returns len(ids) <= 1 for unique edges, and you should use +// OwnerIDs returns the "owner" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // OwnerID instead. It exists only for internal usage by the builders. func (m *EventMutation) OwnerIDs() (ids []int) { if id := m.owner; id != nil { @@ -4451,7 +4711,7 @@ func (m *EventMutation) OwnerIDs() (ids []int) { return } -// ResetOwner reset all changes of the "owner" edge. +// ResetOwner resets all changes to the "owner" edge. func (m *EventMutation) ResetOwner() { m.owner = nil m.clearedowner = false @@ -4467,9 +4727,9 @@ func (m *EventMutation) Type() string { return m.typ } -// Fields returns all fields that were changed during -// this mutation. Note that, in order to get all numeric -// fields that were in/decremented, call AddedFields(). +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). func (m *EventMutation) Fields() []string { fields := make([]string, 0, 4) if m.created_at != nil { @@ -4487,9 +4747,9 @@ func (m *EventMutation) Fields() []string { return fields } -// Field returns the value of a field with the given name. -// The second boolean value indicates that this field was -// not set, or was not define in the schema. +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. func (m *EventMutation) Field(name string) (ent.Value, bool) { switch name { case event.FieldCreatedAt: @@ -4504,9 +4764,9 @@ func (m *EventMutation) Field(name string) (ent.Value, bool) { return nil, false } -// OldField returns the old value of the field from the database. -// An error is returned if the mutation operation is not UpdateOne, -// or the query to the database was failed. +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. func (m *EventMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case event.FieldCreatedAt: @@ -4521,9 +4781,9 @@ func (m *EventMutation) OldField(ctx context.Context, name string) (ent.Value, e return nil, fmt.Errorf("unknown Event field %s", name) } -// SetField sets the value for the given name. It returns an -// error if the field is not defined in the schema, or if the -// type mismatch the field type. +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. func (m *EventMutation) SetField(name string, value ent.Value) error { switch name { case event.FieldCreatedAt: @@ -4558,50 +4818,49 @@ func (m *EventMutation) SetField(name string, value ent.Value) error { return fmt.Errorf("unknown Event field %s", name) } -// AddedFields returns all numeric fields that were incremented -// or decremented during this mutation. +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. func (m *EventMutation) AddedFields() []string { return nil } -// AddedField returns the numeric value that was in/decremented -// from a field with the given name. The second value indicates -// that this field was not set, or was not define in the schema. +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. func (m *EventMutation) AddedField(name string) (ent.Value, bool) { return nil, false } -// AddField adds the value for the given name. It returns an -// error if the field is not defined in the schema, or if the -// type mismatch the field type. +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. func (m *EventMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Event numeric field %s", name) } -// ClearedFields returns all nullable fields that were cleared -// during this mutation. +// ClearedFields returns all nullable fields that were cleared during this +// mutation. func (m *EventMutation) ClearedFields() []string { return nil } -// FieldCleared returns a boolean indicates if this field was +// FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *EventMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } -// ClearField clears the value for the given name. It returns an +// ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *EventMutation) ClearField(name string) error { return fmt.Errorf("unknown Event nullable field %s", name) } -// ResetField resets all changes in the mutation regarding the -// given field name. It returns an error if the field is not -// defined in the schema. +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. func (m *EventMutation) ResetField(name string) error { switch name { case event.FieldCreatedAt: @@ -4620,8 +4879,7 @@ func (m *EventMutation) ResetField(name string) error { return fmt.Errorf("unknown Event field %s", name) } -// AddedEdges returns all edge names that were set/added in this -// mutation. +// AddedEdges returns all edge names that were set/added in this mutation. func (m *EventMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.owner != nil { @@ -4630,8 +4888,8 @@ func (m *EventMutation) AddedEdges() []string { return edges } -// AddedIDs returns all ids (to other nodes) that were added for -// the given edge name. +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. func (m *EventMutation) AddedIDs(name string) []ent.Value { switch name { case event.EdgeOwner: @@ -4642,23 +4900,21 @@ func (m *EventMutation) AddedIDs(name string) []ent.Value { return nil } -// RemovedEdges returns all edge names that were removed in this -// mutation. +// RemovedEdges returns all edge names that were removed in this mutation. func (m *EventMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } -// RemovedIDs returns all ids (to other nodes) that were removed for -// the given edge name. +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. func (m *EventMutation) RemovedIDs(name string) []ent.Value { switch name { } return nil } -// ClearedEdges returns all edge names that were cleared in this -// mutation. +// ClearedEdges returns all edge names that were cleared in this mutation. func (m *EventMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedowner { @@ -4667,8 +4923,8 @@ func (m *EventMutation) ClearedEdges() []string { return edges } -// EdgeCleared returns a boolean indicates if this edge was -// cleared in this mutation. +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. func (m *EventMutation) EdgeCleared(name string) bool { switch name { case event.EdgeOwner: @@ -4677,8 +4933,8 @@ func (m *EventMutation) EdgeCleared(name string) bool { return false } -// ClearEdge clears the value for the given name. It returns an -// error if the edge name is not defined in the schema. +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. func (m *EventMutation) ClearEdge(name string) error { switch name { case event.EdgeOwner: @@ -4688,9 +4944,8 @@ func (m *EventMutation) ClearEdge(name string) error { return fmt.Errorf("unknown Event unique edge %s", name) } -// ResetEdge resets all changes in the mutation regarding the -// given edge name. It returns an error if the edge is not -// defined in the schema. +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. func (m *EventMutation) ResetEdge(name string) error { switch name { case event.EdgeOwner: @@ -4700,8 +4955,7 @@ func (m *EventMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Event edge %s", name) } -// MachineMutation represents an operation that mutate the Machines -// nodes in the graph. +// MachineMutation represents an operation that mutates the Machine nodes in the graph. type MachineMutation struct { config op Op @@ -4722,14 +4976,15 @@ type MachineMutation struct { clearedalerts bool done bool oldValue func(context.Context) (*Machine, error) + predicates []predicate.Machine } var _ ent.Mutation = (*MachineMutation)(nil) -// machineOption allows to manage the mutation configuration using functional options. +// machineOption allows management of the mutation configuration using functional options. type machineOption func(*MachineMutation) -// newMachineMutation creates new mutation for $n.Name. +// newMachineMutation creates new mutation for the Machine entity. func newMachineMutation(c config, op Op, opts ...machineOption) *MachineMutation { m := &MachineMutation{ config: c, @@ -4743,7 +4998,7 @@ func newMachineMutation(c config, op Op, opts ...machineOption) *MachineMutation return m } -// withMachineID sets the id field of the mutation. +// withMachineID sets the ID field of the mutation. func withMachineID(id int) machineOption { return func(m *MachineMutation) { var ( @@ -4794,8 +5049,8 @@ func (m MachineMutation) Tx() (*Tx, error) { return tx, nil } -// ID returns the id value in the mutation. Note that, the id -// is available only if it was provided to the builder. +// ID returns the ID value in the mutation. Note that the ID +// is only available if it was provided to the builder. func (m *MachineMutation) ID() (id int, exists bool) { if m.id == nil { return @@ -4803,12 +5058,12 @@ func (m *MachineMutation) ID() (id int, exists bool) { return *m.id, true } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (m *MachineMutation) SetCreatedAt(t time.Time) { m.created_at = &t } -// CreatedAt returns the created_at value in the mutation. +// CreatedAt returns the value of the "created_at" field in the mutation. func (m *MachineMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { @@ -4817,13 +5072,12 @@ func (m *MachineMutation) CreatedAt() (r time.Time, exists bool) { return *v, true } -// OldCreatedAt returns the old created_at value of the Machine. -// If the Machine object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldCreatedAt returns the old "created_at" field's value of the Machine entity. +// If the Machine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MachineMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") @@ -4835,17 +5089,17 @@ func (m *MachineMutation) OldCreatedAt(ctx context.Context) (v time.Time, err er return oldValue.CreatedAt, nil } -// ResetCreatedAt reset all changes of the "created_at" field. +// ResetCreatedAt resets all changes to the "created_at" field. func (m *MachineMutation) ResetCreatedAt() { m.created_at = nil } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (m *MachineMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } -// UpdatedAt returns the updated_at value in the mutation. +// UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *MachineMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { @@ -4854,13 +5108,12 @@ func (m *MachineMutation) UpdatedAt() (r time.Time, exists bool) { return *v, true } -// OldUpdatedAt returns the old updated_at value of the Machine. -// If the Machine object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldUpdatedAt returns the old "updated_at" field's value of the Machine entity. +// If the Machine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MachineMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") @@ -4872,17 +5125,17 @@ func (m *MachineMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err er return oldValue.UpdatedAt, nil } -// ResetUpdatedAt reset all changes of the "updated_at" field. +// ResetUpdatedAt resets all changes to the "updated_at" field. func (m *MachineMutation) ResetUpdatedAt() { m.updated_at = nil } -// SetMachineId sets the machineId field. +// SetMachineId sets the "machineId" field. func (m *MachineMutation) SetMachineId(s string) { m.machineId = &s } -// MachineId returns the machineId value in the mutation. +// MachineId returns the value of the "machineId" field in the mutation. func (m *MachineMutation) MachineId() (r string, exists bool) { v := m.machineId if v == nil { @@ -4891,13 +5144,12 @@ func (m *MachineMutation) MachineId() (r string, exists bool) { return *v, true } -// OldMachineId returns the old machineId value of the Machine. -// If the Machine object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldMachineId returns the old "machineId" field's value of the Machine entity. +// If the Machine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MachineMutation) OldMachineId(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldMachineId is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldMachineId is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldMachineId requires an ID field in the mutation") @@ -4909,17 +5161,17 @@ func (m *MachineMutation) OldMachineId(ctx context.Context) (v string, err error return oldValue.MachineId, nil } -// ResetMachineId reset all changes of the "machineId" field. +// ResetMachineId resets all changes to the "machineId" field. func (m *MachineMutation) ResetMachineId() { m.machineId = nil } -// SetPassword sets the password field. +// SetPassword sets the "password" field. func (m *MachineMutation) SetPassword(s string) { m.password = &s } -// Password returns the password value in the mutation. +// Password returns the value of the "password" field in the mutation. func (m *MachineMutation) Password() (r string, exists bool) { v := m.password if v == nil { @@ -4928,13 +5180,12 @@ func (m *MachineMutation) Password() (r string, exists bool) { return *v, true } -// OldPassword returns the old password value of the Machine. -// If the Machine object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldPassword returns the old "password" field's value of the Machine entity. +// If the Machine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MachineMutation) OldPassword(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldPassword is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldPassword is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldPassword requires an ID field in the mutation") @@ -4946,17 +5197,17 @@ func (m *MachineMutation) OldPassword(ctx context.Context) (v string, err error) return oldValue.Password, nil } -// ResetPassword reset all changes of the "password" field. +// ResetPassword resets all changes to the "password" field. func (m *MachineMutation) ResetPassword() { m.password = nil } -// SetIpAddress sets the ipAddress field. +// SetIpAddress sets the "ipAddress" field. func (m *MachineMutation) SetIpAddress(s string) { m.ipAddress = &s } -// IpAddress returns the ipAddress value in the mutation. +// IpAddress returns the value of the "ipAddress" field in the mutation. func (m *MachineMutation) IpAddress() (r string, exists bool) { v := m.ipAddress if v == nil { @@ -4965,13 +5216,12 @@ func (m *MachineMutation) IpAddress() (r string, exists bool) { return *v, true } -// OldIpAddress returns the old ipAddress value of the Machine. -// If the Machine object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldIpAddress returns the old "ipAddress" field's value of the Machine entity. +// If the Machine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MachineMutation) OldIpAddress(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldIpAddress is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldIpAddress is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldIpAddress requires an ID field in the mutation") @@ -4983,17 +5233,17 @@ func (m *MachineMutation) OldIpAddress(ctx context.Context) (v string, err error return oldValue.IpAddress, nil } -// ResetIpAddress reset all changes of the "ipAddress" field. +// ResetIpAddress resets all changes to the "ipAddress" field. func (m *MachineMutation) ResetIpAddress() { m.ipAddress = nil } -// SetScenarios sets the scenarios field. +// SetScenarios sets the "scenarios" field. func (m *MachineMutation) SetScenarios(s string) { m.scenarios = &s } -// Scenarios returns the scenarios value in the mutation. +// Scenarios returns the value of the "scenarios" field in the mutation. func (m *MachineMutation) Scenarios() (r string, exists bool) { v := m.scenarios if v == nil { @@ -5002,13 +5252,12 @@ func (m *MachineMutation) Scenarios() (r string, exists bool) { return *v, true } -// OldScenarios returns the old scenarios value of the Machine. -// If the Machine object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldScenarios returns the old "scenarios" field's value of the Machine entity. +// If the Machine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MachineMutation) OldScenarios(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldScenarios is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldScenarios is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldScenarios requires an ID field in the mutation") @@ -5020,30 +5269,30 @@ func (m *MachineMutation) OldScenarios(ctx context.Context) (v string, err error return oldValue.Scenarios, nil } -// ClearScenarios clears the value of scenarios. +// ClearScenarios clears the value of the "scenarios" field. func (m *MachineMutation) ClearScenarios() { m.scenarios = nil m.clearedFields[machine.FieldScenarios] = struct{}{} } -// ScenariosCleared returns if the field scenarios was cleared in this mutation. +// ScenariosCleared returns if the "scenarios" field was cleared in this mutation. func (m *MachineMutation) ScenariosCleared() bool { _, ok := m.clearedFields[machine.FieldScenarios] return ok } -// ResetScenarios reset all changes of the "scenarios" field. +// ResetScenarios resets all changes to the "scenarios" field. func (m *MachineMutation) ResetScenarios() { m.scenarios = nil delete(m.clearedFields, machine.FieldScenarios) } -// SetVersion sets the version field. +// SetVersion sets the "version" field. func (m *MachineMutation) SetVersion(s string) { m.version = &s } -// Version returns the version value in the mutation. +// Version returns the value of the "version" field in the mutation. func (m *MachineMutation) Version() (r string, exists bool) { v := m.version if v == nil { @@ -5052,13 +5301,12 @@ func (m *MachineMutation) Version() (r string, exists bool) { return *v, true } -// OldVersion returns the old version value of the Machine. -// If the Machine object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldVersion returns the old "version" field's value of the Machine entity. +// If the Machine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MachineMutation) OldVersion(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldVersion is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldVersion requires an ID field in the mutation") @@ -5070,30 +5318,30 @@ func (m *MachineMutation) OldVersion(ctx context.Context) (v string, err error) return oldValue.Version, nil } -// ClearVersion clears the value of version. +// ClearVersion clears the value of the "version" field. func (m *MachineMutation) ClearVersion() { m.version = nil m.clearedFields[machine.FieldVersion] = struct{}{} } -// VersionCleared returns if the field version was cleared in this mutation. +// VersionCleared returns if the "version" field was cleared in this mutation. func (m *MachineMutation) VersionCleared() bool { _, ok := m.clearedFields[machine.FieldVersion] return ok } -// ResetVersion reset all changes of the "version" field. +// ResetVersion resets all changes to the "version" field. func (m *MachineMutation) ResetVersion() { m.version = nil delete(m.clearedFields, machine.FieldVersion) } -// SetIsValidated sets the isValidated field. +// SetIsValidated sets the "isValidated" field. func (m *MachineMutation) SetIsValidated(b bool) { m.isValidated = &b } -// IsValidated returns the isValidated value in the mutation. +// IsValidated returns the value of the "isValidated" field in the mutation. func (m *MachineMutation) IsValidated() (r bool, exists bool) { v := m.isValidated if v == nil { @@ -5102,13 +5350,12 @@ func (m *MachineMutation) IsValidated() (r bool, exists bool) { return *v, true } -// OldIsValidated returns the old isValidated value of the Machine. -// If the Machine object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldIsValidated returns the old "isValidated" field's value of the Machine entity. +// If the Machine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MachineMutation) OldIsValidated(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldIsValidated is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldIsValidated is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldIsValidated requires an ID field in the mutation") @@ -5120,17 +5367,17 @@ func (m *MachineMutation) OldIsValidated(ctx context.Context) (v bool, err error return oldValue.IsValidated, nil } -// ResetIsValidated reset all changes of the "isValidated" field. +// ResetIsValidated resets all changes to the "isValidated" field. func (m *MachineMutation) ResetIsValidated() { m.isValidated = nil } -// SetStatus sets the status field. +// SetStatus sets the "status" field. func (m *MachineMutation) SetStatus(s string) { m.status = &s } -// Status returns the status value in the mutation. +// Status returns the value of the "status" field in the mutation. func (m *MachineMutation) Status() (r string, exists bool) { v := m.status if v == nil { @@ -5139,13 +5386,12 @@ func (m *MachineMutation) Status() (r string, exists bool) { return *v, true } -// OldStatus returns the old status value of the Machine. -// If the Machine object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldStatus returns the old "status" field's value of the Machine entity. +// If the Machine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MachineMutation) OldStatus(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldStatus is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldStatus requires an ID field in the mutation") @@ -5157,25 +5403,25 @@ func (m *MachineMutation) OldStatus(ctx context.Context) (v string, err error) { return oldValue.Status, nil } -// ClearStatus clears the value of status. +// ClearStatus clears the value of the "status" field. func (m *MachineMutation) ClearStatus() { m.status = nil m.clearedFields[machine.FieldStatus] = struct{}{} } -// StatusCleared returns if the field status was cleared in this mutation. +// StatusCleared returns if the "status" field was cleared in this mutation. func (m *MachineMutation) StatusCleared() bool { _, ok := m.clearedFields[machine.FieldStatus] return ok } -// ResetStatus reset all changes of the "status" field. +// ResetStatus resets all changes to the "status" field. func (m *MachineMutation) ResetStatus() { m.status = nil delete(m.clearedFields, machine.FieldStatus) } -// AddAlertIDs adds the alerts edge to Alert by ids. +// AddAlertIDs adds the "alerts" edge to the Alert entity by ids. func (m *MachineMutation) AddAlertIDs(ids ...int) { if m.alerts == nil { m.alerts = make(map[int]struct{}) @@ -5185,17 +5431,17 @@ func (m *MachineMutation) AddAlertIDs(ids ...int) { } } -// ClearAlerts clears the alerts edge to Alert. +// ClearAlerts clears the "alerts" edge to the Alert entity. func (m *MachineMutation) ClearAlerts() { m.clearedalerts = true } -// AlertsCleared returns if the edge alerts was cleared. +// AlertsCleared returns if the "alerts" edge to the Alert entity was cleared. func (m *MachineMutation) AlertsCleared() bool { return m.clearedalerts } -// RemoveAlertIDs removes the alerts edge to Alert by ids. +// RemoveAlertIDs removes the "alerts" edge to the Alert entity by IDs. func (m *MachineMutation) RemoveAlertIDs(ids ...int) { if m.removedalerts == nil { m.removedalerts = make(map[int]struct{}) @@ -5205,7 +5451,7 @@ func (m *MachineMutation) RemoveAlertIDs(ids ...int) { } } -// RemovedAlerts returns the removed ids of alerts. +// RemovedAlerts returns the removed IDs of the "alerts" edge to the Alert entity. func (m *MachineMutation) RemovedAlertsIDs() (ids []int) { for id := range m.removedalerts { ids = append(ids, id) @@ -5213,7 +5459,7 @@ func (m *MachineMutation) RemovedAlertsIDs() (ids []int) { return } -// AlertsIDs returns the alerts ids in the mutation. +// AlertsIDs returns the "alerts" edge IDs in the mutation. func (m *MachineMutation) AlertsIDs() (ids []int) { for id := range m.alerts { ids = append(ids, id) @@ -5221,7 +5467,7 @@ func (m *MachineMutation) AlertsIDs() (ids []int) { return } -// ResetAlerts reset all changes of the "alerts" edge. +// ResetAlerts resets all changes to the "alerts" edge. func (m *MachineMutation) ResetAlerts() { m.alerts = nil m.clearedalerts = false @@ -5238,9 +5484,9 @@ func (m *MachineMutation) Type() string { return m.typ } -// Fields returns all fields that were changed during -// this mutation. Note that, in order to get all numeric -// fields that were in/decremented, call AddedFields(). +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). func (m *MachineMutation) Fields() []string { fields := make([]string, 0, 9) if m.created_at != nil { @@ -5273,9 +5519,9 @@ func (m *MachineMutation) Fields() []string { return fields } -// Field returns the value of a field with the given name. -// The second boolean value indicates that this field was -// not set, or was not define in the schema. +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. func (m *MachineMutation) Field(name string) (ent.Value, bool) { switch name { case machine.FieldCreatedAt: @@ -5300,9 +5546,9 @@ func (m *MachineMutation) Field(name string) (ent.Value, bool) { return nil, false } -// OldField returns the old value of the field from the database. -// An error is returned if the mutation operation is not UpdateOne, -// or the query to the database was failed. +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. func (m *MachineMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case machine.FieldCreatedAt: @@ -5327,9 +5573,9 @@ func (m *MachineMutation) OldField(ctx context.Context, name string) (ent.Value, return nil, fmt.Errorf("unknown Machine field %s", name) } -// SetField sets the value for the given name. It returns an -// error if the field is not defined in the schema, or if the -// type mismatch the field type. +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. func (m *MachineMutation) SetField(name string, value ent.Value) error { switch name { case machine.FieldCreatedAt: @@ -5399,30 +5645,30 @@ func (m *MachineMutation) SetField(name string, value ent.Value) error { return fmt.Errorf("unknown Machine field %s", name) } -// AddedFields returns all numeric fields that were incremented -// or decremented during this mutation. +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. func (m *MachineMutation) AddedFields() []string { return nil } -// AddedField returns the numeric value that was in/decremented -// from a field with the given name. The second value indicates -// that this field was not set, or was not define in the schema. +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. func (m *MachineMutation) AddedField(name string) (ent.Value, bool) { return nil, false } -// AddField adds the value for the given name. It returns an -// error if the field is not defined in the schema, or if the -// type mismatch the field type. +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. func (m *MachineMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Machine numeric field %s", name) } -// ClearedFields returns all nullable fields that were cleared -// during this mutation. +// ClearedFields returns all nullable fields that were cleared during this +// mutation. func (m *MachineMutation) ClearedFields() []string { var fields []string if m.FieldCleared(machine.FieldScenarios) { @@ -5437,14 +5683,14 @@ func (m *MachineMutation) ClearedFields() []string { return fields } -// FieldCleared returns a boolean indicates if this field was +// FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *MachineMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } -// ClearField clears the value for the given name. It returns an +// ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *MachineMutation) ClearField(name string) error { switch name { @@ -5461,9 +5707,8 @@ func (m *MachineMutation) ClearField(name string) error { return fmt.Errorf("unknown Machine nullable field %s", name) } -// ResetField resets all changes in the mutation regarding the -// given field name. It returns an error if the field is not -// defined in the schema. +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. func (m *MachineMutation) ResetField(name string) error { switch name { case machine.FieldCreatedAt: @@ -5497,8 +5742,7 @@ func (m *MachineMutation) ResetField(name string) error { return fmt.Errorf("unknown Machine field %s", name) } -// AddedEdges returns all edge names that were set/added in this -// mutation. +// AddedEdges returns all edge names that were set/added in this mutation. func (m *MachineMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.alerts != nil { @@ -5507,8 +5751,8 @@ func (m *MachineMutation) AddedEdges() []string { return edges } -// AddedIDs returns all ids (to other nodes) that were added for -// the given edge name. +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. func (m *MachineMutation) AddedIDs(name string) []ent.Value { switch name { case machine.EdgeAlerts: @@ -5521,8 +5765,7 @@ func (m *MachineMutation) AddedIDs(name string) []ent.Value { return nil } -// RemovedEdges returns all edge names that were removed in this -// mutation. +// RemovedEdges returns all edge names that were removed in this mutation. func (m *MachineMutation) RemovedEdges() []string { edges := make([]string, 0, 1) if m.removedalerts != nil { @@ -5531,8 +5774,8 @@ func (m *MachineMutation) RemovedEdges() []string { return edges } -// RemovedIDs returns all ids (to other nodes) that were removed for -// the given edge name. +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. func (m *MachineMutation) RemovedIDs(name string) []ent.Value { switch name { case machine.EdgeAlerts: @@ -5545,8 +5788,7 @@ func (m *MachineMutation) RemovedIDs(name string) []ent.Value { return nil } -// ClearedEdges returns all edge names that were cleared in this -// mutation. +// ClearedEdges returns all edge names that were cleared in this mutation. func (m *MachineMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedalerts { @@ -5555,8 +5797,8 @@ func (m *MachineMutation) ClearedEdges() []string { return edges } -// EdgeCleared returns a boolean indicates if this edge was -// cleared in this mutation. +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. func (m *MachineMutation) EdgeCleared(name string) bool { switch name { case machine.EdgeAlerts: @@ -5565,17 +5807,16 @@ func (m *MachineMutation) EdgeCleared(name string) bool { return false } -// ClearEdge clears the value for the given name. It returns an -// error if the edge name is not defined in the schema. +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. func (m *MachineMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown Machine unique edge %s", name) } -// ResetEdge resets all changes in the mutation regarding the -// given edge name. It returns an error if the edge is not -// defined in the schema. +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. func (m *MachineMutation) ResetEdge(name string) error { switch name { case machine.EdgeAlerts: @@ -5585,8 +5826,7 @@ func (m *MachineMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Machine edge %s", name) } -// MetaMutation represents an operation that mutate the MetaSlice -// nodes in the graph. +// MetaMutation represents an operation that mutates the Meta nodes in the graph. type MetaMutation struct { config op Op @@ -5601,14 +5841,15 @@ type MetaMutation struct { clearedowner bool done bool oldValue func(context.Context) (*Meta, error) + predicates []predicate.Meta } var _ ent.Mutation = (*MetaMutation)(nil) -// metaOption allows to manage the mutation configuration using functional options. +// metaOption allows management of the mutation configuration using functional options. type metaOption func(*MetaMutation) -// newMetaMutation creates new mutation for $n.Name. +// newMetaMutation creates new mutation for the Meta entity. func newMetaMutation(c config, op Op, opts ...metaOption) *MetaMutation { m := &MetaMutation{ config: c, @@ -5622,7 +5863,7 @@ func newMetaMutation(c config, op Op, opts ...metaOption) *MetaMutation { return m } -// withMetaID sets the id field of the mutation. +// withMetaID sets the ID field of the mutation. func withMetaID(id int) metaOption { return func(m *MetaMutation) { var ( @@ -5673,8 +5914,8 @@ func (m MetaMutation) Tx() (*Tx, error) { return tx, nil } -// ID returns the id value in the mutation. Note that, the id -// is available only if it was provided to the builder. +// ID returns the ID value in the mutation. Note that the ID +// is only available if it was provided to the builder. func (m *MetaMutation) ID() (id int, exists bool) { if m.id == nil { return @@ -5682,12 +5923,12 @@ func (m *MetaMutation) ID() (id int, exists bool) { return *m.id, true } -// SetCreatedAt sets the created_at field. +// SetCreatedAt sets the "created_at" field. func (m *MetaMutation) SetCreatedAt(t time.Time) { m.created_at = &t } -// CreatedAt returns the created_at value in the mutation. +// CreatedAt returns the value of the "created_at" field in the mutation. func (m *MetaMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { @@ -5696,13 +5937,12 @@ func (m *MetaMutation) CreatedAt() (r time.Time, exists bool) { return *v, true } -// OldCreatedAt returns the old created_at value of the Meta. -// If the Meta object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldCreatedAt returns the old "created_at" field's value of the Meta entity. +// If the Meta object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MetaMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") @@ -5714,17 +5954,17 @@ func (m *MetaMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error return oldValue.CreatedAt, nil } -// ResetCreatedAt reset all changes of the "created_at" field. +// ResetCreatedAt resets all changes to the "created_at" field. func (m *MetaMutation) ResetCreatedAt() { m.created_at = nil } -// SetUpdatedAt sets the updated_at field. +// SetUpdatedAt sets the "updated_at" field. func (m *MetaMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } -// UpdatedAt returns the updated_at value in the mutation. +// UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *MetaMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { @@ -5733,13 +5973,12 @@ func (m *MetaMutation) UpdatedAt() (r time.Time, exists bool) { return *v, true } -// OldUpdatedAt returns the old updated_at value of the Meta. -// If the Meta object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldUpdatedAt returns the old "updated_at" field's value of the Meta entity. +// If the Meta object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MetaMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") @@ -5751,17 +5990,17 @@ func (m *MetaMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error return oldValue.UpdatedAt, nil } -// ResetUpdatedAt reset all changes of the "updated_at" field. +// ResetUpdatedAt resets all changes to the "updated_at" field. func (m *MetaMutation) ResetUpdatedAt() { m.updated_at = nil } -// SetKey sets the key field. +// SetKey sets the "key" field. func (m *MetaMutation) SetKey(s string) { m.key = &s } -// Key returns the key value in the mutation. +// Key returns the value of the "key" field in the mutation. func (m *MetaMutation) Key() (r string, exists bool) { v := m.key if v == nil { @@ -5770,13 +6009,12 @@ func (m *MetaMutation) Key() (r string, exists bool) { return *v, true } -// OldKey returns the old key value of the Meta. -// If the Meta object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldKey returns the old "key" field's value of the Meta entity. +// If the Meta object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MetaMutation) OldKey(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldKey is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldKey is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldKey requires an ID field in the mutation") @@ -5788,17 +6026,17 @@ func (m *MetaMutation) OldKey(ctx context.Context) (v string, err error) { return oldValue.Key, nil } -// ResetKey reset all changes of the "key" field. +// ResetKey resets all changes to the "key" field. func (m *MetaMutation) ResetKey() { m.key = nil } -// SetValue sets the value field. +// SetValue sets the "value" field. func (m *MetaMutation) SetValue(s string) { m.value = &s } -// Value returns the value value in the mutation. +// Value returns the value of the "value" field in the mutation. func (m *MetaMutation) Value() (r string, exists bool) { v := m.value if v == nil { @@ -5807,13 +6045,12 @@ func (m *MetaMutation) Value() (r string, exists bool) { return *v, true } -// OldValue returns the old value value of the Meta. -// If the Meta object wasn't provided to the builder, the object is fetched -// from the database. -// An error is returned if the mutation operation is not UpdateOne, or database query fails. +// OldValue returns the old "value" field's value of the Meta entity. +// If the Meta object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MetaMutation) OldValue(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldValue is allowed only on UpdateOne operations") + return v, fmt.Errorf("OldValue is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, fmt.Errorf("OldValue requires an ID field in the mutation") @@ -5825,27 +6062,27 @@ func (m *MetaMutation) OldValue(ctx context.Context) (v string, err error) { return oldValue.Value, nil } -// ResetValue reset all changes of the "value" field. +// ResetValue resets all changes to the "value" field. func (m *MetaMutation) ResetValue() { m.value = nil } -// SetOwnerID sets the owner edge to Alert by id. +// SetOwnerID sets the "owner" edge to the Alert entity by id. func (m *MetaMutation) SetOwnerID(id int) { m.owner = &id } -// ClearOwner clears the owner edge to Alert. +// ClearOwner clears the "owner" edge to the Alert entity. func (m *MetaMutation) ClearOwner() { m.clearedowner = true } -// OwnerCleared returns if the edge owner was cleared. +// OwnerCleared returns if the "owner" edge to the Alert entity was cleared. func (m *MetaMutation) OwnerCleared() bool { return m.clearedowner } -// OwnerID returns the owner id in the mutation. +// OwnerID returns the "owner" edge ID in the mutation. func (m *MetaMutation) OwnerID() (id int, exists bool) { if m.owner != nil { return *m.owner, true @@ -5853,8 +6090,8 @@ func (m *MetaMutation) OwnerID() (id int, exists bool) { return } -// OwnerIDs returns the owner ids in the mutation. -// Note that ids always returns len(ids) <= 1 for unique edges, and you should use +// OwnerIDs returns the "owner" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // OwnerID instead. It exists only for internal usage by the builders. func (m *MetaMutation) OwnerIDs() (ids []int) { if id := m.owner; id != nil { @@ -5863,7 +6100,7 @@ func (m *MetaMutation) OwnerIDs() (ids []int) { return } -// ResetOwner reset all changes of the "owner" edge. +// ResetOwner resets all changes to the "owner" edge. func (m *MetaMutation) ResetOwner() { m.owner = nil m.clearedowner = false @@ -5879,9 +6116,9 @@ func (m *MetaMutation) Type() string { return m.typ } -// Fields returns all fields that were changed during -// this mutation. Note that, in order to get all numeric -// fields that were in/decremented, call AddedFields(). +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). func (m *MetaMutation) Fields() []string { fields := make([]string, 0, 4) if m.created_at != nil { @@ -5899,9 +6136,9 @@ func (m *MetaMutation) Fields() []string { return fields } -// Field returns the value of a field with the given name. -// The second boolean value indicates that this field was -// not set, or was not define in the schema. +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. func (m *MetaMutation) Field(name string) (ent.Value, bool) { switch name { case meta.FieldCreatedAt: @@ -5916,9 +6153,9 @@ func (m *MetaMutation) Field(name string) (ent.Value, bool) { return nil, false } -// OldField returns the old value of the field from the database. -// An error is returned if the mutation operation is not UpdateOne, -// or the query to the database was failed. +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. func (m *MetaMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case meta.FieldCreatedAt: @@ -5933,9 +6170,9 @@ func (m *MetaMutation) OldField(ctx context.Context, name string) (ent.Value, er return nil, fmt.Errorf("unknown Meta field %s", name) } -// SetField sets the value for the given name. It returns an -// error if the field is not defined in the schema, or if the -// type mismatch the field type. +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. func (m *MetaMutation) SetField(name string, value ent.Value) error { switch name { case meta.FieldCreatedAt: @@ -5970,50 +6207,49 @@ func (m *MetaMutation) SetField(name string, value ent.Value) error { return fmt.Errorf("unknown Meta field %s", name) } -// AddedFields returns all numeric fields that were incremented -// or decremented during this mutation. +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. func (m *MetaMutation) AddedFields() []string { return nil } -// AddedField returns the numeric value that was in/decremented -// from a field with the given name. The second value indicates -// that this field was not set, or was not define in the schema. +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. func (m *MetaMutation) AddedField(name string) (ent.Value, bool) { return nil, false } -// AddField adds the value for the given name. It returns an -// error if the field is not defined in the schema, or if the -// type mismatch the field type. +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. func (m *MetaMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Meta numeric field %s", name) } -// ClearedFields returns all nullable fields that were cleared -// during this mutation. +// ClearedFields returns all nullable fields that were cleared during this +// mutation. func (m *MetaMutation) ClearedFields() []string { return nil } -// FieldCleared returns a boolean indicates if this field was +// FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *MetaMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } -// ClearField clears the value for the given name. It returns an +// ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *MetaMutation) ClearField(name string) error { return fmt.Errorf("unknown Meta nullable field %s", name) } -// ResetField resets all changes in the mutation regarding the -// given field name. It returns an error if the field is not -// defined in the schema. +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. func (m *MetaMutation) ResetField(name string) error { switch name { case meta.FieldCreatedAt: @@ -6032,8 +6268,7 @@ func (m *MetaMutation) ResetField(name string) error { return fmt.Errorf("unknown Meta field %s", name) } -// AddedEdges returns all edge names that were set/added in this -// mutation. +// AddedEdges returns all edge names that were set/added in this mutation. func (m *MetaMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.owner != nil { @@ -6042,8 +6277,8 @@ func (m *MetaMutation) AddedEdges() []string { return edges } -// AddedIDs returns all ids (to other nodes) that were added for -// the given edge name. +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. func (m *MetaMutation) AddedIDs(name string) []ent.Value { switch name { case meta.EdgeOwner: @@ -6054,23 +6289,21 @@ func (m *MetaMutation) AddedIDs(name string) []ent.Value { return nil } -// RemovedEdges returns all edge names that were removed in this -// mutation. +// RemovedEdges returns all edge names that were removed in this mutation. func (m *MetaMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } -// RemovedIDs returns all ids (to other nodes) that were removed for -// the given edge name. +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. func (m *MetaMutation) RemovedIDs(name string) []ent.Value { switch name { } return nil } -// ClearedEdges returns all edge names that were cleared in this -// mutation. +// ClearedEdges returns all edge names that were cleared in this mutation. func (m *MetaMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedowner { @@ -6079,8 +6312,8 @@ func (m *MetaMutation) ClearedEdges() []string { return edges } -// EdgeCleared returns a boolean indicates if this edge was -// cleared in this mutation. +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. func (m *MetaMutation) EdgeCleared(name string) bool { switch name { case meta.EdgeOwner: @@ -6089,8 +6322,8 @@ func (m *MetaMutation) EdgeCleared(name string) bool { return false } -// ClearEdge clears the value for the given name. It returns an -// error if the edge name is not defined in the schema. +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. func (m *MetaMutation) ClearEdge(name string) error { switch name { case meta.EdgeOwner: @@ -6100,9 +6333,8 @@ func (m *MetaMutation) ClearEdge(name string) error { return fmt.Errorf("unknown Meta unique edge %s", name) } -// ResetEdge resets all changes in the mutation regarding the -// given edge name. It returns an error if the edge is not -// defined in the schema. +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. func (m *MetaMutation) ResetEdge(name string) error { switch name { case meta.EdgeOwner: diff --git a/pkg/database/ent/privacy/privacy.go b/pkg/database/ent/privacy/privacy.go deleted file mode 100644 index 5407a51be..000000000 --- a/pkg/database/ent/privacy/privacy.go +++ /dev/null @@ -1,355 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package privacy - -import ( - "context" - "errors" - "fmt" - - "github.com/crowdsecurity/crowdsec/pkg/database/ent" -) - -var ( - // Allow may be returned by rules to indicate that the policy - // evaluation should terminate with an allow decision. - Allow = errors.New("ent/privacy: allow rule") - - // Deny may be returned by rules to indicate that the policy - // evaluation should terminate with an deny decision. - Deny = errors.New("ent/privacy: deny rule") - - // Skip may be returned by rules to indicate that the policy - // evaluation should continue to the next rule. - Skip = errors.New("ent/privacy: skip rule") -) - -// Allowf returns an formatted wrapped Allow decision. -func Allowf(format string, a ...interface{}) error { - return fmt.Errorf(format+": %w", append(a, Allow)...) -} - -// Denyf returns an formatted wrapped Deny decision. -func Denyf(format string, a ...interface{}) error { - return fmt.Errorf(format+": %w", append(a, Deny)...) -} - -// Skipf returns an formatted wrapped Skip decision. -func Skipf(format string, a ...interface{}) error { - return fmt.Errorf(format+": %w", append(a, Skip)...) -} - -type decisionCtxKey struct{} - -// DecisionContext creates a decision context. -func DecisionContext(parent context.Context, decision error) context.Context { - if decision == nil || errors.Is(decision, Skip) { - return parent - } - return context.WithValue(parent, decisionCtxKey{}, decision) -} - -func decisionFromContext(ctx context.Context) (error, bool) { - decision, ok := ctx.Value(decisionCtxKey{}).(error) - if ok && errors.Is(decision, Allow) { - decision = nil - } - return decision, ok -} - -type ( - // QueryPolicy combines multiple query rules into a single policy. - QueryPolicy []QueryRule - - // QueryRule defines the interface deciding whether a - // query is allowed and optionally modify it. - QueryRule interface { - EvalQuery(context.Context, ent.Query) error - } -) - -// EvalQuery evaluates a query against a query policy. -func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { - if decision, ok := decisionFromContext(ctx); ok { - return decision - } - for _, rule := range policy { - switch decision := rule.EvalQuery(ctx, q); { - case decision == nil || errors.Is(decision, Skip): - case errors.Is(decision, Allow): - return nil - default: - return decision - } - } - return nil -} - -// QueryRuleFunc type is an adapter to allow the use of -// ordinary functions as query rules. -type QueryRuleFunc func(context.Context, ent.Query) error - -// Eval returns f(ctx, q). -func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { - return f(ctx, q) -} - -type ( - // MutationPolicy combines multiple mutation rules into a single policy. - MutationPolicy []MutationRule - - // MutationRule defines the interface deciding whether a - // mutation is allowed and optionally modify it. - MutationRule interface { - EvalMutation(context.Context, ent.Mutation) error - } -) - -// EvalMutation evaluates a mutation against a mutation policy. -func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { - if decision, ok := decisionFromContext(ctx); ok { - return decision - } - for _, rule := range policy { - switch decision := rule.EvalMutation(ctx, m); { - case decision == nil || errors.Is(decision, Skip): - case errors.Is(decision, Allow): - return nil - default: - return decision - } - } - return nil -} - -// MutationRuleFunc type is an adapter to allow the use of -// ordinary functions as mutation rules. -type MutationRuleFunc func(context.Context, ent.Mutation) error - -// EvalMutation returns f(ctx, m). -func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { - return f(ctx, m) -} - -// Policy groups query and mutation policies. -type Policy struct { - Query QueryPolicy - Mutation MutationPolicy -} - -// EvalQuery forwards evaluation to query policy. -func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { - return policy.Query.EvalQuery(ctx, q) -} - -// EvalMutation forwards evaluation to mutation policy. -func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { - return policy.Mutation.EvalMutation(ctx, m) -} - -// QueryMutationRule is the interface that groups query and mutation rules. -type QueryMutationRule interface { - QueryRule - MutationRule -} - -// AlwaysAllowRule returns a rule that returns an allow decision. -func AlwaysAllowRule() QueryMutationRule { - return fixedDecision{Allow} -} - -// AlwaysDenyRule returns a rule that returns a deny decision. -func AlwaysDenyRule() QueryMutationRule { - return fixedDecision{Deny} -} - -type fixedDecision struct { - decision error -} - -func (f fixedDecision) EvalQuery(context.Context, ent.Query) error { - return f.decision -} - -func (f fixedDecision) EvalMutation(context.Context, ent.Mutation) error { - return f.decision -} - -type contextDecision struct { - eval func(context.Context) error -} - -// ContextQueryMutationRule creates a query/mutation rule from a context eval func. -func ContextQueryMutationRule(eval func(context.Context) error) QueryMutationRule { - return contextDecision{eval} -} - -func (c contextDecision) EvalQuery(ctx context.Context, _ ent.Query) error { - return c.eval(ctx) -} - -func (c contextDecision) EvalMutation(ctx context.Context, _ ent.Mutation) error { - return c.eval(ctx) -} - -// OnMutationOperation evaluates the given rule only on a given mutation operation. -func OnMutationOperation(rule MutationRule, op ent.Op) MutationRule { - return MutationRuleFunc(func(ctx context.Context, m ent.Mutation) error { - if m.Op().Is(op) { - return rule.EvalMutation(ctx, m) - } - return Skip - }) -} - -// DenyMutationOperationRule returns a rule denying specified mutation operation. -func DenyMutationOperationRule(op ent.Op) MutationRule { - rule := MutationRuleFunc(func(_ context.Context, m ent.Mutation) error { - return Denyf("ent/privacy: operation %s is not allowed", m.Op()) - }) - return OnMutationOperation(rule, op) -} - -// The AlertQueryRuleFunc type is an adapter to allow the use of ordinary -// functions as a query rule. -type AlertQueryRuleFunc func(context.Context, *ent.AlertQuery) error - -// EvalQuery return f(ctx, q). -func (f AlertQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { - if q, ok := q.(*ent.AlertQuery); ok { - return f(ctx, q) - } - return Denyf("ent/privacy: unexpected query type %T, expect *ent.AlertQuery", q) -} - -// The AlertMutationRuleFunc type is an adapter to allow the use of ordinary -// functions as a mutation rule. -type AlertMutationRuleFunc func(context.Context, *ent.AlertMutation) error - -// EvalMutation calls f(ctx, m). -func (f AlertMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { - if m, ok := m.(*ent.AlertMutation); ok { - return f(ctx, m) - } - return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.AlertMutation", m) -} - -// The BouncerQueryRuleFunc type is an adapter to allow the use of ordinary -// functions as a query rule. -type BouncerQueryRuleFunc func(context.Context, *ent.BouncerQuery) error - -// EvalQuery return f(ctx, q). -func (f BouncerQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { - if q, ok := q.(*ent.BouncerQuery); ok { - return f(ctx, q) - } - return Denyf("ent/privacy: unexpected query type %T, expect *ent.BouncerQuery", q) -} - -// The BouncerMutationRuleFunc type is an adapter to allow the use of ordinary -// functions as a mutation rule. -type BouncerMutationRuleFunc func(context.Context, *ent.BouncerMutation) error - -// EvalMutation calls f(ctx, m). -func (f BouncerMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { - if m, ok := m.(*ent.BouncerMutation); ok { - return f(ctx, m) - } - return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.BouncerMutation", m) -} - -// The DecisionQueryRuleFunc type is an adapter to allow the use of ordinary -// functions as a query rule. -type DecisionQueryRuleFunc func(context.Context, *ent.DecisionQuery) error - -// EvalQuery return f(ctx, q). -func (f DecisionQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { - if q, ok := q.(*ent.DecisionQuery); ok { - return f(ctx, q) - } - return Denyf("ent/privacy: unexpected query type %T, expect *ent.DecisionQuery", q) -} - -// The DecisionMutationRuleFunc type is an adapter to allow the use of ordinary -// functions as a mutation rule. -type DecisionMutationRuleFunc func(context.Context, *ent.DecisionMutation) error - -// EvalMutation calls f(ctx, m). -func (f DecisionMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { - if m, ok := m.(*ent.DecisionMutation); ok { - return f(ctx, m) - } - return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.DecisionMutation", m) -} - -// The EventQueryRuleFunc type is an adapter to allow the use of ordinary -// functions as a query rule. -type EventQueryRuleFunc func(context.Context, *ent.EventQuery) error - -// EvalQuery return f(ctx, q). -func (f EventQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { - if q, ok := q.(*ent.EventQuery); ok { - return f(ctx, q) - } - return Denyf("ent/privacy: unexpected query type %T, expect *ent.EventQuery", q) -} - -// The EventMutationRuleFunc type is an adapter to allow the use of ordinary -// functions as a mutation rule. -type EventMutationRuleFunc func(context.Context, *ent.EventMutation) error - -// EvalMutation calls f(ctx, m). -func (f EventMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { - if m, ok := m.(*ent.EventMutation); ok { - return f(ctx, m) - } - return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.EventMutation", m) -} - -// The MachineQueryRuleFunc type is an adapter to allow the use of ordinary -// functions as a query rule. -type MachineQueryRuleFunc func(context.Context, *ent.MachineQuery) error - -// EvalQuery return f(ctx, q). -func (f MachineQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { - if q, ok := q.(*ent.MachineQuery); ok { - return f(ctx, q) - } - return Denyf("ent/privacy: unexpected query type %T, expect *ent.MachineQuery", q) -} - -// The MachineMutationRuleFunc type is an adapter to allow the use of ordinary -// functions as a mutation rule. -type MachineMutationRuleFunc func(context.Context, *ent.MachineMutation) error - -// EvalMutation calls f(ctx, m). -func (f MachineMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { - if m, ok := m.(*ent.MachineMutation); ok { - return f(ctx, m) - } - return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.MachineMutation", m) -} - -// The MetaQueryRuleFunc type is an adapter to allow the use of ordinary -// functions as a query rule. -type MetaQueryRuleFunc func(context.Context, *ent.MetaQuery) error - -// EvalQuery return f(ctx, q). -func (f MetaQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { - if q, ok := q.(*ent.MetaQuery); ok { - return f(ctx, q) - } - return Denyf("ent/privacy: unexpected query type %T, expect *ent.MetaQuery", q) -} - -// The MetaMutationRuleFunc type is an adapter to allow the use of ordinary -// functions as a mutation rule. -type MetaMutationRuleFunc func(context.Context, *ent.MetaMutation) error - -// EvalMutation calls f(ctx, m). -func (f MetaMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { - if m, ok := m.(*ent.MetaMutation); ok { - return f(ctx, m) - } - return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.MetaMutation", m) -} diff --git a/pkg/database/ent/runtime.go b/pkg/database/ent/runtime.go index e95336d98..f6be19afa 100644 --- a/pkg/database/ent/runtime.go +++ b/pkg/database/ent/runtime.go @@ -14,8 +14,8 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/database/ent/schema" ) -// The init function reads all schema descriptors with runtime -// code (default values, validators or hooks) and stitches it +// The init function reads all schema descriptors with runtime code +// (default values, validators, hooks and policies) and stitches it // to their package variables. func init() { alertFields := schema.Alert{}.Fields() @@ -85,7 +85,7 @@ func init() { // decision.DefaultUpdatedAt holds the default value on creation for the updated_at field. decision.DefaultUpdatedAt = decisionDescUpdatedAt.Default.(func() time.Time) // decisionDescSimulated is the schema descriptor for simulated field. - decisionDescSimulated := decisionFields[10].Descriptor() + decisionDescSimulated := decisionFields[13].Descriptor() // decision.DefaultSimulated holds the default value on creation for the simulated field. decision.DefaultSimulated = decisionDescSimulated.Default.(bool) eventFields := schema.Event{}.Fields() diff --git a/pkg/database/ent/runtime/runtime.go b/pkg/database/ent/runtime/runtime.go index 301ca1f6d..b3894bb54 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.4.3" // Version of ent codegen. - Sum = "h1:ds9HENceKzpGBgCRlkZNq6TqBIegwKcF3e5reuV9Z0M=" // Sum of ent codegen. + Version = "v0.5.4" // Version of ent codegen. + Sum = "h1:kIf2BQUdRJ7XrlTXzCyJCg69ar1K1FjFR2UQWRo/M8M=" // Sum of ent codegen. ) diff --git a/pkg/database/ent/schema/decision.go b/pkg/database/ent/schema/decision.go index a102f9f1a..576051398 100644 --- a/pkg/database/ent/schema/decision.go +++ b/pkg/database/ent/schema/decision.go @@ -25,6 +25,9 @@ func (Decision) Fields() []ent.Field { field.String("type"), field.Int64("start_ip").Optional(), field.Int64("end_ip").Optional(), + field.Int64("start_suffix").Optional(), + field.Int64("end_suffix").Optional(), + field.Int64("ip_size").Optional(), field.String("scope"), field.String("value"), field.String("origin"), diff --git a/pkg/models/decision.go b/pkg/models/decision.go index 0d05c1a93..de9a78edc 100644 --- a/pkg/models/decision.go +++ b/pkg/models/decision.go @@ -21,9 +21,6 @@ type Decision struct { // Required: true Duration *string `json:"duration"` - // (only relevant for GET ops) when the value is an IP or range, its numeric representation - EndIP int64 `json:"end_ip,omitempty"` - // (only relevant for GET ops) the unique id // Read Only: true ID int64 `json:"id,omitempty"` @@ -44,9 +41,6 @@ type Decision struct { // Read Only: true Simulated *bool `json:"simulated,omitempty"` - // (only relevant for GET ops) when the value is an IP or range, its numeric representation - StartIP int64 `json:"start_ip,omitempty"` - // the type of decision, might be 'ban', 'captcha' or something custom. Ignored when watcher (cscli/crowdsec) is pushing to APIL. // Required: true Type *string `json:"type"` diff --git a/pkg/models/localapi_swagger.yaml b/pkg/models/localapi_swagger.yaml index f868758ba..2d8cac399 100644 --- a/pkg/models/localapi_swagger.yaml +++ b/pkg/models/localapi_swagger.yaml @@ -802,12 +802,6 @@ definitions: value: description: 'the value of the decision scope : an IP, a range, a username, etc' type: string - start_ip: - description: '(only relevant for GET ops) when the value is an IP or range, its numeric representation' - type: integer - end_ip: - description: '(only relevant for GET ops) when the value is an IP or range, its numeric representation' - type: integer duration: type: string scenario: diff --git a/pkg/types/ip.go b/pkg/types/ip.go new file mode 100644 index 000000000..62104a212 --- /dev/null +++ b/pkg/types/ip.go @@ -0,0 +1,106 @@ +package types + +import ( + "encoding/binary" + "fmt" + "math" + "net" + "strings" + + "github.com/pkg/errors" +) + +func LastAddress(n net.IPNet) net.IP { + ip := n.IP.To4() + if ip == nil { + ip = n.IP + return net.IP{ + ip[0] | ^n.Mask[0], ip[1] | ^n.Mask[1], ip[2] | ^n.Mask[2], + ip[3] | ^n.Mask[3], ip[4] | ^n.Mask[4], ip[5] | ^n.Mask[5], + ip[6] | ^n.Mask[6], ip[7] | ^n.Mask[7], ip[8] | ^n.Mask[8], + ip[9] | ^n.Mask[9], ip[10] | ^n.Mask[10], ip[11] | ^n.Mask[11], + ip[12] | ^n.Mask[12], ip[13] | ^n.Mask[13], ip[14] | ^n.Mask[14], + ip[15] | ^n.Mask[15]} + } + + return net.IPv4( + ip[0]|^n.Mask[0], + ip[1]|^n.Mask[1], + ip[2]|^n.Mask[2], + ip[3]|^n.Mask[3]) +} + +/*returns a range for any ip or range*/ +func Addr2Ints(any string) (int, int64, int64, int64, int64, error) { + if strings.Contains(any, "/") { + _, net, err := net.ParseCIDR(any) + if err != nil { + return -1, 0, 0, 0, 0, errors.Wrapf(err, "while parsing range %s", any) + } + return Range2Ints(*net) + } else { + ip := net.ParseIP(any) + if ip == nil { + return -1, 0, 0, 0, 0, fmt.Errorf("invalid address") + } + sz, start, end, err := IP2Ints(ip) + if err != nil { + return -1, 0, 0, 0, 0, errors.Wrapf(err, "while parsing ip %s", any) + } + return sz, start, end, start, end, nil + } +} + +/*size (16|4), nw_start, suffix_start, nw_end, suffix_end, error*/ +func Range2Ints(network net.IPNet) (int, int64, int64, int64, int64, error) { + + szStart, nwStart, sfxStart, err := IP2Ints(network.IP) + if err != nil { + return -1, 0, 0, 0, 0, errors.Wrap(err, "converting first ip in range") + } + lastAddr := LastAddress(network) + szEnd, nwEnd, sfxEnd, err := IP2Ints(lastAddr) + if err != nil { + return -1, 0, 0, 0, 0, errors.Wrap(err, "transforming last address of range") + } + if szEnd != szStart { + return -1, 0, 0, 0, 0, fmt.Errorf("inconsistent size for range first(%d) and last(%d) ip", szStart, szEnd) + } + return szStart, nwStart, sfxStart, nwEnd, sfxEnd, nil +} + +func uint2int(u uint64) int64 { + var ret int64 + if u == math.MaxInt64 { + ret = 0 + } else if u == math.MaxUint64 { + ret = math.MaxInt64 + } else if u > math.MaxInt64 { + u -= math.MaxInt64 + ret = int64(u) + } else { + ret = int64(u) + ret -= math.MaxInt64 + } + return ret +} + +/*size (16|4), network, suffix, error*/ +func IP2Ints(pip net.IP) (int, int64, int64, error) { + var ip_nw, ip_sfx uint64 + + pip4 := pip.To4() + pip16 := pip.To16() + + if pip4 != nil { + ip_nw32 := binary.BigEndian.Uint32(pip4) + + return 4, uint2int(uint64(ip_nw32)), uint2int(ip_sfx), nil + } else if pip16 != nil { + ip_nw = binary.BigEndian.Uint64(pip16[0:8]) + ip_sfx = binary.BigEndian.Uint64(pip16[8:16]) + return 16, uint2int(ip_nw), uint2int(ip_sfx), nil + } else { + return -1, 0, 0, fmt.Errorf("unexpected len %d for %s", len(pip), pip) + } +} diff --git a/pkg/types/ip_test.go b/pkg/types/ip_test.go new file mode 100644 index 000000000..d978d7110 --- /dev/null +++ b/pkg/types/ip_test.go @@ -0,0 +1,220 @@ +package types + +import ( + "math" + "net" + "strings" + "testing" +) + +func TestIP2Int(t *testing.T) { + + tEmpty := net.IP{} + _, _, _, err := IP2Ints(tEmpty) + if !strings.Contains(err.Error(), "unexpected len 0 for ") { + t.Fatalf("unexpected: %s", err.Error()) + } +} +func TestRange2Int(t *testing.T) { + tEmpty := net.IPNet{} + //empty item + _, _, _, _, _, err := Range2Ints(tEmpty) + if !strings.Contains(err.Error(), "converting first ip in range") { + t.Fatalf("unexpected: %s", err.Error()) + } + +} + +func TestAdd2Int(t *testing.T) { + tests := []struct { + in_addr string + exp_sz int + exp_start_ip int64 + exp_start_sfx int64 + exp_end_ip int64 + exp_end_sfx int64 + exp_error string + }{ + { + in_addr: "7FFF:FFFF:FFFF:FFFF:aaaa:aaaa:aaaa:fff7", + + exp_sz: 16, + exp_start_ip: -math.MaxInt64 + 0x7FFFFFFFFFFFFFFF, + exp_start_sfx: -math.MaxInt64 + 0xaaaaaaaaaaaafff7, + exp_end_ip: -math.MaxInt64 + 0x7FFFFFFFFFFFFFFF, + exp_end_sfx: -math.MaxInt64 + 0xaaaaaaaaaaaafff7, + }, + { + in_addr: "aaaa:aaaa:aaaa:aaaa:aaaa:aaaa:aaaa:fff7", + + exp_sz: 16, + exp_start_ip: -math.MaxInt64 + 0xaaaaaaaaaaaaaaaa, + exp_start_sfx: -math.MaxInt64 + 0xaaaaaaaaaaaafff7, + exp_end_ip: -math.MaxInt64 + 0xaaaaaaaaaaaaaaaa, + exp_end_sfx: -math.MaxInt64 + 0xaaaaaaaaaaaafff7, + }, + { + in_addr: "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff7", + /*ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff*/ + + exp_sz: 16, + exp_start_ip: math.MaxInt64, + exp_start_sfx: -math.MaxInt64 + 0xfffffffffffffff7, + exp_end_ip: math.MaxInt64, + exp_end_sfx: -math.MaxInt64 + 0xfffffffffffffff7, + }, + { + in_addr: "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", + /*ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff*/ + + exp_sz: 16, + exp_start_ip: math.MaxInt64, + exp_start_sfx: math.MaxInt64, + exp_end_ip: math.MaxInt64, + exp_end_sfx: math.MaxInt64, + }, + { + in_addr: "::", + /*::*/ + + exp_sz: 16, + exp_start_ip: -math.MaxInt64, + exp_start_sfx: -math.MaxInt64, + exp_end_ip: -math.MaxInt64, + exp_end_sfx: -math.MaxInt64, + }, + { + in_addr: "2001:db8::", + /*2001:db8:: -> 2001:db8::*/ + exp_sz: 16, + exp_start_ip: -math.MaxInt64 + 0x20010DB800000000, + exp_start_sfx: -math.MaxInt64, + exp_end_ip: -math.MaxInt64 + 0x20010DB800000000, + exp_end_sfx: -math.MaxInt64, + }, + { + in_addr: "2001:db8:0000:0000:0000:0000:0000:00ff", + /*2001:db8:0000:0000:0000:0000:0000:00ff*/ + exp_sz: 16, + exp_start_ip: -math.MaxInt64 + 0x20010DB800000000, + exp_start_sfx: -math.MaxInt64 + 0xFF, + exp_end_ip: -math.MaxInt64 + 0x20010DB800000000, + exp_end_sfx: -math.MaxInt64 + 0xFF, + }, + { + in_addr: "1.2.3.4", + /*1.2.3.4*/ + exp_sz: 4, + exp_start_ip: -math.MaxInt64 + 0x01020304, + exp_start_sfx: 0, + exp_end_ip: -math.MaxInt64 + 0x01020304, + exp_end_sfx: 0, + }, + { + in_addr: "::/0", + /*:: -> ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff*/ + + exp_sz: 16, + exp_start_ip: -math.MaxInt64, + exp_start_sfx: -math.MaxInt64, + exp_end_ip: math.MaxInt64, + exp_end_sfx: math.MaxInt64, + }, + { + in_addr: "::/64", + /*:: -> 0000:0000:0000:0000:ffff:ffff:ffff:ffff*/ + exp_sz: 16, + exp_start_ip: -math.MaxInt64, + exp_start_sfx: -math.MaxInt64, + exp_end_ip: -math.MaxInt64, + exp_end_sfx: math.MaxInt64, + }, + { + in_addr: "2001:db8::/109", + /*2001:db8:: -> 2001:db8:0000:0000:0000:0000:0007:ffff*/ + exp_sz: 16, + exp_start_ip: -math.MaxInt64 + 0x20010DB800000000, + exp_start_sfx: -math.MaxInt64, + exp_end_ip: -math.MaxInt64 + 0x20010DB800000000, + exp_end_sfx: -math.MaxInt64 + 0x7FFFF, + }, + { + in_addr: "0.0.0.0/0", + /*0.0.0.0 -> 255.255.255.255*/ + exp_sz: 4, + exp_start_ip: -math.MaxInt64, + exp_start_sfx: 0, + exp_end_ip: -math.MaxInt64 + 0xFFFFFFFF, + exp_end_sfx: 0, + }, + { + in_addr: "0.0.0.0/16", + /*0.0.0.0 -> 0.0.255.255*/ + exp_sz: 4, + exp_start_ip: -math.MaxInt64, + exp_start_sfx: 0, + exp_end_ip: -math.MaxInt64 + 0x0000FFFF, + exp_end_sfx: 0, + }, + { + in_addr: "255.255.0.0/16", + /*255.255.0.0 -> 255.255.255.255*/ + exp_sz: 4, + exp_start_ip: -math.MaxInt64 + 0xFFFF0000, + exp_start_sfx: 0, + exp_end_ip: -math.MaxInt64 + 0xFFFFFFFF, + exp_end_sfx: 0, + }, + { + in_addr: "1.2.3.0/24", + /*1.2.3.0 -> 1.2.3.255*/ + exp_sz: 4, + exp_start_ip: -math.MaxInt64 + 0x01020300, + exp_start_sfx: 0, + exp_end_ip: -math.MaxInt64 + 0x010203FF, + exp_end_sfx: 0, + }, + /*errors*/ + { + in_addr: "xxx/24", + exp_error: "invalid CIDR address", + }, + { + in_addr: "xxx2", + exp_error: "invalid address", + }, + } + + for idx, test := range tests { + sz, start_ip, start_sfx, end_ip, end_sfx, err := Addr2Ints(test.in_addr) + if err != nil && test.exp_error == "" { + t.Fatalf("%d unexpected error : %s", idx, err) + } + if test.exp_error != "" { + if !strings.Contains(err.Error(), test.exp_error) { + t.Fatalf("%d unmatched error : %s != %s", idx, err, test.exp_error) + } + continue //we can skip this one + } + if sz != test.exp_sz { + t.Fatalf("%d unexpected size %d != %d", idx, sz, test.exp_sz) + } + if start_ip != test.exp_start_ip { + t.Fatalf("%d unexpected start_ip %d != %d", idx, start_ip, test.exp_start_ip) + } + if sz == 16 { + if start_sfx != test.exp_start_sfx { + t.Fatalf("%d unexpected start sfx %d != %d", idx, start_sfx, test.exp_start_sfx) + } + } + if end_ip != test.exp_end_ip { + t.Fatalf("%d unexpected end ip %d != %d", idx, end_ip, test.exp_end_ip) + } + if sz == 16 { + if end_sfx != test.exp_end_sfx { + t.Fatalf("%d unexpected end sfx %d != %d", idx, end_sfx, test.exp_end_sfx) + } + } + + } +} diff --git a/pkg/types/utils.go b/pkg/types/utils.go index a0624f7d9..c394ffff8 100644 --- a/pkg/types/utils.go +++ b/pkg/types/utils.go @@ -2,7 +2,6 @@ package types import ( "bytes" - "encoding/binary" "encoding/gob" "fmt" "io" @@ -21,42 +20,6 @@ import ( "gopkg.in/natefinch/lumberjack.v2" ) -func IP2Int(ip net.IP) uint32 { - if len(ip) == 16 { - return binary.BigEndian.Uint32(ip[12:16]) - } - return binary.BigEndian.Uint32(ip) -} - -func Int2ip(nn uint32) net.IP { - ip := make(net.IP, 4) - binary.BigEndian.PutUint32(ip, nn) - return ip -} - -//Stolen from : https://github.com/llimllib/ipaddress/ -// Return the final address of a net range. Convert to IPv4 if possible, -// otherwise return an ipv6 -func LastAddress(n *net.IPNet) net.IP { - ip := n.IP.To4() - if ip == nil { - ip = n.IP - return net.IP{ - ip[0] | ^n.Mask[0], ip[1] | ^n.Mask[1], ip[2] | ^n.Mask[2], - ip[3] | ^n.Mask[3], ip[4] | ^n.Mask[4], ip[5] | ^n.Mask[5], - ip[6] | ^n.Mask[6], ip[7] | ^n.Mask[7], ip[8] | ^n.Mask[8], - ip[9] | ^n.Mask[9], ip[10] | ^n.Mask[10], ip[11] | ^n.Mask[11], - ip[12] | ^n.Mask[12], ip[13] | ^n.Mask[13], ip[14] | ^n.Mask[14], - ip[15] | ^n.Mask[15]} - } - - return net.IPv4( - ip[0]|^n.Mask[0], - ip[1]|^n.Mask[1], - ip[2]|^n.Mask[2], - ip[3]|^n.Mask[3]) -} - var logFormatter log.Formatter var LogOutput *lumberjack.Logger //io.Writer var logLevel log.Level diff --git a/scripts/test_ip_management.sh b/scripts/test_ip_management.sh new file mode 100755 index 000000000..e18d733a0 --- /dev/null +++ b/scripts/test_ip_management.sh @@ -0,0 +1,434 @@ +#! /usr/bin/env bash +# -*- coding: utf-8 -*- + + +# Codes +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' +OK_STR="${GREEN}OK${NC}" +FAIL_STR="${RED}FAIL${NC}" + +CSCLI_BIN="./cscli" +CSCLI="${CSCLI_BIN} -c dev.yaml" +JQ="jq -e" +CROWDSEC_API_URL="http://localhost:8081" +CROWDSEC_VERSION="" +API_KEY="" + +RELEASE_FOLDER_FULL="" +FAILED="false" +MUST_FAIL="false" + + +get_latest_release() { + CROWDSEC_VERSION=$(curl --silent "https://api.github.com/repos/crowdsecurity/crowdsec/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') +} + +### Helpers +function docurl +{ + URI=$1 + curl -s -H "X-Api-Key: ${API_KEY}" "${CROWDSEC_API_URL}${URI}" +} + +function bouncer_echo { + if [[ ${FAILED} == "false" ]]; + then + echo -e "[bouncer] $1: ${OK_STR}" + else + echo -e "[bouncer] $1: ${FAIL_STR}" + fi + FAILED="false" +} + +function cscli_echo { + if [[ ${FAILED} == "false" ]]; + then + echo -e "[cscli] $1: ${OK_STR}" + else + echo -e "[cscli] $1: ${FAIL_STR}" + fi + FAILED="false" +} + +function fail { + FAILED="true" + MUST_FAIL="true" +} + +## End helpersĀ ## + + +function init +{ + if [[ ! -d ${RELEASE_FOLDER} ]]; + then + cd .. + get_latest_release + BUILD_VERSION=${CROWDSEC_VERSION} make release + if [ $? != 0 ]; then + echo "Unable to make the release (make sur you have go installed), exiting" + exit 1 + fi + RELEASE_FOLDER="crowdsec-${CROWDSEC_VERSION}" + fi + RELEASE_FOLDER_FULL="$(readlink -f ${RELEASE_FOLDER})" + TEST_ENV_FOLDER="${RELEASE_FOLDER_FULL}/tests/" + cd ${RELEASE_FOLDER}/ + if [[ ! -d "${TEST_ENV_FOLDER}" ]]; + then + echo "Installing crowdsec test environment" + ./test_env.sh + fi + reset +} + + +function test_ipv4_ip +{ + echo "" + echo "##########################################" + echo "$FUNCNAME" + echo "##########################################" + echo "" + + ${CSCLI} decisions list -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "first decisions list" + + docurl /v1/decisions | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "first bouncer decisions request (must be empty)" + + #add ip decision + echo "adding decision for 1.2.3.4" + ${CSCLI} decisions add -i 1.2.3.4 > /dev/null 2>&1 || fail + + ${CSCLI} decisions list -o json | ${JQ} '.[].decisions[0].value == "1.2.3.4"' > /dev/null || fail + cscli_echo "getting all decision" + + docurl /v1/decisions | ${JQ} '.[0].value == "1.2.3.4"' > /dev/null || fail + bouncer_echo "getting all decision" + + #check ip match + ${CSCLI} decisions list -i 1.2.3.4 -o json | ${JQ} '.[].decisions[0].value == "1.2.3.4"' > /dev/null || fail + cscli_echo "getting decision for 1.2.3.4" + + docurl /v1/decisions?ip=1.2.3.4 | ${JQ} '.[0].value == "1.2.3.4"' > /dev/null || fail + bouncer_echo "getting decision for 1.2.3.4" + + ${CSCLI} decisions list -i 1.2.3.5 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decision for 1.2.3.5" + + docurl /v1/decisions?ip=1.2.3.5 | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decision for 1.2.3.5" + + #check outer range match + ${CSCLI} decisions list -r 1.2.3.0/24 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decision for 1.2.3.0/24" + + docurl "/v1/decisions?range=1.2.3.0/24" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decision for 1.2.3.0/24" + + ${CSCLI} decisions list -r 1.2.3.0/24 --contained -o json |${JQ} '.[].decisions[0].value == "1.2.3.4"' > /dev/null || fail + cscli_echo "getting decisions where IP in 1.2.3.0/24" + + docurl "/v1/decisions?range=1.2.3.0/24&contains=false" | ${JQ} '.[0].value == "1.2.3.4"' > /dev/null || fail + bouncer_echo "getting decisions where IP in 1.2.3.0/24" + +} + +function test_ipv4_range +{ + echo "" + echo "##########################################" + echo "$FUNCNAME" + echo "##########################################" + echo "" + + cscli_echo "adding decision for range 4.4.4.0/24" + ${CSCLI} decisions add -r 4.4.4.0/24 > /dev/null 2>&1 || fail + + ${CSCLI} decisions list -o json | ${JQ} '.[0].decisions[0].value == "4.4.4.0/24", .[1].decisions[0].value == "1.2.3.4"'> /dev/null || fail + cscli_echo "getting all decision" + + docurl ${APIK} "/v1/decisions" | ${JQ} '.[0].value == "1.2.3.4", .[1].value == "4.4.4.0/24"'> /dev/null || fail + bouncer_echo "getting all decision" + + #check ip within/outside of range + ${CSCLI} decisions list -i 4.4.4.3 -o json | ${JQ} '.[].decisions[0].value == "4.4.4.0/24"' > /dev/null || fail + cscli_echo "getting decisions for ip 4.4.4." + + docurl ${APIK} "/v1/decisions?ip=4.4.4.3" | ${JQ} '.[0].value == "4.4.4.0/24"' > /dev/null || fail + bouncer_echo "getting decisions for ip 4.4.4." + + ${CSCLI} decisions list -i 4.4.4.4 -o json --contained | ${JQ} '. == null'> /dev/null || fail + cscli_echo "getting decisions for ip contained in 4.4.4." + + docurl ${APIK} "/v1/decisions?ip=4.4.4.4&contains=false" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for ip contained in 4.4.4." + + ${CSCLI} decisions list -i 5.4.4.3 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for ip 5.4.4." + + docurl ${APIK} "/v1/decisions?ip=5.4.4.3" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for ip 5.4.4." + + ${CSCLI} decisions list -r 4.4.0.0/16 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for range 4.4.0.0/1" + + docurl ${APIK} "/v1/decisions?range=4.4.0.0/16" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for range 4.4.0.0/1" + + ${CSCLI} decisions list -r 4.4.0.0/16 -o json --contained | ${JQ} '.[].decisions[0].value == "4.4.4.0/24"' > /dev/null || fail + cscli_echo "getting decisions for ip/range in 4.4.0.0/1" + + docurl ${APIK} "/v1/decisions?range=4.4.0.0/16&contains=false" | ${JQ} '.[0].value == "4.4.4.0/24"' > /dev/null || fail + bouncer_echo "getting decisions for ip/range in 4.4.0.0/1" + + #check subrange + ${CSCLI} decisions list -r 4.4.4.2/28 -o json | ${JQ} '.[].decisions[0].value == "4.4.4.0/24"' > /dev/null || fail + cscli_echo "getting decisions for range 4.4.4.2/2" + + docurl ${APIK} "/v1/decisions?range=4.4.4.2/28" | ${JQ} '.[].value == "4.4.4.0/24"' > /dev/null || fail + bouncer_echo "getting decisions for range 4.4.4.2/2" + + ${CSCLI} decisions list -r 4.4.3.2/28 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for range 4.4.3.2/2" + + docurl ${APIK} "/v1/decisions?range=4.4.3.2/28" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for range 4.4.3.2/2" + +} + +function test_ipv6_ip +{ + + echo "" + echo "##########################################" + echo "$FUNCNAME" + echo "##########################################" + echo "" + + cscli_echo "adding decision for ip 1111:2222:3333:4444:5555:6666:7777:8888" + ${CSCLI} decisions add -i 1111:2222:3333:4444:5555:6666:7777:8888 > /dev/null 2>&1 + + ${CSCLI} decisions list -o json | ${JQ} '.[].decisions[0].value == "1111:2222:3333:4444:5555:6666:7777:8888"' > /dev/null || fail + cscli_echo "getting all decision" + + docurl ${APIK} "/v1/decisions" | ${JQ} '.[].value == "1111:2222:3333:4444:5555:6666:7777:8888"' > /dev/null || fail + bouncer_echo "getting all decision" + + ${CSCLI} decisions list -i 1111:2222:3333:4444:5555:6666:7777:8888 -o json | ${JQ} '.[].decisions[0].value == "1111:2222:3333:4444:5555:6666:7777:8888"' > /dev/null || fail + cscli_echo "getting decisions for ip 1111:2222:3333:4444:5555:6666:7777:8888" + + docurl ${APIK} "/v1/decisions?ip=1111:2222:3333:4444:5555:6666:7777:8888" | ${JQ} '.[].value == "1111:2222:3333:4444:5555:6666:7777:8888"' > /dev/null || fail + bouncer_echo "getting decisions for ip 1111:2222:3333:4444:5555:6666:7777:888" + + ${CSCLI} decisions list -i 1211:2222:3333:4444:5555:6666:7777:8888 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for ip 1211:2222:3333:4444:5555:6666:7777:8888" + + docurl ${APIK} "/v1/decisions?ip=1211:2222:3333:4444:5555:6666:7777:8888" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for ip 1211:2222:3333:4444:5555:6666:7777:888" + + ${CSCLI} decisions list -i 1111:2222:3333:4444:5555:6666:7777:8887 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for ip 1111:2222:3333:4444:5555:6666:7777:8887" + + docurl ${APIK} "/v1/decisions?ip=1111:2222:3333:4444:5555:6666:7777:8887" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for ip 1111:2222:3333:4444:5555:6666:7777:888" + + ${CSCLI} decisions list -r 1111:2222:3333:4444:5555:6666:7777:8888/48 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for range 1111:2222:3333:4444:5555:6666:7777:8888/48" + + docurl ${APIK} "/v1/decisions?range=1111:2222:3333:4444:5555:6666:7777:8888/48" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for range 1111:2222:3333:4444:5555:6666:7777:8888/48" + + ${CSCLI} decisions list -r 1111:2222:3333:4444:5555:6666:7777:8888/48 --contained -o json | ${JQ} '.[].decisions[0].value == "1111:2222:3333:4444:5555:6666:7777:8888"' > /dev/null || fail + cscli_echo "getting decisions for ip/range in range 1111:2222:3333:4444:5555:6666:7777:8888/48" + + docurl ${APIK} "/v1/decisions?range=1111:2222:3333:4444:5555:6666:7777:8888/48&&contains=false" | ${JQ} '.[].value == "1111:2222:3333:4444:5555:6666:7777:8888"' > /dev/null || fail + bouncer_echo "getting decisions for ip/range in 1111:2222:3333:4444:5555:6666:7777:8888/48" + + ${CSCLI} decisions list -r 1111:2222:3333:4444:5555:6666:7777:8888/64 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for range 1111:2222:3333:4444:5555:6666:7777:8888/64" + + docurl ${APIK} "/v1/decisions?range=1111:2222:3333:4444:5555:6666:7777:8888/64" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for range 1111:2222:3333:4444:5555:6666:7777:8888/64" + + ${CSCLI} decisions list -r 1111:2222:3333:4444:5555:6666:7777:8888/64 -o json --contained | ${JQ} '.[].decisions[0].value == "1111:2222:3333:4444:5555:6666:7777:8888"' > /dev/null || fail + cscli_echo "getting decisions for ip/range in 1111:2222:3333:4444:5555:6666:7777:8888/64" + + docurl ${APIK} "/v1/decisions?range=1111:2222:3333:4444:5555:6666:7777:8888/64&&contains=false" | ${JQ} '.[].value == "1111:2222:3333:4444:5555:6666:7777:8888"' > /dev/null || fail + bouncer_echo "getting decisions for ip/range in 1111:2222:3333:4444:5555:6666:7777:8888/64" + +} + +function test_ipv6_range +{ + echo "" + echo "##########################################" + echo "$FUNCNAME" + echo "##########################################" + echo "" + + cscli_echo "adding decision for range aaaa:2222:3333:4444::/64" + ${CSCLI} decisions add -r aaaa:2222:3333:4444::/64 > /dev/null 2>&1 || fail + + ${CSCLI} decisions list -o json | ${JQ} '.[0].decisions[0].value == "aaaa:2222:3333:4444::/64", .[1].decisions[0].value == "1111:2222:3333:4444:5555:6666:7777:8888"' > /dev/null || fail + cscli_echo "getting all decision" + + docurl ${APIK} "/v1/decisions" | ${JQ} '.[0].value == "1111:2222:3333:4444:5555:6666:7777:8888", .[1].value == "aaaa:2222:3333:4444::/64"' > /dev/null || fail + bouncer_echo "getting all decision" + + #check ip within/out of range + ${CSCLI} decisions list -i aaaa:2222:3333:4444:5555:6666:7777:8888 -o json | ${JQ} '.[].decisions[0].value == "aaaa:2222:3333:4444::/64"' > /dev/null || fail + cscli_echo "getting decisions for ip aaaa:2222:3333:4444:5555:6666:7777:8888" + + docurl ${APIK} "/v1/decisions?ip=aaaa:2222:3333:4444:5555:6666:7777:8888" | ${JQ} '.[].value == "aaaa:2222:3333:4444::/64"' > /dev/null || fail + bouncer_echo "getting decisions for ip aaaa:2222:3333:4444:5555:6666:7777:8888" + + ${CSCLI} decisions list -i aaaa:2222:3333:4445:5555:6666:7777:8888 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for ip aaaa:2222:3333:4445:5555:6666:7777:8888" + + docurl ${APIK} "/v1/decisions?ip=aaaa:2222:3333:4445:5555:6666:7777:8888" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for ip aaaa:2222:3333:4445:5555:6666:7777:8888" + + ${CSCLI} decisions list -i aaa1:2222:3333:4444:5555:6666:7777:8887 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for ip aaa1:2222:3333:4444:5555:6666:7777:8887" + + docurl ${APIK} "/v1/decisions?ip=aaa1:2222:3333:4444:5555:6666:7777:8887" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for ip aaa1:2222:3333:4444:5555:6666:7777:8887" + + #check subrange within/out of range + ${CSCLI} decisions list -r aaaa:2222:3333:4444:5555::/80 -o json | ${JQ} '.[].decisions[0].value == "aaaa:2222:3333:4444::/64"' > /dev/null || fail + cscli_echo "getting decisions for range aaaa:2222:3333:4444:5555::/80" + + docurl ${APIK} "/v1/decisions?range=aaaa:2222:3333:4444:5555::/80" | ${JQ} '.[].value == "aaaa:2222:3333:4444::/64"' > /dev/null || fail + bouncer_echo "getting decisions for range aaaa:2222:3333:4444:5555::/80" + + ${CSCLI} decisions list -r aaaa:2222:3333:4441:5555::/80 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for range aaaa:2222:3333:4441:5555::/80" + + docurl ${APIK} "/v1/decisions?range=aaaa:2222:3333:4441:5555::/80" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for range aaaa:2222:3333:4441:5555::/80" + + ${CSCLI} decisions list -r aaa1:2222:3333:4444:5555::/80 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for range aaa1:2222:3333:4444:5555::/80" + + docurl ${APIK} "/v1/decisions?range=aaa1:2222:3333:4444:5555::/80" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for range aaa1:2222:3333:4444:5555::/80" + + #check outer range + ${CSCLI} decisions list -r aaaa:2222:3333:4444:5555:6666:7777:8888/48 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for range aaaa:2222:3333:4444:5555:6666:7777:8888/48" + + docurl ${APIK} "/v1/decisions?range=aaaa:2222:3333:4444:5555:6666:7777:8888/48" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for range aaaa:2222:3333:4444:5555:6666:7777:8888/48" + + ${CSCLI} decisions list -r aaaa:2222:3333:4444:5555:6666:7777:8888/48 -o json --contained | ${JQ} '.[].decisions[0].value == "aaaa:2222:3333:4444::/64"' > /dev/null || fail + cscli_echo "getting decisions for ip/range in aaaa:2222:3333:4444:5555:6666:7777:8888/48" + + docurl ${APIK} "/v1/decisions?range=aaaa:2222:3333:4444:5555:6666:7777:8888/48&contains=false" | ${JQ} '.[].value == "aaaa:2222:3333:4444::/64"' > /dev/null || fail + bouncer_echo "getting decisions for ip/range in aaaa:2222:3333:4444:5555:6666:7777:8888/48" + + ${CSCLI} decisions list -r aaaa:2222:3333:4445:5555:6666:7777:8888/48 -o json | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for ip/range aaaa:2222:3333:4445:5555:6666:7777:8888/48" + + docurl ${APIK} "/v1/decisions?range=aaaa:2222:3333:4445:5555:6666:7777:8888/48" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for ip/range in aaaa:2222:3333:4445:5555:6666:7777:8888/48" + + #bbbb:db8:: -> bbbb:db8:0000:0000:0000:7fff:ffff:ffff + ${CSCLI} decisions add -r bbbb:db8::/81 > /dev/null 2>&1 + cscli_echo "adding decision for range bbbb:db8::/81" > /dev/null || fail + + ${CSCLI} decisions list -o json -i bbbb:db8:0000:0000:0000:6fff:ffff:ffff | ${JQ} '.[].decisions[0].value == "bbbb:db8::/81"' > /dev/null || fail + cscli_echo "getting decisions for ip bbbb:db8:0000:0000:0000:6fff:ffff:ffff" + + docurl ${APIK} "/v1/decisions?ip=bbbb:db8:0000:0000:0000:6fff:ffff:ffff" | ${JQ} '.[].value == "bbbb:db8::/81"' > /dev/null || fail + bouncer_echo "getting decisions for ip in bbbb:db8:0000:0000:0000:6fff:ffff:ffff" + + ${CSCLI} decisions list -o json -i bbbb:db8:0000:0000:0000:8fff:ffff:ffff | ${JQ} '. == null' > /dev/null || fail + cscli_echo "getting decisions for ip bbbb:db8:0000:0000:0000:8fff:ffff:ffff" + + docurl ${APIK} "/v1/decisions?ip=bbbb:db8:0000:0000:0000:8fff:ffff:ffff" | ${JQ} '. == null' > /dev/null || fail + bouncer_echo "getting decisions for ip in bbbb:db8:0000:0000:0000:8fff:ffff:ffff" + +} + + +function start_test +{ + + ## ipv4 testing + test_ipv4_ip + test_ipv4_range + + reset + + ## ipv6 testing + test_ipv6_ip + test_ipv6_range +} + +function reset +{ + cd ${RELEASE_FOLDER_FULL}/tests/ + rm data/crowdsec.db > /dev/null 2>&1 || echo "" + killall crowdsec > /dev/null 2>&1 || echo "" + ${CSCLI} hub update + ${CSCLI} machines add -a + API_KEY=`${CSCLI} bouncers add TestingBouncer -o=raw` + ./crowdsec -c dev.yaml> crowdsec-out.log 2>&1 & + sleep 2 +} + +function down +{ + cd ${RELEASE_FOLDER_FULL}/tests/ + rm data/crowdsec.db + killall crowdsec + #rm -rf tests/ +} + + +usage() { + echo "Usage:" + echo "" + echo " ./ip_mgmt_tests.sh -h Display this help message." + echo " ./ip_mgmt_tests.sh Run all the testsuite. Go must be available to make the release" + echo " ./ip_mgmt_tests.sh --release If go is not installed, please provide a path to the crowdsec-vX.Y.Z release folder" + echo "" + exit 0 +} + +while [[ $# -gt 0 ]] +do + key="${1}" + case ${key} in + --release|-r) + RELEASE_FOLDER="${2}" + shift #past argument + shift + ;; + -h|--help) + usage + exit 0 + ;; + *) # unknown option + echo "Unknown argument ${key}." + usage + exit 1 + ;; + esac +done + + +init +start_test +down + +if [[ ${MUST_FAIL} == "true" ]]; +then + echo "" + echo "One or more tests have failed !" + exit 1 +fi \ No newline at end of file diff --git a/scripts/test_wizard_upgrade.sh b/scripts/test_wizard_upgrade.sh index 259907653..4736cd55d 100755 --- a/scripts/test_wizard_upgrade.sh +++ b/scripts/test_wizard_upgrade.sh @@ -69,7 +69,7 @@ function init wget https://github.com/crowdsecurity/cs-firewall-bouncer/releases/download/${BOUNCER_VERSION}/cs-firewall-bouncer.tgz tar xzvf cs-firewall-bouncer.tgz cd cs-firewall-bouncer-${BOUNCER_VERSION}/ - echo "iptables" | sudo ./install.sh + (echo "iptables" | sudo ./install.sh) || (echo "Unable to install cs-firewall-bouncer" && exit 1) cd ${CURRENT_FOLDER} echo "[*] Tainting parser /etc/crowdsec/parsers/s01-parse/sshd-logs.yaml"