From 030139685e9ecce6e61a099e6a75f17a01c91e4d Mon Sep 17 00:00:00 2001 From: Shivansh Vij Date: Fri, 7 Jul 2023 17:35:00 -0700 Subject: [PATCH] Completely removing dependencies on database from Auth (#12) Signed-off-by: Shivansh Vij --- go.mod | 14 +- go.sum | 38 +- internal/api/v1/device/device.go | 7 +- internal/api/v1/github/github.go | 5 +- internal/api/v1/google/google.go | 5 +- internal/api/v1/magic/magic.go | 6 +- internal/api/v1/options/options.go | 8 +- internal/controller/controller.go | 26 +- internal/database/database.go | 75 - internal/database/device.go | 77 - internal/database/github.go | 49 - internal/database/google.go | 49 - internal/database/magic.go | 51 - internal/ent/client.go | 716 ---- internal/ent/deviceflow.go | 188 -- internal/ent/deviceflow/deviceflow.go | 126 - internal/ent/deviceflow/where.go | 538 ---- internal/ent/deviceflow_create.go | 329 -- internal/ent/deviceflow_delete.go | 104 - internal/ent/deviceflow_query.go | 542 ---- internal/ent/deviceflow_update.go | 330 -- internal/ent/ent.go | 630 ---- internal/ent/enttest/enttest.go | 100 - internal/ent/generate.go | 19 - internal/ent/githubflow.go | 188 -- internal/ent/githubflow/githubflow.go | 126 - internal/ent/githubflow/where.go | 588 ---- internal/ent/githubflow_create.go | 322 -- internal/ent/githubflow_delete.go | 104 - internal/ent/githubflow_query.go | 542 ---- internal/ent/githubflow_update.go | 203 -- internal/ent/googleflow.go | 188 -- internal/ent/googleflow/googleflow.go | 126 - internal/ent/googleflow/where.go | 588 ---- internal/ent/googleflow_create.go | 322 -- internal/ent/googleflow_delete.go | 104 - internal/ent/googleflow_query.go | 542 ---- internal/ent/googleflow_update.go | 203 -- internal/ent/hook/hook.go | 251 -- internal/ent/magicflow.go | 199 -- internal/ent/magicflow/magicflow.go | 136 - internal/ent/magicflow/where.go | 658 ---- internal/ent/magicflow_create.go | 340 -- internal/ent/magicflow_delete.go | 104 - internal/ent/magicflow_query.go | 542 ---- internal/ent/magicflow_update.go | 203 -- internal/ent/migrate/migrate.go | 80 - internal/ent/migrate/schema.go | 106 - internal/ent/mutation.go | 2868 ----------------- internal/ent/predicate/predicate.go | 35 - internal/ent/runtime.go | 127 - internal/ent/runtime/runtime.go | 26 - internal/ent/schema/deviceFlow.go | 46 - internal/ent/schema/githubFlow.go | 46 - internal/ent/schema/googleFlow.go | 46 - internal/ent/schema/magicFlow.go | 47 - internal/ent/tx.go | 235 -- internal/provider/device/database.go | 33 - internal/provider/github/database.go | 30 - internal/provider/google/database.go | 30 - pkg/config/config.go | 7 - .../provider => pkg/flow}/device/device.go | 77 +- .../magic/database.go => pkg/flow/flow.go | 31 +- .../provider => pkg/flow}/github/github.go | 106 +- .../provider => pkg/flow}/google/google.go | 106 +- .../provider => pkg/flow}/magic/magic.go | 74 +- {internal => pkg}/magic/magic.go | 0 pkg/manager/manager.go | 55 +- pkg/provider/provider.go | 35 - pkg/session/session.go | 26 +- pkg/session/session_test.go | 4 +- pkg/storage/flow.go | 102 + pkg/storage/storage.go | 23 +- 73 files changed, 418 insertions(+), 14594 deletions(-) delete mode 100644 internal/database/database.go delete mode 100644 internal/database/device.go delete mode 100644 internal/database/github.go delete mode 100644 internal/database/google.go delete mode 100644 internal/database/magic.go delete mode 100644 internal/ent/client.go delete mode 100644 internal/ent/deviceflow.go delete mode 100644 internal/ent/deviceflow/deviceflow.go delete mode 100644 internal/ent/deviceflow/where.go delete mode 100644 internal/ent/deviceflow_create.go delete mode 100644 internal/ent/deviceflow_delete.go delete mode 100644 internal/ent/deviceflow_query.go delete mode 100644 internal/ent/deviceflow_update.go delete mode 100644 internal/ent/ent.go delete mode 100644 internal/ent/enttest/enttest.go delete mode 100644 internal/ent/generate.go delete mode 100644 internal/ent/githubflow.go delete mode 100644 internal/ent/githubflow/githubflow.go delete mode 100644 internal/ent/githubflow/where.go delete mode 100644 internal/ent/githubflow_create.go delete mode 100644 internal/ent/githubflow_delete.go delete mode 100644 internal/ent/githubflow_query.go delete mode 100644 internal/ent/githubflow_update.go delete mode 100644 internal/ent/googleflow.go delete mode 100644 internal/ent/googleflow/googleflow.go delete mode 100644 internal/ent/googleflow/where.go delete mode 100644 internal/ent/googleflow_create.go delete mode 100644 internal/ent/googleflow_delete.go delete mode 100644 internal/ent/googleflow_query.go delete mode 100644 internal/ent/googleflow_update.go delete mode 100644 internal/ent/hook/hook.go delete mode 100644 internal/ent/magicflow.go delete mode 100644 internal/ent/magicflow/magicflow.go delete mode 100644 internal/ent/magicflow/where.go delete mode 100644 internal/ent/magicflow_create.go delete mode 100644 internal/ent/magicflow_delete.go delete mode 100644 internal/ent/magicflow_query.go delete mode 100644 internal/ent/magicflow_update.go delete mode 100644 internal/ent/migrate/migrate.go delete mode 100644 internal/ent/migrate/schema.go delete mode 100644 internal/ent/mutation.go delete mode 100644 internal/ent/predicate/predicate.go delete mode 100644 internal/ent/runtime.go delete mode 100644 internal/ent/runtime/runtime.go delete mode 100644 internal/ent/schema/deviceFlow.go delete mode 100644 internal/ent/schema/githubFlow.go delete mode 100644 internal/ent/schema/googleFlow.go delete mode 100644 internal/ent/schema/magicFlow.go delete mode 100644 internal/ent/tx.go delete mode 100644 internal/provider/device/database.go delete mode 100644 internal/provider/github/database.go delete mode 100644 internal/provider/google/database.go rename {internal/provider => pkg/flow}/device/device.go (52%) rename internal/provider/magic/database.go => pkg/flow/flow.go (53%) rename {internal/provider => pkg/flow}/github/github.go (62%) rename {internal/provider => pkg/flow}/google/google.go (59%) rename {internal/provider => pkg/flow}/magic/magic.go (70%) rename {internal => pkg}/magic/magic.go (100%) delete mode 100644 pkg/provider/provider.go create mode 100644 pkg/storage/flow.go diff --git a/go.mod b/go.mod index 96b6a5d..28a9860 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/loopholelabs/auth go 1.20 require ( - entgo.io/ent v0.12.3 github.com/AfterShip/email-verifier v1.3.3 github.com/go-openapi/errors v0.20.4 github.com/go-openapi/runtime v0.26.0 @@ -13,7 +12,6 @@ require ( github.com/gofiber/fiber/v2 v2.47.0 github.com/google/uuid v1.3.0 github.com/grokify/go-pkce v0.2.3 - github.com/jackc/pgx/v5 v5.4.1 github.com/mattevans/postmark-go v0.1.6 github.com/rs/zerolog v1.29.1 github.com/spf13/cobra v1.7.0 @@ -26,36 +24,28 @@ require ( ) require ( - ariga.io/atlas v0.10.2-0.20230427182402-87a07dfb83bf // indirect cloud.google.com/go/compute/metadata v0.2.0 // indirect github.com/KyleBanks/depth v1.2.1 // indirect - github.com/agext/levenshtein v1.2.1 // indirect github.com/andybalholm/brotli v1.0.5 // indirect - github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/analysis v0.21.4 // indirect - github.com/go-openapi/inflect v0.19.0 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.20.0 // indirect github.com/go-openapi/loads v0.21.2 // indirect github.com/go-openapi/spec v0.20.8 // indirect github.com/golang/protobuf v1.5.2 // indirect - github.com/google/go-cmp v0.5.9 // indirect - github.com/hashicorp/hcl/v2 v2.13.0 // indirect github.com/hbollon/go-edlib v1.6.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/josharian/intern v1.0.0 // indirect github.com/klauspost/compress v1.16.3 // indirect + github.com/kr/pretty v0.3.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect - github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/oklog/ulid v1.3.1 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect @@ -69,11 +59,9 @@ require ( github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.47.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect - github.com/zclconf/go-cty v1.8.0 // indirect go.mongodb.org/mongo-driver v1.11.3 // indirect go.opentelemetry.io/otel v1.14.0 // indirect go.opentelemetry.io/otel/trace v1.14.0 // indirect - golang.org/x/mod v0.10.0 // indirect golang.org/x/sys v0.10.0 // indirect golang.org/x/text v0.11.0 // indirect golang.org/x/tools v0.8.1-0.20230428195545-5283a0178901 // indirect diff --git a/go.sum b/go.sum index 47e6c28..12ca131 100644 --- a/go.sum +++ b/go.sum @@ -1,23 +1,14 @@ -ariga.io/atlas v0.10.2-0.20230427182402-87a07dfb83bf h1:Tq2DRB39ZHScIwWACjPKLv5oEErv7zv6PBb5RTz5CKA= -ariga.io/atlas v0.10.2-0.20230427182402-87a07dfb83bf/go.mod h1:+TR129FJZ5Lvzms6dvCeGWh1yR6hMvmXBhug4hrNIGk= cloud.google.com/go/compute/metadata v0.2.0 h1:nBbNSZyDpkNlo3DepaaLKVuO7ClyifSAmNloSCZrHnQ= cloud.google.com/go/compute/metadata v0.2.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= -entgo.io/ent v0.12.3 h1:N5lO2EOrHpCH5HYfiMOCHYbo+oh5M8GjT0/cx5x6xkk= -entgo.io/ent v0.12.3/go.mod h1:AigGGx+tbrBBYHAzGOg8ND661E5cxx1Uiu5o/otJ6Yg= github.com/AfterShip/email-verifier v1.3.3 h1:1IQ9ye+veU7+QmDLISbZQ0wf1BiiS873YGVYC/WCkIg= github.com/AfterShip/email-verifier v1.3.3/go.mod h1:duPLT6e3xTLLEKYuQOXMAQPLdDsaEuUp5x5H/mb+aHc= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= -github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= -github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= -github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= @@ -40,8 +31,6 @@ github.com/go-openapi/errors v0.19.9/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpX github.com/go-openapi/errors v0.20.2/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= github.com/go-openapi/errors v0.20.4 h1:unTcVm6PispJsMECE3zWgvG4xTiKda1LIR5rCRWLG6M= github.com/go-openapi/errors v0.20.4/go.mod h1:Z3FlZ4I8jEGxjUK+bugx3on2mIAk4txuAOhlsB1FSgk= -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.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -70,7 +59,6 @@ github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+ github.com/go-openapi/validate v0.22.1 h1:G+c2ub6q47kfX1sOBLwIQwzBVt8qmOAARyo/9Fqs9NU= github.com/go-openapi/validate v0.22.1/go.mod h1:rjnrwK57VJ7A8xqfpAOEKRH8yQSGUriMu5/zuPSQ1hg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg= @@ -99,16 +87,13 @@ github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x github.com/gofiber/fiber/v2 v2.47.0 h1:EN5lHVCc+Pyqh5OEsk8fzRiifgwpbrP0rulQ4iNf3fs= github.com/gofiber/fiber/v2 v2.47.0/go.mod h1:mbFMVN1lQuzziTkkakgtKKdjfsXSw9BKR5lmcNksUoU= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -116,19 +101,11 @@ github.com/grokify/go-pkce v0.2.3 h1:L4VmAvavBAcmC4sz084ccmK21qo9y7it4ZEG76DgD0I github.com/grokify/go-pkce v0.2.3/go.mod h1:DABMww8Ue+sVrmOBDrt8dH8iFFUtSfmUCKOS3nh4ye8= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= -github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc= -github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= github.com/hbollon/go-edlib v1.6.0 h1:ga7AwwVIvP8mHm9GsPueC0d71cfRU/52hmPJ7Tprv4E= github.com/hbollon/go-edlib v1.6.0/go.mod h1:wnt6o6EIVEzUfgbUZY7BerzQ2uvzp354qmS2xaLkrhM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= -github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.4.1 h1:oKfB/FhuVtit1bBM3zNRRsZ925ZkMN3HXL+LgLUM9lE= -github.com/jackc/pgx/v5 v5.4.1/go.mod h1:q6iHT8uDNXWiFNOlRqJzBTaSH3+2xCXkokxHZC5qWFY= github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= @@ -143,11 +120,11 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxv github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= @@ -166,9 +143,6 @@ github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APP github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= -github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= -github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -178,7 +152,6 @@ github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uY github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= @@ -195,6 +168,7 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= @@ -206,7 +180,6 @@ github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94/go.mod h1:90zrgN3 github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4= github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk= github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g= -github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= @@ -242,8 +215,6 @@ github.com/valyala/fasthttp v1.47.0 h1:y7moDoxYzMooFpT5aHgNgVOQDrS3qlkfiP9mDtGGK github.com/valyala/fasthttp v1.47.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= -github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= -github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= @@ -252,8 +223,6 @@ github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgk github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/zclconf/go-cty v1.8.0 h1:s4AvqaeQzJIu3ndv4gVIhplVD0krU+bgrcLSVUnaWuA= -github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= go.mongodb.org/mongo-driver v1.7.3/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R79oO62zWg= go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4xhp5Zvxng= go.mongodb.org/mongo-driver v1.10.0/go.mod h1:wsihk0Kdgv8Kqu1Anit4sfK+22vSFbUrAVEYRhCXrA8= @@ -278,12 +247,10 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= -golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= @@ -354,7 +321,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= diff --git a/internal/api/v1/device/device.go b/internal/api/v1/device/device.go index 16eff00..e05a8c5 100644 --- a/internal/api/v1/device/device.go +++ b/internal/api/v1/device/device.go @@ -17,11 +17,12 @@ package device import ( + "errors" "github.com/gofiber/fiber/v2" "github.com/loopholelabs/auth/internal/api/v1/models" "github.com/loopholelabs/auth/internal/api/v1/options" - "github.com/loopholelabs/auth/internal/ent" "github.com/loopholelabs/auth/internal/utils" + "github.com/loopholelabs/auth/pkg/storage" "github.com/rs/zerolog" "time" ) @@ -114,7 +115,7 @@ func (d *Device) DeviceCallback(ctx *fiber.Ctx) error { identifier, err := d.options.DeviceProvider().ValidateFlow(ctx.Context(), code) if err != nil { - if ent.IsNotFound(err) { + if errors.Is(err, storage.ErrNotFound) { return ctx.Status(fiber.StatusUnauthorized).SendString("invalid code") } d.logger.Error().Err(err).Msg("failed to validate device code") @@ -153,7 +154,7 @@ func (d *Device) DevicePoll(ctx *fiber.Ctx) error { session, expires, lastPoll, err := d.options.DeviceProvider().PollFlow(ctx.Context(), code) if err != nil { - if ent.IsNotFound(err) { + if errors.Is(err, storage.ErrNotFound) { return ctx.Status(fiber.StatusUnauthorized).SendString("invalid code") } d.logger.Error().Err(err).Msg("failed to poll device code") diff --git a/internal/api/v1/github/github.go b/internal/api/v1/github/github.go index e66c76c..a5ee498 100644 --- a/internal/api/v1/github/github.go +++ b/internal/api/v1/github/github.go @@ -17,11 +17,12 @@ package github import ( + "errors" "github.com/gofiber/fiber/v2" "github.com/loopholelabs/auth/internal/api/v1/options" - "github.com/loopholelabs/auth/internal/ent" "github.com/loopholelabs/auth/internal/utils" "github.com/loopholelabs/auth/pkg/sessionKind" + "github.com/loopholelabs/auth/pkg/storage" "github.com/rs/zerolog" ) @@ -131,7 +132,7 @@ func (a *Github) GithubCallback(ctx *fiber.Ctx) error { a.logger.Debug().Msgf("completing flow for state %s", state) userID, organization, nextURL, deviceIdentifier, err := a.options.GithubProvider().CompleteFlow(ctx.Context(), code, state) if err != nil { - if ent.IsNotFound(err) { + if errors.Is(err, storage.ErrNotFound) { return ctx.Status(fiber.StatusUnauthorized).SendString("code is invalid") } a.logger.Error().Err(err).Msg("failed to get token") diff --git a/internal/api/v1/google/google.go b/internal/api/v1/google/google.go index 7e59a69..2451216 100644 --- a/internal/api/v1/google/google.go +++ b/internal/api/v1/google/google.go @@ -17,11 +17,12 @@ package google import ( + "errors" "github.com/gofiber/fiber/v2" "github.com/loopholelabs/auth/internal/api/v1/options" - "github.com/loopholelabs/auth/internal/ent" "github.com/loopholelabs/auth/internal/utils" "github.com/loopholelabs/auth/pkg/sessionKind" + "github.com/loopholelabs/auth/pkg/storage" "github.com/rs/zerolog" ) @@ -131,7 +132,7 @@ func (a *Google) GoogleCallback(ctx *fiber.Ctx) error { a.logger.Debug().Msgf("completing flow for state %s", state) userID, organization, nextURL, deviceIdentifier, err := a.options.GoogleProvider().CompleteFlow(ctx.Context(), code, state) if err != nil { - if ent.IsNotFound(err) { + if errors.Is(err, storage.ErrNotFound) { return ctx.Status(fiber.StatusUnauthorized).SendString("code is invalid") } a.logger.Error().Err(err).Msg("failed to get token") diff --git a/internal/api/v1/magic/magic.go b/internal/api/v1/magic/magic.go index fba0618..3984a3b 100644 --- a/internal/api/v1/magic/magic.go +++ b/internal/api/v1/magic/magic.go @@ -22,10 +22,10 @@ import ( "github.com/AfterShip/email-verifier" "github.com/gofiber/fiber/v2" "github.com/loopholelabs/auth/internal/api/v1/options" - "github.com/loopholelabs/auth/internal/ent" - "github.com/loopholelabs/auth/internal/provider/magic" "github.com/loopholelabs/auth/internal/utils" + "github.com/loopholelabs/auth/pkg/flow/magic" "github.com/loopholelabs/auth/pkg/sessionKind" + "github.com/loopholelabs/auth/pkg/storage" "github.com/rs/zerolog" ) @@ -171,7 +171,7 @@ func (d *Magic) MagicCallback(ctx *fiber.Ctx) error { d.logger.Debug().Msgf("completing flow for %s", email) organization, nextURL, deviceIdentifier, err := d.options.MagicProvider().CompleteFlow(ctx.Context(), email, secret) if err != nil { - if ent.IsNotFound(err) || errors.Is(err, magic.ErrInvalidSecret) { + if errors.Is(err, storage.ErrNotFound) || errors.Is(err, magic.ErrInvalidSecret) { return ctx.Status(fiber.StatusUnauthorized).SendString("invalid magic link token") } d.logger.Error().Err(err).Msg("failed to complete magic link flow") diff --git a/internal/api/v1/options/options.go b/internal/api/v1/options/options.go index 5f8732e..67faada 100644 --- a/internal/api/v1/options/options.go +++ b/internal/api/v1/options/options.go @@ -18,10 +18,10 @@ package options import ( "github.com/loopholelabs/auth/internal/controller" - "github.com/loopholelabs/auth/internal/provider/device" - "github.com/loopholelabs/auth/internal/provider/github" - "github.com/loopholelabs/auth/internal/provider/google" - "github.com/loopholelabs/auth/internal/provider/magic" + "github.com/loopholelabs/auth/pkg/flow/device" + "github.com/loopholelabs/auth/pkg/flow/github" + "github.com/loopholelabs/auth/pkg/flow/google" + "github.com/loopholelabs/auth/pkg/flow/magic" ) type Github func() *github.Github diff --git a/internal/controller/controller.go b/internal/controller/controller.go index 73c5d30..0c5623d 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -1,17 +1,17 @@ /* - Copyright 2023 Loophole Labs + Copyright 2023 Loophole Labs - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ package controller @@ -25,11 +25,11 @@ import ( "github.com/gofiber/fiber/v2" "github.com/loopholelabs/auth" "github.com/loopholelabs/auth/internal/aes" - "github.com/loopholelabs/auth/internal/magic" "github.com/loopholelabs/auth/internal/utils" "github.com/loopholelabs/auth/pkg/apikey" "github.com/loopholelabs/auth/pkg/claims" - "github.com/loopholelabs/auth/pkg/provider" + "github.com/loopholelabs/auth/pkg/flow" + "github.com/loopholelabs/auth/pkg/magic" "github.com/loopholelabs/auth/pkg/servicesession" "github.com/loopholelabs/auth/pkg/session" "github.com/loopholelabs/auth/pkg/sessionKind" @@ -266,7 +266,7 @@ func (m *Controller) DecryptMagic(encrypted string) (string, string, error) { return ma.Email, ma.Secret, nil } -func (m *Controller) CreateSession(ctx *fiber.Ctx, kind sessionKind.SessionKind, provider provider.Key, userIdentifier string, organization string) (*fiber.Cookie, error) { +func (m *Controller) CreateSession(ctx *fiber.Ctx, kind sessionKind.SessionKind, provider flow.Key, userIdentifier string, organization string) (*fiber.Cookie, error) { m.logger.Debug().Msgf("creating session for user %s (org '%s')", userIdentifier, organization) exists, err := m.storage.UserExists(ctx.Context(), userIdentifier) if err != nil { diff --git a/internal/database/database.go b/internal/database/database.go deleted file mode 100644 index 4059766..0000000 --- a/internal/database/database.go +++ /dev/null @@ -1,75 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package database - -import ( - "context" - "database/sql" - "entgo.io/ent/dialect" - entsql "entgo.io/ent/dialect/sql" - "github.com/loopholelabs/auth/internal/ent" - "github.com/rs/zerolog" - - _ "github.com/jackc/pgx/v5/stdlib" -) - -type Database struct { - logger *zerolog.Logger - client *ent.Client - ctx context.Context - cancel context.CancelFunc -} - -func New(url string, logger *zerolog.Logger) (*Database, error) { - l := logger.With().Str("AUTH", "DATABASE").Logger() - - l.Debug().Msgf("connecting to %s", url) - db, err := sql.Open("pgx", url) - if err != nil { - return nil, err - } - - client := ent.NewClient(ent.Driver(entsql.OpenDB(dialect.Postgres, db))) - ctx, cancel := context.WithCancel(context.Background()) - - l.Info().Msg("running database migrations") - err = client.Schema.Create(ctx) - if err != nil { - cancel() - return nil, err - } - return &Database{ - logger: &l, - client: client, - ctx: ctx, - cancel: cancel, - }, nil -} - -func (d *Database) Shutdown() error { - if d.cancel != nil { - d.cancel() - } - - if d.client != nil { - err := d.client.Close() - if err != nil { - return err - } - } - return nil -} diff --git a/internal/database/device.go b/internal/database/device.go deleted file mode 100644 index 4083e37..0000000 --- a/internal/database/device.go +++ /dev/null @@ -1,77 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package database - -import ( - "context" - "github.com/loopholelabs/auth/internal/ent" - "github.com/loopholelabs/auth/internal/ent/deviceflow" - "github.com/loopholelabs/auth/internal/provider/device" - "time" -) - -var _ device.Database = (*Database)(nil) - -func (d *Database) SetDeviceFlow(ctx context.Context, identifier string, deviceCode string, userCode string) error { - d.logger.Debug().Msgf("setting device flow for %s (device code %s, user code %s)", identifier, deviceCode, userCode) - _, err := d.client.DeviceFlow.Create().SetIdentifier(identifier).SetDeviceCode(deviceCode).SetUserCode(userCode).Save(ctx) - return err -} - -func (d *Database) GetDeviceFlow(ctx context.Context, deviceCode string) (*ent.DeviceFlow, error) { - d.logger.Debug().Msgf("getting device flow for device code %s", deviceCode) - return d.client.DeviceFlow.Query().Where(deviceflow.DeviceCode(deviceCode)).Only(ctx) -} - -func (d *Database) UpdateDeviceFlow(ctx context.Context, identifier string, session string, expiry time.Time) error { - d.logger.Debug().Msgf("updating device flow for %s (expiry %s)", identifier, expiry) - _, err := d.client.DeviceFlow.Update().Where(deviceflow.Identifier(identifier)).SetSession(session).SetExpiresAt(expiry).Save(ctx) - return err -} - -func (d *Database) GetDeviceFlowUserCode(ctx context.Context, userCode string) (*ent.DeviceFlow, error) { - d.logger.Debug().Msgf("getting device flow for user code %s", userCode) - flow, err := d.client.DeviceFlow.Query().Where(deviceflow.UserCode(userCode)).Only(ctx) - if err != nil { - return nil, err - } - _, err = flow.Update().SetLastPoll(time.Now()).Save(ctx) - if err != nil { - return nil, err - } - return flow, nil -} - -func (d *Database) GetDeviceFlowIdentifier(ctx context.Context, identifier string) (*ent.DeviceFlow, error) { - d.logger.Debug().Msgf("getting device flow for identifier %s", identifier) - flow, err := d.client.DeviceFlow.Query().Where(deviceflow.Identifier(identifier)).Only(ctx) - if err != nil { - return nil, err - } - return flow, nil -} - -func (d *Database) DeleteDeviceFlow(ctx context.Context, deviceCode string) error { - d.logger.Debug().Msgf("deleting device flow for device code %s", deviceCode) - _, err := d.client.DeviceFlow.Delete().Where(deviceflow.DeviceCode(deviceCode)).Exec(ctx) - return err -} - -func (d *Database) GCDeviceFlow(ctx context.Context, expiry time.Duration) (int, error) { - d.logger.Debug().Msgf("running device flow gc") - return d.client.DeviceFlow.Delete().Where(deviceflow.CreatedAtLT(time.Now().Add(expiry * -1))).Exec(ctx) -} diff --git a/internal/database/github.go b/internal/database/github.go deleted file mode 100644 index 78603c8..0000000 --- a/internal/database/github.go +++ /dev/null @@ -1,49 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package database - -import ( - "context" - "github.com/loopholelabs/auth/internal/ent" - "github.com/loopholelabs/auth/internal/ent/githubflow" - "github.com/loopholelabs/auth/internal/provider/github" - "time" -) - -var _ github.Database = (*Database)(nil) - -func (d *Database) SetGithubFlow(ctx context.Context, state string, verifier string, challenge string, nextURL string, organization string, deviceIdentifier string) error { - d.logger.Debug().Msgf("setting github flow for %s", state) - _, err := d.client.GithubFlow.Create().SetIdentifier(state).SetVerifier(verifier).SetChallenge(challenge).SetNextURL(nextURL).SetOrganization(organization).SetDeviceIdentifier(deviceIdentifier).Save(ctx) - return err -} - -func (d *Database) GetGithubFlow(ctx context.Context, state string) (*ent.GithubFlow, error) { - d.logger.Debug().Msgf("getting github flow for %s", state) - return d.client.GithubFlow.Query().Where(githubflow.Identifier(state)).Only(ctx) -} - -func (d *Database) DeleteGithubFlow(ctx context.Context, state string) error { - d.logger.Debug().Msgf("deleting github flow for %s", state) - _, err := d.client.GithubFlow.Delete().Where(githubflow.Identifier(state)).Exec(ctx) - return err -} - -func (d *Database) GCGithubFlow(ctx context.Context, expiry time.Duration) (int, error) { - d.logger.Debug().Msgf("running github flow gc") - return d.client.GithubFlow.Delete().Where(githubflow.CreatedAtLT(time.Now().Add(expiry * -1))).Exec(ctx) -} diff --git a/internal/database/google.go b/internal/database/google.go deleted file mode 100644 index 8c2ea58..0000000 --- a/internal/database/google.go +++ /dev/null @@ -1,49 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package database - -import ( - "context" - "github.com/loopholelabs/auth/internal/ent" - "github.com/loopholelabs/auth/internal/ent/googleflow" - "github.com/loopholelabs/auth/internal/provider/google" - "time" -) - -var _ google.Database = (*Database)(nil) - -func (d *Database) SetGoogleFlow(ctx context.Context, state string, verifier string, challenge string, nextURL string, organization string, deviceIdentifier string) error { - d.logger.Debug().Msgf("setting google flow for %s", state) - _, err := d.client.GoogleFlow.Create().SetIdentifier(state).SetVerifier(verifier).SetChallenge(challenge).SetNextURL(nextURL).SetOrganization(organization).SetDeviceIdentifier(deviceIdentifier).Save(ctx) - return err -} - -func (d *Database) GetGoogleFlow(ctx context.Context, state string) (*ent.GoogleFlow, error) { - d.logger.Debug().Msgf("getting google flow for %s", state) - return d.client.GoogleFlow.Query().Where(googleflow.Identifier(state)).Only(ctx) -} - -func (d *Database) DeleteGoogleFlow(ctx context.Context, state string) error { - d.logger.Debug().Msgf("deleting google flow for %s", state) - _, err := d.client.GoogleFlow.Delete().Where(googleflow.Identifier(state)).Exec(ctx) - return err -} - -func (d *Database) GCGoogleFlow(ctx context.Context, expiry time.Duration) (int, error) { - d.logger.Debug().Msgf("running google flow gc") - return d.client.GoogleFlow.Delete().Where(googleflow.CreatedAtLT(time.Now().Add(expiry * -1))).Exec(ctx) -} diff --git a/internal/database/magic.go b/internal/database/magic.go deleted file mode 100644 index 675c9db..0000000 --- a/internal/database/magic.go +++ /dev/null @@ -1,51 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package database - -import ( - "context" - "github.com/google/uuid" - "github.com/loopholelabs/auth/internal/ent" - "github.com/loopholelabs/auth/internal/ent/magicflow" - "github.com/loopholelabs/auth/internal/provider/magic" - "time" -) - -var _ magic.Database = (*Database)(nil) - -func (d *Database) SetMagicFlow(ctx context.Context, email string, ip string, secret string, nextURL string, organization string, deviceIdentifier string) error { - identifier := uuid.New().String() - d.logger.Debug().Msgf("setting magic flow for %s (identifier: %s)", email, identifier) - _, err := d.client.MagicFlow.Create().SetIdentifier(identifier).SetEmail(email).SetIPAddress(ip).SetSecret(secret).SetNextURL(nextURL).SetOrganization(organization).SetDeviceIdentifier(deviceIdentifier).Save(ctx) - return err -} - -func (d *Database) GetMagicFlow(ctx context.Context, email string) (*ent.MagicFlow, error) { - d.logger.Debug().Msgf("getting magic flow for %s", email) - return d.client.MagicFlow.Query().Where(magicflow.Email(email)).Only(ctx) -} - -func (d *Database) DeleteMagicFlow(ctx context.Context, email string) error { - d.logger.Debug().Msgf("deleting magic flow for %s", email) - _, err := d.client.MagicFlow.Delete().Where(magicflow.Email(email)).Exec(ctx) - return err -} - -func (d *Database) GCMagicFlow(ctx context.Context, expiry time.Duration) (int, error) { - d.logger.Debug().Msgf("running magic flow gc") - return d.client.MagicFlow.Delete().Where(magicflow.CreatedAtLT(time.Now().Add(expiry * -1))).Exec(ctx) -} diff --git a/internal/ent/client.go b/internal/ent/client.go deleted file mode 100644 index a5e7288..0000000 --- a/internal/ent/client.go +++ /dev/null @@ -1,716 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "log" - - "github.com/loopholelabs/auth/internal/ent/migrate" - - "entgo.io/ent" - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "github.com/loopholelabs/auth/internal/ent/deviceflow" - "github.com/loopholelabs/auth/internal/ent/githubflow" - "github.com/loopholelabs/auth/internal/ent/googleflow" - "github.com/loopholelabs/auth/internal/ent/magicflow" -) - -// Client is the client that holds all ent builders. -type Client struct { - config - // Schema is the client for creating, migrating and dropping schema. - Schema *migrate.Schema - // DeviceFlow is the client for interacting with the DeviceFlow builders. - DeviceFlow *DeviceFlowClient - // GithubFlow is the client for interacting with the GithubFlow builders. - GithubFlow *GithubFlowClient - // GoogleFlow is the client for interacting with the GoogleFlow builders. - GoogleFlow *GoogleFlowClient - // MagicFlow is the client for interacting with the MagicFlow builders. - MagicFlow *MagicFlowClient -} - -// NewClient creates a new client configured with the given options. -func NewClient(opts ...Option) *Client { - cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} - cfg.options(opts...) - client := &Client{config: cfg} - client.init() - return client -} - -func (c *Client) init() { - c.Schema = migrate.NewSchema(c.driver) - c.DeviceFlow = NewDeviceFlowClient(c.config) - c.GithubFlow = NewGithubFlowClient(c.config) - c.GoogleFlow = NewGoogleFlowClient(c.config) - c.MagicFlow = NewMagicFlowClient(c.config) -} - -type ( - // config is the configuration for the client and its builder. - config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters - } - // Option function to configure the client. - Option func(*config) -) - -// options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} - -// Open opens a database/sql.DB specified by the driver name and -// the data source name, and returns a new client attached to it. -// Optional parameters can be added for configuring the client. -func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { - switch driverName { - case dialect.MySQL, dialect.Postgres, dialect.SQLite: - drv, err := sql.Open(driverName, dataSourceName) - if err != nil { - return nil, err - } - return NewClient(append(options, Driver(drv))...), nil - default: - return nil, fmt.Errorf("unsupported driver: %q", driverName) - } -} - -// Tx returns a new transactional client. The provided context -// is used until the transaction is committed or rolled back. -func (c *Client) Tx(ctx context.Context) (*Tx, error) { - if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") - } - tx, err := newTx(ctx, c.driver) - if err != nil { - return nil, fmt.Errorf("ent: starting a transaction: %w", err) - } - cfg := c.config - cfg.driver = tx - return &Tx{ - ctx: ctx, - config: cfg, - DeviceFlow: NewDeviceFlowClient(cfg), - GithubFlow: NewGithubFlowClient(cfg), - GoogleFlow: NewGoogleFlowClient(cfg), - MagicFlow: NewMagicFlowClient(cfg), - }, nil -} - -// 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, errors.New("ent: cannot start a transaction within a transaction") - } - tx, err := c.driver.(interface { - BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) - }).BeginTx(ctx, opts) - if err != nil { - return nil, fmt.Errorf("ent: starting a transaction: %w", err) - } - cfg := c.config - cfg.driver = &txDriver{tx: tx, drv: c.driver} - return &Tx{ - ctx: ctx, - config: cfg, - DeviceFlow: NewDeviceFlowClient(cfg), - GithubFlow: NewGithubFlowClient(cfg), - GoogleFlow: NewGoogleFlowClient(cfg), - MagicFlow: NewMagicFlowClient(cfg), - }, nil -} - -// Debug returns a new debug-client. It's used to get verbose logging on specific operations. -// -// client.Debug(). -// DeviceFlow. -// Query(). -// Count(ctx) -func (c *Client) Debug() *Client { - if c.debug { - return c - } - cfg := c.config - cfg.driver = dialect.Debug(c.driver, c.log) - client := &Client{config: cfg} - client.init() - return client -} - -// Close closes the database connection and prevents new queries from starting. -func (c *Client) Close() error { - return c.driver.Close() -} - -// Use adds the mutation hooks to all the entity clients. -// In order to add hooks to a specific client, call: `client.Node.Use(...)`. -func (c *Client) Use(hooks ...Hook) { - c.DeviceFlow.Use(hooks...) - c.GithubFlow.Use(hooks...) - c.GoogleFlow.Use(hooks...) - c.MagicFlow.Use(hooks...) -} - -// Intercept adds the query interceptors to all the entity clients. -// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. -func (c *Client) Intercept(interceptors ...Interceptor) { - c.DeviceFlow.Intercept(interceptors...) - c.GithubFlow.Intercept(interceptors...) - c.GoogleFlow.Intercept(interceptors...) - c.MagicFlow.Intercept(interceptors...) -} - -// Mutate implements the ent.Mutator interface. -func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { - switch m := m.(type) { - case *DeviceFlowMutation: - return c.DeviceFlow.mutate(ctx, m) - case *GithubFlowMutation: - return c.GithubFlow.mutate(ctx, m) - case *GoogleFlowMutation: - return c.GoogleFlow.mutate(ctx, m) - case *MagicFlowMutation: - return c.MagicFlow.mutate(ctx, m) - default: - return nil, fmt.Errorf("ent: unknown mutation type %T", m) - } -} - -// DeviceFlowClient is a client for the DeviceFlow schema. -type DeviceFlowClient struct { - config -} - -// NewDeviceFlowClient returns a client for the DeviceFlow from the given config. -func NewDeviceFlowClient(c config) *DeviceFlowClient { - return &DeviceFlowClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `deviceflow.Hooks(f(g(h())))`. -func (c *DeviceFlowClient) Use(hooks ...Hook) { - c.hooks.DeviceFlow = append(c.hooks.DeviceFlow, hooks...) -} - -// Intercept adds a list of query interceptors to the interceptors stack. -// A call to `Intercept(f, g, h)` equals to `deviceflow.Intercept(f(g(h())))`. -func (c *DeviceFlowClient) Intercept(interceptors ...Interceptor) { - c.inters.DeviceFlow = append(c.inters.DeviceFlow, interceptors...) -} - -// Create returns a builder for creating a DeviceFlow entity. -func (c *DeviceFlowClient) Create() *DeviceFlowCreate { - mutation := newDeviceFlowMutation(c.config, OpCreate) - return &DeviceFlowCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of DeviceFlow entities. -func (c *DeviceFlowClient) CreateBulk(builders ...*DeviceFlowCreate) *DeviceFlowCreateBulk { - return &DeviceFlowCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for DeviceFlow. -func (c *DeviceFlowClient) Update() *DeviceFlowUpdate { - mutation := newDeviceFlowMutation(c.config, OpUpdate) - return &DeviceFlowUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *DeviceFlowClient) UpdateOne(df *DeviceFlow) *DeviceFlowUpdateOne { - mutation := newDeviceFlowMutation(c.config, OpUpdateOne, withDeviceFlow(df)) - return &DeviceFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *DeviceFlowClient) UpdateOneID(id int) *DeviceFlowUpdateOne { - mutation := newDeviceFlowMutation(c.config, OpUpdateOne, withDeviceFlowID(id)) - return &DeviceFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for DeviceFlow. -func (c *DeviceFlowClient) Delete() *DeviceFlowDelete { - mutation := newDeviceFlowMutation(c.config, OpDelete) - return &DeviceFlowDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a builder for deleting the given entity. -func (c *DeviceFlowClient) DeleteOne(df *DeviceFlow) *DeviceFlowDeleteOne { - return c.DeleteOneID(df.ID) -} - -// DeleteOneID returns a builder for deleting the given entity by its id. -func (c *DeviceFlowClient) DeleteOneID(id int) *DeviceFlowDeleteOne { - builder := c.Delete().Where(deviceflow.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &DeviceFlowDeleteOne{builder} -} - -// Query returns a query builder for DeviceFlow. -func (c *DeviceFlowClient) Query() *DeviceFlowQuery { - return &DeviceFlowQuery{ - config: c.config, - ctx: &QueryContext{Type: TypeDeviceFlow}, - inters: c.Interceptors(), - } -} - -// Get returns a DeviceFlow entity by its id. -func (c *DeviceFlowClient) Get(ctx context.Context, id int) (*DeviceFlow, error) { - return c.Query().Where(deviceflow.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *DeviceFlowClient) GetX(ctx context.Context, id int) *DeviceFlow { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// Hooks returns the client hooks. -func (c *DeviceFlowClient) Hooks() []Hook { - return c.hooks.DeviceFlow -} - -// Interceptors returns the client interceptors. -func (c *DeviceFlowClient) Interceptors() []Interceptor { - return c.inters.DeviceFlow -} - -func (c *DeviceFlowClient) mutate(ctx context.Context, m *DeviceFlowMutation) (Value, error) { - switch m.Op() { - case OpCreate: - return (&DeviceFlowCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdate: - return (&DeviceFlowUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdateOne: - return (&DeviceFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpDelete, OpDeleteOne: - return (&DeviceFlowDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) - default: - return nil, fmt.Errorf("ent: unknown DeviceFlow mutation op: %q", m.Op()) - } -} - -// GithubFlowClient is a client for the GithubFlow schema. -type GithubFlowClient struct { - config -} - -// NewGithubFlowClient returns a client for the GithubFlow from the given config. -func NewGithubFlowClient(c config) *GithubFlowClient { - return &GithubFlowClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `githubflow.Hooks(f(g(h())))`. -func (c *GithubFlowClient) Use(hooks ...Hook) { - c.hooks.GithubFlow = append(c.hooks.GithubFlow, hooks...) -} - -// Intercept adds a list of query interceptors to the interceptors stack. -// A call to `Intercept(f, g, h)` equals to `githubflow.Intercept(f(g(h())))`. -func (c *GithubFlowClient) Intercept(interceptors ...Interceptor) { - c.inters.GithubFlow = append(c.inters.GithubFlow, interceptors...) -} - -// Create returns a builder for creating a GithubFlow entity. -func (c *GithubFlowClient) Create() *GithubFlowCreate { - mutation := newGithubFlowMutation(c.config, OpCreate) - return &GithubFlowCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of GithubFlow entities. -func (c *GithubFlowClient) CreateBulk(builders ...*GithubFlowCreate) *GithubFlowCreateBulk { - return &GithubFlowCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for GithubFlow. -func (c *GithubFlowClient) Update() *GithubFlowUpdate { - mutation := newGithubFlowMutation(c.config, OpUpdate) - return &GithubFlowUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *GithubFlowClient) UpdateOne(gf *GithubFlow) *GithubFlowUpdateOne { - mutation := newGithubFlowMutation(c.config, OpUpdateOne, withGithubFlow(gf)) - return &GithubFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *GithubFlowClient) UpdateOneID(id int) *GithubFlowUpdateOne { - mutation := newGithubFlowMutation(c.config, OpUpdateOne, withGithubFlowID(id)) - return &GithubFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for GithubFlow. -func (c *GithubFlowClient) Delete() *GithubFlowDelete { - mutation := newGithubFlowMutation(c.config, OpDelete) - return &GithubFlowDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a builder for deleting the given entity. -func (c *GithubFlowClient) DeleteOne(gf *GithubFlow) *GithubFlowDeleteOne { - return c.DeleteOneID(gf.ID) -} - -// DeleteOneID returns a builder for deleting the given entity by its id. -func (c *GithubFlowClient) DeleteOneID(id int) *GithubFlowDeleteOne { - builder := c.Delete().Where(githubflow.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &GithubFlowDeleteOne{builder} -} - -// Query returns a query builder for GithubFlow. -func (c *GithubFlowClient) Query() *GithubFlowQuery { - return &GithubFlowQuery{ - config: c.config, - ctx: &QueryContext{Type: TypeGithubFlow}, - inters: c.Interceptors(), - } -} - -// Get returns a GithubFlow entity by its id. -func (c *GithubFlowClient) Get(ctx context.Context, id int) (*GithubFlow, error) { - return c.Query().Where(githubflow.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *GithubFlowClient) GetX(ctx context.Context, id int) *GithubFlow { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// Hooks returns the client hooks. -func (c *GithubFlowClient) Hooks() []Hook { - return c.hooks.GithubFlow -} - -// Interceptors returns the client interceptors. -func (c *GithubFlowClient) Interceptors() []Interceptor { - return c.inters.GithubFlow -} - -func (c *GithubFlowClient) mutate(ctx context.Context, m *GithubFlowMutation) (Value, error) { - switch m.Op() { - case OpCreate: - return (&GithubFlowCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdate: - return (&GithubFlowUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdateOne: - return (&GithubFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpDelete, OpDeleteOne: - return (&GithubFlowDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) - default: - return nil, fmt.Errorf("ent: unknown GithubFlow mutation op: %q", m.Op()) - } -} - -// GoogleFlowClient is a client for the GoogleFlow schema. -type GoogleFlowClient struct { - config -} - -// NewGoogleFlowClient returns a client for the GoogleFlow from the given config. -func NewGoogleFlowClient(c config) *GoogleFlowClient { - return &GoogleFlowClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `googleflow.Hooks(f(g(h())))`. -func (c *GoogleFlowClient) Use(hooks ...Hook) { - c.hooks.GoogleFlow = append(c.hooks.GoogleFlow, hooks...) -} - -// Intercept adds a list of query interceptors to the interceptors stack. -// A call to `Intercept(f, g, h)` equals to `googleflow.Intercept(f(g(h())))`. -func (c *GoogleFlowClient) Intercept(interceptors ...Interceptor) { - c.inters.GoogleFlow = append(c.inters.GoogleFlow, interceptors...) -} - -// Create returns a builder for creating a GoogleFlow entity. -func (c *GoogleFlowClient) Create() *GoogleFlowCreate { - mutation := newGoogleFlowMutation(c.config, OpCreate) - return &GoogleFlowCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of GoogleFlow entities. -func (c *GoogleFlowClient) CreateBulk(builders ...*GoogleFlowCreate) *GoogleFlowCreateBulk { - return &GoogleFlowCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for GoogleFlow. -func (c *GoogleFlowClient) Update() *GoogleFlowUpdate { - mutation := newGoogleFlowMutation(c.config, OpUpdate) - return &GoogleFlowUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *GoogleFlowClient) UpdateOne(gf *GoogleFlow) *GoogleFlowUpdateOne { - mutation := newGoogleFlowMutation(c.config, OpUpdateOne, withGoogleFlow(gf)) - return &GoogleFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *GoogleFlowClient) UpdateOneID(id int) *GoogleFlowUpdateOne { - mutation := newGoogleFlowMutation(c.config, OpUpdateOne, withGoogleFlowID(id)) - return &GoogleFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for GoogleFlow. -func (c *GoogleFlowClient) Delete() *GoogleFlowDelete { - mutation := newGoogleFlowMutation(c.config, OpDelete) - return &GoogleFlowDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a builder for deleting the given entity. -func (c *GoogleFlowClient) DeleteOne(gf *GoogleFlow) *GoogleFlowDeleteOne { - return c.DeleteOneID(gf.ID) -} - -// DeleteOneID returns a builder for deleting the given entity by its id. -func (c *GoogleFlowClient) DeleteOneID(id int) *GoogleFlowDeleteOne { - builder := c.Delete().Where(googleflow.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &GoogleFlowDeleteOne{builder} -} - -// Query returns a query builder for GoogleFlow. -func (c *GoogleFlowClient) Query() *GoogleFlowQuery { - return &GoogleFlowQuery{ - config: c.config, - ctx: &QueryContext{Type: TypeGoogleFlow}, - inters: c.Interceptors(), - } -} - -// Get returns a GoogleFlow entity by its id. -func (c *GoogleFlowClient) Get(ctx context.Context, id int) (*GoogleFlow, error) { - return c.Query().Where(googleflow.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *GoogleFlowClient) GetX(ctx context.Context, id int) *GoogleFlow { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// Hooks returns the client hooks. -func (c *GoogleFlowClient) Hooks() []Hook { - return c.hooks.GoogleFlow -} - -// Interceptors returns the client interceptors. -func (c *GoogleFlowClient) Interceptors() []Interceptor { - return c.inters.GoogleFlow -} - -func (c *GoogleFlowClient) mutate(ctx context.Context, m *GoogleFlowMutation) (Value, error) { - switch m.Op() { - case OpCreate: - return (&GoogleFlowCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdate: - return (&GoogleFlowUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdateOne: - return (&GoogleFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpDelete, OpDeleteOne: - return (&GoogleFlowDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) - default: - return nil, fmt.Errorf("ent: unknown GoogleFlow mutation op: %q", m.Op()) - } -} - -// MagicFlowClient is a client for the MagicFlow schema. -type MagicFlowClient struct { - config -} - -// NewMagicFlowClient returns a client for the MagicFlow from the given config. -func NewMagicFlowClient(c config) *MagicFlowClient { - return &MagicFlowClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `magicflow.Hooks(f(g(h())))`. -func (c *MagicFlowClient) Use(hooks ...Hook) { - c.hooks.MagicFlow = append(c.hooks.MagicFlow, hooks...) -} - -// Intercept adds a list of query interceptors to the interceptors stack. -// A call to `Intercept(f, g, h)` equals to `magicflow.Intercept(f(g(h())))`. -func (c *MagicFlowClient) Intercept(interceptors ...Interceptor) { - c.inters.MagicFlow = append(c.inters.MagicFlow, interceptors...) -} - -// Create returns a builder for creating a MagicFlow entity. -func (c *MagicFlowClient) Create() *MagicFlowCreate { - mutation := newMagicFlowMutation(c.config, OpCreate) - return &MagicFlowCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of MagicFlow entities. -func (c *MagicFlowClient) CreateBulk(builders ...*MagicFlowCreate) *MagicFlowCreateBulk { - return &MagicFlowCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for MagicFlow. -func (c *MagicFlowClient) Update() *MagicFlowUpdate { - mutation := newMagicFlowMutation(c.config, OpUpdate) - return &MagicFlowUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *MagicFlowClient) UpdateOne(mf *MagicFlow) *MagicFlowUpdateOne { - mutation := newMagicFlowMutation(c.config, OpUpdateOne, withMagicFlow(mf)) - return &MagicFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *MagicFlowClient) UpdateOneID(id int) *MagicFlowUpdateOne { - mutation := newMagicFlowMutation(c.config, OpUpdateOne, withMagicFlowID(id)) - return &MagicFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for MagicFlow. -func (c *MagicFlowClient) Delete() *MagicFlowDelete { - mutation := newMagicFlowMutation(c.config, OpDelete) - return &MagicFlowDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a builder for deleting the given entity. -func (c *MagicFlowClient) DeleteOne(mf *MagicFlow) *MagicFlowDeleteOne { - return c.DeleteOneID(mf.ID) -} - -// DeleteOneID returns a builder for deleting the given entity by its id. -func (c *MagicFlowClient) DeleteOneID(id int) *MagicFlowDeleteOne { - builder := c.Delete().Where(magicflow.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &MagicFlowDeleteOne{builder} -} - -// Query returns a query builder for MagicFlow. -func (c *MagicFlowClient) Query() *MagicFlowQuery { - return &MagicFlowQuery{ - config: c.config, - ctx: &QueryContext{Type: TypeMagicFlow}, - inters: c.Interceptors(), - } -} - -// Get returns a MagicFlow entity by its id. -func (c *MagicFlowClient) Get(ctx context.Context, id int) (*MagicFlow, error) { - return c.Query().Where(magicflow.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *MagicFlowClient) GetX(ctx context.Context, id int) *MagicFlow { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// Hooks returns the client hooks. -func (c *MagicFlowClient) Hooks() []Hook { - return c.hooks.MagicFlow -} - -// Interceptors returns the client interceptors. -func (c *MagicFlowClient) Interceptors() []Interceptor { - return c.inters.MagicFlow -} - -func (c *MagicFlowClient) mutate(ctx context.Context, m *MagicFlowMutation) (Value, error) { - switch m.Op() { - case OpCreate: - return (&MagicFlowCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdate: - return (&MagicFlowUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdateOne: - return (&MagicFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpDelete, OpDeleteOne: - return (&MagicFlowDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) - default: - return nil, fmt.Errorf("ent: unknown MagicFlow mutation op: %q", m.Op()) - } -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - DeviceFlow, GithubFlow, GoogleFlow, MagicFlow []ent.Hook - } - inters struct { - DeviceFlow, GithubFlow, GoogleFlow, MagicFlow []ent.Interceptor - } -) diff --git a/internal/ent/deviceflow.go b/internal/ent/deviceflow.go deleted file mode 100644 index ea85146..0000000 --- a/internal/ent/deviceflow.go +++ /dev/null @@ -1,188 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "github.com/loopholelabs/auth/internal/ent/deviceflow" -) - -// DeviceFlow is the model entity for the DeviceFlow schema. -type DeviceFlow struct { - config `json:"-"` - // ID of the ent. - ID int `json:"id,omitempty"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at,omitempty"` - // Identifier holds the value of the "identifier" field. - Identifier string `json:"identifier,omitempty"` - // DeviceCode holds the value of the "device_code" field. - DeviceCode string `json:"device_code,omitempty"` - // UserCode holds the value of the "user_code" field. - UserCode string `json:"user_code,omitempty"` - // Session holds the value of the "session" field. - Session string `json:"session,omitempty"` - // LastPoll holds the value of the "last_poll" field. - LastPoll time.Time `json:"last_poll,omitempty"` - // ExpiresAt holds the value of the "expires_at" field. - ExpiresAt time.Time `json:"expires_at,omitempty"` - selectValues sql.SelectValues -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*DeviceFlow) scanValues(columns []string) ([]any, error) { - values := make([]any, len(columns)) - for i := range columns { - switch columns[i] { - case deviceflow.FieldID: - values[i] = new(sql.NullInt64) - case deviceflow.FieldIdentifier, deviceflow.FieldDeviceCode, deviceflow.FieldUserCode, deviceflow.FieldSession: - values[i] = new(sql.NullString) - case deviceflow.FieldCreatedAt, deviceflow.FieldLastPoll, deviceflow.FieldExpiresAt: - values[i] = new(sql.NullTime) - default: - values[i] = new(sql.UnknownType) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the DeviceFlow fields. -func (df *DeviceFlow) assignValues(columns []string, values []any) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case deviceflow.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - df.ID = int(value.Int64) - case deviceflow.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 { - df.CreatedAt = value.Time - } - case deviceflow.FieldIdentifier: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field identifier", values[i]) - } else if value.Valid { - df.Identifier = value.String - } - case deviceflow.FieldDeviceCode: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field device_code", values[i]) - } else if value.Valid { - df.DeviceCode = value.String - } - case deviceflow.FieldUserCode: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field user_code", values[i]) - } else if value.Valid { - df.UserCode = value.String - } - case deviceflow.FieldSession: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field session", values[i]) - } else if value.Valid { - df.Session = value.String - } - case deviceflow.FieldLastPoll: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field last_poll", values[i]) - } else if value.Valid { - df.LastPoll = value.Time - } - case deviceflow.FieldExpiresAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field expires_at", values[i]) - } else if value.Valid { - df.ExpiresAt = value.Time - } - default: - df.selectValues.Set(columns[i], values[i]) - } - } - return nil -} - -// Value returns the ent.Value that was dynamically selected and assigned to the DeviceFlow. -// This includes values selected through modifiers, order, etc. -func (df *DeviceFlow) Value(name string) (ent.Value, error) { - return df.selectValues.Get(name) -} - -// Update returns a builder for updating this DeviceFlow. -// Note that you need to call DeviceFlow.Unwrap() before calling this method if this DeviceFlow -// was returned from a transaction, and the transaction was committed or rolled back. -func (df *DeviceFlow) Update() *DeviceFlowUpdateOne { - return NewDeviceFlowClient(df.config).UpdateOne(df) -} - -// Unwrap unwraps the DeviceFlow 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 (df *DeviceFlow) Unwrap() *DeviceFlow { - _tx, ok := df.config.driver.(*txDriver) - if !ok { - panic("ent: DeviceFlow is not a transactional entity") - } - df.config.driver = _tx.drv - return df -} - -// String implements the fmt.Stringer. -func (df *DeviceFlow) String() string { - var builder strings.Builder - builder.WriteString("DeviceFlow(") - builder.WriteString(fmt.Sprintf("id=%v, ", df.ID)) - builder.WriteString("created_at=") - builder.WriteString(df.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("identifier=") - builder.WriteString(df.Identifier) - builder.WriteString(", ") - builder.WriteString("device_code=") - builder.WriteString(df.DeviceCode) - builder.WriteString(", ") - builder.WriteString("user_code=") - builder.WriteString(df.UserCode) - builder.WriteString(", ") - builder.WriteString("session=") - builder.WriteString(df.Session) - builder.WriteString(", ") - builder.WriteString("last_poll=") - builder.WriteString(df.LastPoll.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("expires_at=") - builder.WriteString(df.ExpiresAt.Format(time.ANSIC)) - builder.WriteByte(')') - return builder.String() -} - -// DeviceFlows is a parsable slice of DeviceFlow. -type DeviceFlows []*DeviceFlow diff --git a/internal/ent/deviceflow/deviceflow.go b/internal/ent/deviceflow/deviceflow.go deleted file mode 100644 index 6938a4c..0000000 --- a/internal/ent/deviceflow/deviceflow.go +++ /dev/null @@ -1,126 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package deviceflow - -import ( - "time" - - "entgo.io/ent/dialect/sql" -) - -const ( - // Label holds the string label denoting the deviceflow type in the database. - Label = "device_flow" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldCreatedAt holds the string denoting the created_at field in the database. - FieldCreatedAt = "created_at" - // FieldIdentifier holds the string denoting the identifier field in the database. - FieldIdentifier = "identifier" - // FieldDeviceCode holds the string denoting the device_code field in the database. - FieldDeviceCode = "device_code" - // FieldUserCode holds the string denoting the user_code field in the database. - FieldUserCode = "user_code" - // FieldSession holds the string denoting the session field in the database. - FieldSession = "session" - // FieldLastPoll holds the string denoting the last_poll field in the database. - FieldLastPoll = "last_poll" - // FieldExpiresAt holds the string denoting the expires_at field in the database. - FieldExpiresAt = "expires_at" - // Table holds the table name of the deviceflow in the database. - Table = "device_flows" -) - -// Columns holds all SQL columns for deviceflow fields. -var Columns = []string{ - FieldID, - FieldCreatedAt, - FieldIdentifier, - FieldDeviceCode, - FieldUserCode, - FieldSession, - FieldLastPoll, - FieldExpiresAt, -} - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} - -var ( - // DefaultCreatedAt holds the default value on creation for the "created_at" field. - DefaultCreatedAt func() time.Time - // IdentifierValidator is a validator for the "identifier" field. It is called by the builders before save. - IdentifierValidator func(string) error - // DeviceCodeValidator is a validator for the "device_code" field. It is called by the builders before save. - DeviceCodeValidator func(string) error - // UserCodeValidator is a validator for the "user_code" field. It is called by the builders before save. - UserCodeValidator func(string) error - // DefaultLastPoll holds the default value on creation for the "last_poll" field. - DefaultLastPoll func() time.Time -) - -// OrderOption defines the ordering options for the DeviceFlow queries. -type OrderOption func(*sql.Selector) - -// ByID orders the results by the id field. -func ByID(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldID, opts...).ToFunc() -} - -// ByCreatedAt orders the results by the created_at field. -func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() -} - -// ByIdentifier orders the results by the identifier field. -func ByIdentifier(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldIdentifier, opts...).ToFunc() -} - -// ByDeviceCode orders the results by the device_code field. -func ByDeviceCode(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldDeviceCode, opts...).ToFunc() -} - -// ByUserCode orders the results by the user_code field. -func ByUserCode(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldUserCode, opts...).ToFunc() -} - -// BySession orders the results by the session field. -func BySession(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldSession, opts...).ToFunc() -} - -// ByLastPoll orders the results by the last_poll field. -func ByLastPoll(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldLastPoll, opts...).ToFunc() -} - -// ByExpiresAt orders the results by the expires_at field. -func ByExpiresAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldExpiresAt, opts...).ToFunc() -} diff --git a/internal/ent/deviceflow/where.go b/internal/ent/deviceflow/where.go deleted file mode 100644 index b566679..0000000 --- a/internal/ent/deviceflow/where.go +++ /dev/null @@ -1,538 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package deviceflow - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id int) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldID, id)) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldID, id)) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNEQ(FieldID, id)) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldIn(FieldID, ids...)) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNotIn(FieldID, ids...)) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGT(FieldID, id)) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGTE(FieldID, id)) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLT(FieldID, id)) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLTE(FieldID, id)) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldCreatedAt, v)) -} - -// Identifier applies equality check predicate on the "identifier" field. It's identical to IdentifierEQ. -func Identifier(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldIdentifier, v)) -} - -// DeviceCode applies equality check predicate on the "device_code" field. It's identical to DeviceCodeEQ. -func DeviceCode(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldDeviceCode, v)) -} - -// UserCode applies equality check predicate on the "user_code" field. It's identical to UserCodeEQ. -func UserCode(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldUserCode, v)) -} - -// Session applies equality check predicate on the "session" field. It's identical to SessionEQ. -func Session(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldSession, v)) -} - -// LastPoll applies equality check predicate on the "last_poll" field. It's identical to LastPollEQ. -func LastPoll(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldLastPoll, v)) -} - -// ExpiresAt applies equality check predicate on the "expires_at" field. It's identical to ExpiresAtEQ. -func ExpiresAt(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldExpiresAt, v)) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldCreatedAt, v)) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNEQ(FieldCreatedAt, v)) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldIn(FieldCreatedAt, vs...)) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNotIn(FieldCreatedAt, vs...)) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGT(FieldCreatedAt, v)) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGTE(FieldCreatedAt, v)) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLT(FieldCreatedAt, v)) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLTE(FieldCreatedAt, v)) -} - -// IdentifierEQ applies the EQ predicate on the "identifier" field. -func IdentifierEQ(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldIdentifier, v)) -} - -// IdentifierNEQ applies the NEQ predicate on the "identifier" field. -func IdentifierNEQ(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNEQ(FieldIdentifier, v)) -} - -// IdentifierIn applies the In predicate on the "identifier" field. -func IdentifierIn(vs ...string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldIn(FieldIdentifier, vs...)) -} - -// IdentifierNotIn applies the NotIn predicate on the "identifier" field. -func IdentifierNotIn(vs ...string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNotIn(FieldIdentifier, vs...)) -} - -// IdentifierGT applies the GT predicate on the "identifier" field. -func IdentifierGT(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGT(FieldIdentifier, v)) -} - -// IdentifierGTE applies the GTE predicate on the "identifier" field. -func IdentifierGTE(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGTE(FieldIdentifier, v)) -} - -// IdentifierLT applies the LT predicate on the "identifier" field. -func IdentifierLT(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLT(FieldIdentifier, v)) -} - -// IdentifierLTE applies the LTE predicate on the "identifier" field. -func IdentifierLTE(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLTE(FieldIdentifier, v)) -} - -// IdentifierContains applies the Contains predicate on the "identifier" field. -func IdentifierContains(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldContains(FieldIdentifier, v)) -} - -// IdentifierHasPrefix applies the HasPrefix predicate on the "identifier" field. -func IdentifierHasPrefix(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldHasPrefix(FieldIdentifier, v)) -} - -// IdentifierHasSuffix applies the HasSuffix predicate on the "identifier" field. -func IdentifierHasSuffix(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldHasSuffix(FieldIdentifier, v)) -} - -// IdentifierEqualFold applies the EqualFold predicate on the "identifier" field. -func IdentifierEqualFold(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEqualFold(FieldIdentifier, v)) -} - -// IdentifierContainsFold applies the ContainsFold predicate on the "identifier" field. -func IdentifierContainsFold(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldContainsFold(FieldIdentifier, v)) -} - -// DeviceCodeEQ applies the EQ predicate on the "device_code" field. -func DeviceCodeEQ(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldDeviceCode, v)) -} - -// DeviceCodeNEQ applies the NEQ predicate on the "device_code" field. -func DeviceCodeNEQ(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNEQ(FieldDeviceCode, v)) -} - -// DeviceCodeIn applies the In predicate on the "device_code" field. -func DeviceCodeIn(vs ...string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldIn(FieldDeviceCode, vs...)) -} - -// DeviceCodeNotIn applies the NotIn predicate on the "device_code" field. -func DeviceCodeNotIn(vs ...string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNotIn(FieldDeviceCode, vs...)) -} - -// DeviceCodeGT applies the GT predicate on the "device_code" field. -func DeviceCodeGT(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGT(FieldDeviceCode, v)) -} - -// DeviceCodeGTE applies the GTE predicate on the "device_code" field. -func DeviceCodeGTE(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGTE(FieldDeviceCode, v)) -} - -// DeviceCodeLT applies the LT predicate on the "device_code" field. -func DeviceCodeLT(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLT(FieldDeviceCode, v)) -} - -// DeviceCodeLTE applies the LTE predicate on the "device_code" field. -func DeviceCodeLTE(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLTE(FieldDeviceCode, v)) -} - -// DeviceCodeContains applies the Contains predicate on the "device_code" field. -func DeviceCodeContains(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldContains(FieldDeviceCode, v)) -} - -// DeviceCodeHasPrefix applies the HasPrefix predicate on the "device_code" field. -func DeviceCodeHasPrefix(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldHasPrefix(FieldDeviceCode, v)) -} - -// DeviceCodeHasSuffix applies the HasSuffix predicate on the "device_code" field. -func DeviceCodeHasSuffix(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldHasSuffix(FieldDeviceCode, v)) -} - -// DeviceCodeEqualFold applies the EqualFold predicate on the "device_code" field. -func DeviceCodeEqualFold(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEqualFold(FieldDeviceCode, v)) -} - -// DeviceCodeContainsFold applies the ContainsFold predicate on the "device_code" field. -func DeviceCodeContainsFold(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldContainsFold(FieldDeviceCode, v)) -} - -// UserCodeEQ applies the EQ predicate on the "user_code" field. -func UserCodeEQ(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldUserCode, v)) -} - -// UserCodeNEQ applies the NEQ predicate on the "user_code" field. -func UserCodeNEQ(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNEQ(FieldUserCode, v)) -} - -// UserCodeIn applies the In predicate on the "user_code" field. -func UserCodeIn(vs ...string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldIn(FieldUserCode, vs...)) -} - -// UserCodeNotIn applies the NotIn predicate on the "user_code" field. -func UserCodeNotIn(vs ...string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNotIn(FieldUserCode, vs...)) -} - -// UserCodeGT applies the GT predicate on the "user_code" field. -func UserCodeGT(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGT(FieldUserCode, v)) -} - -// UserCodeGTE applies the GTE predicate on the "user_code" field. -func UserCodeGTE(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGTE(FieldUserCode, v)) -} - -// UserCodeLT applies the LT predicate on the "user_code" field. -func UserCodeLT(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLT(FieldUserCode, v)) -} - -// UserCodeLTE applies the LTE predicate on the "user_code" field. -func UserCodeLTE(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLTE(FieldUserCode, v)) -} - -// UserCodeContains applies the Contains predicate on the "user_code" field. -func UserCodeContains(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldContains(FieldUserCode, v)) -} - -// UserCodeHasPrefix applies the HasPrefix predicate on the "user_code" field. -func UserCodeHasPrefix(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldHasPrefix(FieldUserCode, v)) -} - -// UserCodeHasSuffix applies the HasSuffix predicate on the "user_code" field. -func UserCodeHasSuffix(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldHasSuffix(FieldUserCode, v)) -} - -// UserCodeEqualFold applies the EqualFold predicate on the "user_code" field. -func UserCodeEqualFold(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEqualFold(FieldUserCode, v)) -} - -// UserCodeContainsFold applies the ContainsFold predicate on the "user_code" field. -func UserCodeContainsFold(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldContainsFold(FieldUserCode, v)) -} - -// SessionEQ applies the EQ predicate on the "session" field. -func SessionEQ(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldSession, v)) -} - -// SessionNEQ applies the NEQ predicate on the "session" field. -func SessionNEQ(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNEQ(FieldSession, v)) -} - -// SessionIn applies the In predicate on the "session" field. -func SessionIn(vs ...string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldIn(FieldSession, vs...)) -} - -// SessionNotIn applies the NotIn predicate on the "session" field. -func SessionNotIn(vs ...string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNotIn(FieldSession, vs...)) -} - -// SessionGT applies the GT predicate on the "session" field. -func SessionGT(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGT(FieldSession, v)) -} - -// SessionGTE applies the GTE predicate on the "session" field. -func SessionGTE(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGTE(FieldSession, v)) -} - -// SessionLT applies the LT predicate on the "session" field. -func SessionLT(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLT(FieldSession, v)) -} - -// SessionLTE applies the LTE predicate on the "session" field. -func SessionLTE(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLTE(FieldSession, v)) -} - -// SessionContains applies the Contains predicate on the "session" field. -func SessionContains(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldContains(FieldSession, v)) -} - -// SessionHasPrefix applies the HasPrefix predicate on the "session" field. -func SessionHasPrefix(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldHasPrefix(FieldSession, v)) -} - -// SessionHasSuffix applies the HasSuffix predicate on the "session" field. -func SessionHasSuffix(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldHasSuffix(FieldSession, v)) -} - -// SessionIsNil applies the IsNil predicate on the "session" field. -func SessionIsNil() predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldIsNull(FieldSession)) -} - -// SessionNotNil applies the NotNil predicate on the "session" field. -func SessionNotNil() predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNotNull(FieldSession)) -} - -// SessionEqualFold applies the EqualFold predicate on the "session" field. -func SessionEqualFold(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEqualFold(FieldSession, v)) -} - -// SessionContainsFold applies the ContainsFold predicate on the "session" field. -func SessionContainsFold(v string) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldContainsFold(FieldSession, v)) -} - -// LastPollEQ applies the EQ predicate on the "last_poll" field. -func LastPollEQ(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldLastPoll, v)) -} - -// LastPollNEQ applies the NEQ predicate on the "last_poll" field. -func LastPollNEQ(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNEQ(FieldLastPoll, v)) -} - -// LastPollIn applies the In predicate on the "last_poll" field. -func LastPollIn(vs ...time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldIn(FieldLastPoll, vs...)) -} - -// LastPollNotIn applies the NotIn predicate on the "last_poll" field. -func LastPollNotIn(vs ...time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNotIn(FieldLastPoll, vs...)) -} - -// LastPollGT applies the GT predicate on the "last_poll" field. -func LastPollGT(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGT(FieldLastPoll, v)) -} - -// LastPollGTE applies the GTE predicate on the "last_poll" field. -func LastPollGTE(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGTE(FieldLastPoll, v)) -} - -// LastPollLT applies the LT predicate on the "last_poll" field. -func LastPollLT(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLT(FieldLastPoll, v)) -} - -// LastPollLTE applies the LTE predicate on the "last_poll" field. -func LastPollLTE(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLTE(FieldLastPoll, v)) -} - -// ExpiresAtEQ applies the EQ predicate on the "expires_at" field. -func ExpiresAtEQ(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldEQ(FieldExpiresAt, v)) -} - -// ExpiresAtNEQ applies the NEQ predicate on the "expires_at" field. -func ExpiresAtNEQ(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNEQ(FieldExpiresAt, v)) -} - -// ExpiresAtIn applies the In predicate on the "expires_at" field. -func ExpiresAtIn(vs ...time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldIn(FieldExpiresAt, vs...)) -} - -// ExpiresAtNotIn applies the NotIn predicate on the "expires_at" field. -func ExpiresAtNotIn(vs ...time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNotIn(FieldExpiresAt, vs...)) -} - -// ExpiresAtGT applies the GT predicate on the "expires_at" field. -func ExpiresAtGT(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGT(FieldExpiresAt, v)) -} - -// ExpiresAtGTE applies the GTE predicate on the "expires_at" field. -func ExpiresAtGTE(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldGTE(FieldExpiresAt, v)) -} - -// ExpiresAtLT applies the LT predicate on the "expires_at" field. -func ExpiresAtLT(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLT(FieldExpiresAt, v)) -} - -// ExpiresAtLTE applies the LTE predicate on the "expires_at" field. -func ExpiresAtLTE(v time.Time) predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldLTE(FieldExpiresAt, v)) -} - -// ExpiresAtIsNil applies the IsNil predicate on the "expires_at" field. -func ExpiresAtIsNil() predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldIsNull(FieldExpiresAt)) -} - -// ExpiresAtNotNil applies the NotNil predicate on the "expires_at" field. -func ExpiresAtNotNil() predicate.DeviceFlow { - return predicate.DeviceFlow(sql.FieldNotNull(FieldExpiresAt)) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.DeviceFlow) predicate.DeviceFlow { - return predicate.DeviceFlow(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.DeviceFlow) predicate.DeviceFlow { - return predicate.DeviceFlow(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.DeviceFlow) predicate.DeviceFlow { - return predicate.DeviceFlow(func(s *sql.Selector) { - p(s.Not()) - }) -} diff --git a/internal/ent/deviceflow_create.go b/internal/ent/deviceflow_create.go deleted file mode 100644 index 9a9077e..0000000 --- a/internal/ent/deviceflow_create.go +++ /dev/null @@ -1,329 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/deviceflow" -) - -// DeviceFlowCreate is the builder for creating a DeviceFlow entity. -type DeviceFlowCreate struct { - config - mutation *DeviceFlowMutation - hooks []Hook -} - -// SetCreatedAt sets the "created_at" field. -func (dfc *DeviceFlowCreate) SetCreatedAt(t time.Time) *DeviceFlowCreate { - dfc.mutation.SetCreatedAt(t) - return dfc -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (dfc *DeviceFlowCreate) SetNillableCreatedAt(t *time.Time) *DeviceFlowCreate { - if t != nil { - dfc.SetCreatedAt(*t) - } - return dfc -} - -// SetIdentifier sets the "identifier" field. -func (dfc *DeviceFlowCreate) SetIdentifier(s string) *DeviceFlowCreate { - dfc.mutation.SetIdentifier(s) - return dfc -} - -// SetDeviceCode sets the "device_code" field. -func (dfc *DeviceFlowCreate) SetDeviceCode(s string) *DeviceFlowCreate { - dfc.mutation.SetDeviceCode(s) - return dfc -} - -// SetUserCode sets the "user_code" field. -func (dfc *DeviceFlowCreate) SetUserCode(s string) *DeviceFlowCreate { - dfc.mutation.SetUserCode(s) - return dfc -} - -// SetSession sets the "session" field. -func (dfc *DeviceFlowCreate) SetSession(s string) *DeviceFlowCreate { - dfc.mutation.SetSession(s) - return dfc -} - -// SetNillableSession sets the "session" field if the given value is not nil. -func (dfc *DeviceFlowCreate) SetNillableSession(s *string) *DeviceFlowCreate { - if s != nil { - dfc.SetSession(*s) - } - return dfc -} - -// SetLastPoll sets the "last_poll" field. -func (dfc *DeviceFlowCreate) SetLastPoll(t time.Time) *DeviceFlowCreate { - dfc.mutation.SetLastPoll(t) - return dfc -} - -// SetNillableLastPoll sets the "last_poll" field if the given value is not nil. -func (dfc *DeviceFlowCreate) SetNillableLastPoll(t *time.Time) *DeviceFlowCreate { - if t != nil { - dfc.SetLastPoll(*t) - } - return dfc -} - -// SetExpiresAt sets the "expires_at" field. -func (dfc *DeviceFlowCreate) SetExpiresAt(t time.Time) *DeviceFlowCreate { - dfc.mutation.SetExpiresAt(t) - return dfc -} - -// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil. -func (dfc *DeviceFlowCreate) SetNillableExpiresAt(t *time.Time) *DeviceFlowCreate { - if t != nil { - dfc.SetExpiresAt(*t) - } - return dfc -} - -// Mutation returns the DeviceFlowMutation object of the builder. -func (dfc *DeviceFlowCreate) Mutation() *DeviceFlowMutation { - return dfc.mutation -} - -// Save creates the DeviceFlow in the database. -func (dfc *DeviceFlowCreate) Save(ctx context.Context) (*DeviceFlow, error) { - dfc.defaults() - return withHooks(ctx, dfc.sqlSave, dfc.mutation, dfc.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (dfc *DeviceFlowCreate) SaveX(ctx context.Context) *DeviceFlow { - v, err := dfc.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (dfc *DeviceFlowCreate) Exec(ctx context.Context) error { - _, err := dfc.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (dfc *DeviceFlowCreate) ExecX(ctx context.Context) { - if err := dfc.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (dfc *DeviceFlowCreate) defaults() { - if _, ok := dfc.mutation.CreatedAt(); !ok { - v := deviceflow.DefaultCreatedAt() - dfc.mutation.SetCreatedAt(v) - } - if _, ok := dfc.mutation.LastPoll(); !ok { - v := deviceflow.DefaultLastPoll() - dfc.mutation.SetLastPoll(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (dfc *DeviceFlowCreate) check() error { - if _, ok := dfc.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "DeviceFlow.created_at"`)} - } - if _, ok := dfc.mutation.Identifier(); !ok { - return &ValidationError{Name: "identifier", err: errors.New(`ent: missing required field "DeviceFlow.identifier"`)} - } - if v, ok := dfc.mutation.Identifier(); ok { - if err := deviceflow.IdentifierValidator(v); err != nil { - return &ValidationError{Name: "identifier", err: fmt.Errorf(`ent: validator failed for field "DeviceFlow.identifier": %w`, err)} - } - } - if _, ok := dfc.mutation.DeviceCode(); !ok { - return &ValidationError{Name: "device_code", err: errors.New(`ent: missing required field "DeviceFlow.device_code"`)} - } - if v, ok := dfc.mutation.DeviceCode(); ok { - if err := deviceflow.DeviceCodeValidator(v); err != nil { - return &ValidationError{Name: "device_code", err: fmt.Errorf(`ent: validator failed for field "DeviceFlow.device_code": %w`, err)} - } - } - if _, ok := dfc.mutation.UserCode(); !ok { - return &ValidationError{Name: "user_code", err: errors.New(`ent: missing required field "DeviceFlow.user_code"`)} - } - if v, ok := dfc.mutation.UserCode(); ok { - if err := deviceflow.UserCodeValidator(v); err != nil { - return &ValidationError{Name: "user_code", err: fmt.Errorf(`ent: validator failed for field "DeviceFlow.user_code": %w`, err)} - } - } - if _, ok := dfc.mutation.LastPoll(); !ok { - return &ValidationError{Name: "last_poll", err: errors.New(`ent: missing required field "DeviceFlow.last_poll"`)} - } - return nil -} - -func (dfc *DeviceFlowCreate) sqlSave(ctx context.Context) (*DeviceFlow, error) { - if err := dfc.check(); err != nil { - return nil, err - } - _node, _spec := dfc.createSpec() - if err := sqlgraph.CreateNode(ctx, dfc.driver, _spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - id := _spec.ID.Value.(int64) - _node.ID = int(id) - dfc.mutation.id = &_node.ID - dfc.mutation.done = true - return _node, nil -} - -func (dfc *DeviceFlowCreate) createSpec() (*DeviceFlow, *sqlgraph.CreateSpec) { - var ( - _node = &DeviceFlow{config: dfc.config} - _spec = sqlgraph.NewCreateSpec(deviceflow.Table, sqlgraph.NewFieldSpec(deviceflow.FieldID, field.TypeInt)) - ) - if value, ok := dfc.mutation.CreatedAt(); ok { - _spec.SetField(deviceflow.FieldCreatedAt, field.TypeTime, value) - _node.CreatedAt = value - } - if value, ok := dfc.mutation.Identifier(); ok { - _spec.SetField(deviceflow.FieldIdentifier, field.TypeString, value) - _node.Identifier = value - } - if value, ok := dfc.mutation.DeviceCode(); ok { - _spec.SetField(deviceflow.FieldDeviceCode, field.TypeString, value) - _node.DeviceCode = value - } - if value, ok := dfc.mutation.UserCode(); ok { - _spec.SetField(deviceflow.FieldUserCode, field.TypeString, value) - _node.UserCode = value - } - if value, ok := dfc.mutation.Session(); ok { - _spec.SetField(deviceflow.FieldSession, field.TypeString, value) - _node.Session = value - } - if value, ok := dfc.mutation.LastPoll(); ok { - _spec.SetField(deviceflow.FieldLastPoll, field.TypeTime, value) - _node.LastPoll = value - } - if value, ok := dfc.mutation.ExpiresAt(); ok { - _spec.SetField(deviceflow.FieldExpiresAt, field.TypeTime, value) - _node.ExpiresAt = value - } - return _node, _spec -} - -// DeviceFlowCreateBulk is the builder for creating many DeviceFlow entities in bulk. -type DeviceFlowCreateBulk struct { - config - builders []*DeviceFlowCreate -} - -// Save creates the DeviceFlow entities in the database. -func (dfcb *DeviceFlowCreateBulk) Save(ctx context.Context) ([]*DeviceFlow, error) { - specs := make([]*sqlgraph.CreateSpec, len(dfcb.builders)) - nodes := make([]*DeviceFlow, len(dfcb.builders)) - mutators := make([]Mutator, len(dfcb.builders)) - for i := range dfcb.builders { - func(i int, root context.Context) { - builder := dfcb.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DeviceFlowMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - var err error - nodes[i], specs[i] = builder.createSpec() - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, dfcb.builders[i+1].mutation) - } else { - spec := &sqlgraph.BatchCreateSpec{Nodes: specs} - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, dfcb.driver, spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - } - } - if err != nil { - return nil, err - } - mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) - } - mutation.done = true - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, dfcb.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (dfcb *DeviceFlowCreateBulk) SaveX(ctx context.Context) []*DeviceFlow { - v, err := dfcb.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (dfcb *DeviceFlowCreateBulk) Exec(ctx context.Context) error { - _, err := dfcb.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (dfcb *DeviceFlowCreateBulk) ExecX(ctx context.Context) { - if err := dfcb.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/internal/ent/deviceflow_delete.go b/internal/ent/deviceflow_delete.go deleted file mode 100644 index 6e5b25f..0000000 --- a/internal/ent/deviceflow_delete.go +++ /dev/null @@ -1,104 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/deviceflow" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// DeviceFlowDelete is the builder for deleting a DeviceFlow entity. -type DeviceFlowDelete struct { - config - hooks []Hook - mutation *DeviceFlowMutation -} - -// Where appends a list predicates to the DeviceFlowDelete builder. -func (dfd *DeviceFlowDelete) Where(ps ...predicate.DeviceFlow) *DeviceFlowDelete { - dfd.mutation.Where(ps...) - return dfd -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (dfd *DeviceFlowDelete) Exec(ctx context.Context) (int, error) { - return withHooks(ctx, dfd.sqlExec, dfd.mutation, dfd.hooks) -} - -// ExecX is like Exec, but panics if an error occurs. -func (dfd *DeviceFlowDelete) ExecX(ctx context.Context) int { - n, err := dfd.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (dfd *DeviceFlowDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(deviceflow.Table, sqlgraph.NewFieldSpec(deviceflow.FieldID, field.TypeInt)) - if ps := dfd.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - affected, err := sqlgraph.DeleteNodes(ctx, dfd.driver, _spec) - if err != nil && sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - dfd.mutation.done = true - return affected, err -} - -// DeviceFlowDeleteOne is the builder for deleting a single DeviceFlow entity. -type DeviceFlowDeleteOne struct { - dfd *DeviceFlowDelete -} - -// Where appends a list predicates to the DeviceFlowDelete builder. -func (dfdo *DeviceFlowDeleteOne) Where(ps ...predicate.DeviceFlow) *DeviceFlowDeleteOne { - dfdo.dfd.mutation.Where(ps...) - return dfdo -} - -// Exec executes the deletion query. -func (dfdo *DeviceFlowDeleteOne) Exec(ctx context.Context) error { - n, err := dfdo.dfd.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{deviceflow.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (dfdo *DeviceFlowDeleteOne) ExecX(ctx context.Context) { - if err := dfdo.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/internal/ent/deviceflow_query.go b/internal/ent/deviceflow_query.go deleted file mode 100644 index a9dc3a2..0000000 --- a/internal/ent/deviceflow_query.go +++ /dev/null @@ -1,542 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "math" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/deviceflow" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// DeviceFlowQuery is the builder for querying DeviceFlow entities. -type DeviceFlowQuery struct { - config - ctx *QueryContext - order []deviceflow.OrderOption - inters []Interceptor - predicates []predicate.DeviceFlow - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the DeviceFlowQuery builder. -func (dfq *DeviceFlowQuery) Where(ps ...predicate.DeviceFlow) *DeviceFlowQuery { - dfq.predicates = append(dfq.predicates, ps...) - return dfq -} - -// Limit the number of records to be returned by this query. -func (dfq *DeviceFlowQuery) Limit(limit int) *DeviceFlowQuery { - dfq.ctx.Limit = &limit - return dfq -} - -// Offset to start from. -func (dfq *DeviceFlowQuery) Offset(offset int) *DeviceFlowQuery { - dfq.ctx.Offset = &offset - return dfq -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (dfq *DeviceFlowQuery) Unique(unique bool) *DeviceFlowQuery { - dfq.ctx.Unique = &unique - return dfq -} - -// Order specifies how the records should be ordered. -func (dfq *DeviceFlowQuery) Order(o ...deviceflow.OrderOption) *DeviceFlowQuery { - dfq.order = append(dfq.order, o...) - return dfq -} - -// First returns the first DeviceFlow entity from the query. -// Returns a *NotFoundError when no DeviceFlow was found. -func (dfq *DeviceFlowQuery) First(ctx context.Context) (*DeviceFlow, error) { - nodes, err := dfq.Limit(1).All(setContextOp(ctx, dfq.ctx, "First")) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{deviceflow.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (dfq *DeviceFlowQuery) FirstX(ctx context.Context) *DeviceFlow { - node, err := dfq.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first DeviceFlow ID from the query. -// Returns a *NotFoundError when no DeviceFlow ID was found. -func (dfq *DeviceFlowQuery) FirstID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = dfq.Limit(1).IDs(setContextOp(ctx, dfq.ctx, "FirstID")); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{deviceflow.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (dfq *DeviceFlowQuery) FirstIDX(ctx context.Context) int { - id, err := dfq.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single DeviceFlow entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one DeviceFlow entity is found. -// Returns a *NotFoundError when no DeviceFlow entities are found. -func (dfq *DeviceFlowQuery) Only(ctx context.Context) (*DeviceFlow, error) { - nodes, err := dfq.Limit(2).All(setContextOp(ctx, dfq.ctx, "Only")) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{deviceflow.Label} - default: - return nil, &NotSingularError{deviceflow.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (dfq *DeviceFlowQuery) OnlyX(ctx context.Context) *DeviceFlow { - node, err := dfq.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only DeviceFlow ID in the query. -// Returns a *NotSingularError when more than one DeviceFlow ID is found. -// Returns a *NotFoundError when no entities are found. -func (dfq *DeviceFlowQuery) OnlyID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = dfq.Limit(2).IDs(setContextOp(ctx, dfq.ctx, "OnlyID")); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{deviceflow.Label} - default: - err = &NotSingularError{deviceflow.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (dfq *DeviceFlowQuery) OnlyIDX(ctx context.Context) int { - id, err := dfq.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of DeviceFlows. -func (dfq *DeviceFlowQuery) All(ctx context.Context) ([]*DeviceFlow, error) { - ctx = setContextOp(ctx, dfq.ctx, "All") - if err := dfq.prepareQuery(ctx); err != nil { - return nil, err - } - qr := querierAll[[]*DeviceFlow, *DeviceFlowQuery]() - return withInterceptors[[]*DeviceFlow](ctx, dfq, qr, dfq.inters) -} - -// AllX is like All, but panics if an error occurs. -func (dfq *DeviceFlowQuery) AllX(ctx context.Context) []*DeviceFlow { - nodes, err := dfq.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of DeviceFlow IDs. -func (dfq *DeviceFlowQuery) IDs(ctx context.Context) (ids []int, err error) { - if dfq.ctx.Unique == nil && dfq.path != nil { - dfq.Unique(true) - } - ctx = setContextOp(ctx, dfq.ctx, "IDs") - if err = dfq.Select(deviceflow.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (dfq *DeviceFlowQuery) IDsX(ctx context.Context) []int { - ids, err := dfq.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (dfq *DeviceFlowQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, dfq.ctx, "Count") - if err := dfq.prepareQuery(ctx); err != nil { - return 0, err - } - return withInterceptors[int](ctx, dfq, querierCount[*DeviceFlowQuery](), dfq.inters) -} - -// CountX is like Count, but panics if an error occurs. -func (dfq *DeviceFlowQuery) CountX(ctx context.Context) int { - count, err := dfq.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (dfq *DeviceFlowQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, dfq.ctx, "Exist") - switch _, err := dfq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - -// ExistX is like Exist, but panics if an error occurs. -func (dfq *DeviceFlowQuery) ExistX(ctx context.Context) bool { - exist, err := dfq.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the DeviceFlowQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (dfq *DeviceFlowQuery) Clone() *DeviceFlowQuery { - if dfq == nil { - return nil - } - return &DeviceFlowQuery{ - config: dfq.config, - ctx: dfq.ctx.Clone(), - order: append([]deviceflow.OrderOption{}, dfq.order...), - inters: append([]Interceptor{}, dfq.inters...), - predicates: append([]predicate.DeviceFlow{}, dfq.predicates...), - // clone intermediate query. - sql: dfq.sql.Clone(), - path: dfq.path, - } -} - -// 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: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.DeviceFlow.Query(). -// GroupBy(deviceflow.FieldCreatedAt). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -func (dfq *DeviceFlowQuery) GroupBy(field string, fields ...string) *DeviceFlowGroupBy { - dfq.ctx.Fields = append([]string{field}, fields...) - grbuild := &DeviceFlowGroupBy{build: dfq} - grbuild.flds = &dfq.ctx.Fields - grbuild.label = deviceflow.Label - grbuild.scan = grbuild.Scan - return grbuild -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// } -// -// client.DeviceFlow.Query(). -// Select(deviceflow.FieldCreatedAt). -// Scan(ctx, &v) -func (dfq *DeviceFlowQuery) Select(fields ...string) *DeviceFlowSelect { - dfq.ctx.Fields = append(dfq.ctx.Fields, fields...) - sbuild := &DeviceFlowSelect{DeviceFlowQuery: dfq} - sbuild.label = deviceflow.Label - sbuild.flds, sbuild.scan = &dfq.ctx.Fields, sbuild.Scan - return sbuild -} - -// Aggregate returns a DeviceFlowSelect configured with the given aggregations. -func (dfq *DeviceFlowQuery) Aggregate(fns ...AggregateFunc) *DeviceFlowSelect { - return dfq.Select().Aggregate(fns...) -} - -func (dfq *DeviceFlowQuery) prepareQuery(ctx context.Context) error { - for _, inter := range dfq.inters { - if inter == nil { - return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") - } - if trv, ok := inter.(Traverser); ok { - if err := trv.Traverse(ctx, dfq); err != nil { - return err - } - } - } - for _, f := range dfq.ctx.Fields { - if !deviceflow.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if dfq.path != nil { - prev, err := dfq.path(ctx) - if err != nil { - return err - } - dfq.sql = prev - } - return nil -} - -func (dfq *DeviceFlowQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*DeviceFlow, error) { - var ( - nodes = []*DeviceFlow{} - _spec = dfq.querySpec() - ) - _spec.ScanValues = func(columns []string) ([]any, error) { - return (*DeviceFlow).scanValues(nil, columns) - } - _spec.Assign = func(columns []string, values []any) error { - node := &DeviceFlow{config: dfq.config} - nodes = append(nodes, node) - return node.assignValues(columns, values) - } - for i := range hooks { - hooks[i](ctx, _spec) - } - if err := sqlgraph.QueryNodes(ctx, dfq.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - return nodes, nil -} - -func (dfq *DeviceFlowQuery) sqlCount(ctx context.Context) (int, error) { - _spec := dfq.querySpec() - _spec.Node.Columns = dfq.ctx.Fields - if len(dfq.ctx.Fields) > 0 { - _spec.Unique = dfq.ctx.Unique != nil && *dfq.ctx.Unique - } - return sqlgraph.CountNodes(ctx, dfq.driver, _spec) -} - -func (dfq *DeviceFlowQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(deviceflow.Table, deviceflow.Columns, sqlgraph.NewFieldSpec(deviceflow.FieldID, field.TypeInt)) - _spec.From = dfq.sql - if unique := dfq.ctx.Unique; unique != nil { - _spec.Unique = *unique - } else if dfq.path != nil { - _spec.Unique = true - } - if fields := dfq.ctx.Fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, deviceflow.FieldID) - for i := range fields { - if fields[i] != deviceflow.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := dfq.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := dfq.ctx.Limit; limit != nil { - _spec.Limit = *limit - } - if offset := dfq.ctx.Offset; offset != nil { - _spec.Offset = *offset - } - if ps := dfq.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (dfq *DeviceFlowQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(dfq.driver.Dialect()) - t1 := builder.Table(deviceflow.Table) - columns := dfq.ctx.Fields - if len(columns) == 0 { - columns = deviceflow.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if dfq.sql != nil { - selector = dfq.sql - selector.Select(selector.Columns(columns...)...) - } - if dfq.ctx.Unique != nil && *dfq.ctx.Unique { - selector.Distinct() - } - for _, p := range dfq.predicates { - p(selector) - } - for _, p := range dfq.order { - p(selector) - } - if offset := dfq.ctx.Offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := dfq.ctx.Limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// DeviceFlowGroupBy is the group-by builder for DeviceFlow entities. -type DeviceFlowGroupBy struct { - selector - build *DeviceFlowQuery -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (dfgb *DeviceFlowGroupBy) Aggregate(fns ...AggregateFunc) *DeviceFlowGroupBy { - dfgb.fns = append(dfgb.fns, fns...) - return dfgb -} - -// Scan applies the selector query and scans the result into the given value. -func (dfgb *DeviceFlowGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, dfgb.build.ctx, "GroupBy") - if err := dfgb.build.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*DeviceFlowQuery, *DeviceFlowGroupBy](ctx, dfgb.build, dfgb, dfgb.build.inters, v) -} - -func (dfgb *DeviceFlowGroupBy) sqlScan(ctx context.Context, root *DeviceFlowQuery, v any) error { - selector := root.sqlQuery(ctx).Select() - aggregation := make([]string, 0, len(dfgb.fns)) - for _, fn := range dfgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(*dfgb.flds)+len(dfgb.fns)) - for _, f := range *dfgb.flds { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - selector.GroupBy(selector.Columns(*dfgb.flds...)...) - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := dfgb.build.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -// DeviceFlowSelect is the builder for selecting fields of DeviceFlow entities. -type DeviceFlowSelect struct { - *DeviceFlowQuery - selector -} - -// Aggregate adds the given aggregation functions to the selector query. -func (dfs *DeviceFlowSelect) Aggregate(fns ...AggregateFunc) *DeviceFlowSelect { - dfs.fns = append(dfs.fns, fns...) - return dfs -} - -// Scan applies the selector query and scans the result into the given value. -func (dfs *DeviceFlowSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, dfs.ctx, "Select") - if err := dfs.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*DeviceFlowQuery, *DeviceFlowSelect](ctx, dfs.DeviceFlowQuery, dfs, dfs.inters, v) -} - -func (dfs *DeviceFlowSelect) sqlScan(ctx context.Context, root *DeviceFlowQuery, v any) error { - selector := root.sqlQuery(ctx) - aggregation := make([]string, 0, len(dfs.fns)) - for _, fn := range dfs.fns { - aggregation = append(aggregation, fn(selector)) - } - switch n := len(*dfs.selector.flds); { - case n == 0 && len(aggregation) > 0: - selector.Select(aggregation...) - case n != 0 && len(aggregation) > 0: - selector.AppendSelect(aggregation...) - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := dfs.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/internal/ent/deviceflow_update.go b/internal/ent/deviceflow_update.go deleted file mode 100644 index 2a1823a..0000000 --- a/internal/ent/deviceflow_update.go +++ /dev/null @@ -1,330 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/deviceflow" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// DeviceFlowUpdate is the builder for updating DeviceFlow entities. -type DeviceFlowUpdate struct { - config - hooks []Hook - mutation *DeviceFlowMutation -} - -// Where appends a list predicates to the DeviceFlowUpdate builder. -func (dfu *DeviceFlowUpdate) Where(ps ...predicate.DeviceFlow) *DeviceFlowUpdate { - dfu.mutation.Where(ps...) - return dfu -} - -// SetSession sets the "session" field. -func (dfu *DeviceFlowUpdate) SetSession(s string) *DeviceFlowUpdate { - dfu.mutation.SetSession(s) - return dfu -} - -// SetNillableSession sets the "session" field if the given value is not nil. -func (dfu *DeviceFlowUpdate) SetNillableSession(s *string) *DeviceFlowUpdate { - if s != nil { - dfu.SetSession(*s) - } - return dfu -} - -// ClearSession clears the value of the "session" field. -func (dfu *DeviceFlowUpdate) ClearSession() *DeviceFlowUpdate { - dfu.mutation.ClearSession() - return dfu -} - -// SetLastPoll sets the "last_poll" field. -func (dfu *DeviceFlowUpdate) SetLastPoll(t time.Time) *DeviceFlowUpdate { - dfu.mutation.SetLastPoll(t) - return dfu -} - -// SetNillableLastPoll sets the "last_poll" field if the given value is not nil. -func (dfu *DeviceFlowUpdate) SetNillableLastPoll(t *time.Time) *DeviceFlowUpdate { - if t != nil { - dfu.SetLastPoll(*t) - } - return dfu -} - -// SetExpiresAt sets the "expires_at" field. -func (dfu *DeviceFlowUpdate) SetExpiresAt(t time.Time) *DeviceFlowUpdate { - dfu.mutation.SetExpiresAt(t) - return dfu -} - -// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil. -func (dfu *DeviceFlowUpdate) SetNillableExpiresAt(t *time.Time) *DeviceFlowUpdate { - if t != nil { - dfu.SetExpiresAt(*t) - } - return dfu -} - -// ClearExpiresAt clears the value of the "expires_at" field. -func (dfu *DeviceFlowUpdate) ClearExpiresAt() *DeviceFlowUpdate { - dfu.mutation.ClearExpiresAt() - return dfu -} - -// Mutation returns the DeviceFlowMutation object of the builder. -func (dfu *DeviceFlowUpdate) Mutation() *DeviceFlowMutation { - return dfu.mutation -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (dfu *DeviceFlowUpdate) Save(ctx context.Context) (int, error) { - return withHooks(ctx, dfu.sqlSave, dfu.mutation, dfu.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (dfu *DeviceFlowUpdate) SaveX(ctx context.Context) int { - affected, err := dfu.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (dfu *DeviceFlowUpdate) Exec(ctx context.Context) error { - _, err := dfu.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (dfu *DeviceFlowUpdate) ExecX(ctx context.Context) { - if err := dfu.Exec(ctx); err != nil { - panic(err) - } -} - -func (dfu *DeviceFlowUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := sqlgraph.NewUpdateSpec(deviceflow.Table, deviceflow.Columns, sqlgraph.NewFieldSpec(deviceflow.FieldID, field.TypeInt)) - if ps := dfu.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := dfu.mutation.Session(); ok { - _spec.SetField(deviceflow.FieldSession, field.TypeString, value) - } - if dfu.mutation.SessionCleared() { - _spec.ClearField(deviceflow.FieldSession, field.TypeString) - } - if value, ok := dfu.mutation.LastPoll(); ok { - _spec.SetField(deviceflow.FieldLastPoll, field.TypeTime, value) - } - if value, ok := dfu.mutation.ExpiresAt(); ok { - _spec.SetField(deviceflow.FieldExpiresAt, field.TypeTime, value) - } - if dfu.mutation.ExpiresAtCleared() { - _spec.ClearField(deviceflow.FieldExpiresAt, field.TypeTime) - } - if n, err = sqlgraph.UpdateNodes(ctx, dfu.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{deviceflow.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - dfu.mutation.done = true - return n, nil -} - -// DeviceFlowUpdateOne is the builder for updating a single DeviceFlow entity. -type DeviceFlowUpdateOne struct { - config - fields []string - hooks []Hook - mutation *DeviceFlowMutation -} - -// SetSession sets the "session" field. -func (dfuo *DeviceFlowUpdateOne) SetSession(s string) *DeviceFlowUpdateOne { - dfuo.mutation.SetSession(s) - return dfuo -} - -// SetNillableSession sets the "session" field if the given value is not nil. -func (dfuo *DeviceFlowUpdateOne) SetNillableSession(s *string) *DeviceFlowUpdateOne { - if s != nil { - dfuo.SetSession(*s) - } - return dfuo -} - -// ClearSession clears the value of the "session" field. -func (dfuo *DeviceFlowUpdateOne) ClearSession() *DeviceFlowUpdateOne { - dfuo.mutation.ClearSession() - return dfuo -} - -// SetLastPoll sets the "last_poll" field. -func (dfuo *DeviceFlowUpdateOne) SetLastPoll(t time.Time) *DeviceFlowUpdateOne { - dfuo.mutation.SetLastPoll(t) - return dfuo -} - -// SetNillableLastPoll sets the "last_poll" field if the given value is not nil. -func (dfuo *DeviceFlowUpdateOne) SetNillableLastPoll(t *time.Time) *DeviceFlowUpdateOne { - if t != nil { - dfuo.SetLastPoll(*t) - } - return dfuo -} - -// SetExpiresAt sets the "expires_at" field. -func (dfuo *DeviceFlowUpdateOne) SetExpiresAt(t time.Time) *DeviceFlowUpdateOne { - dfuo.mutation.SetExpiresAt(t) - return dfuo -} - -// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil. -func (dfuo *DeviceFlowUpdateOne) SetNillableExpiresAt(t *time.Time) *DeviceFlowUpdateOne { - if t != nil { - dfuo.SetExpiresAt(*t) - } - return dfuo -} - -// ClearExpiresAt clears the value of the "expires_at" field. -func (dfuo *DeviceFlowUpdateOne) ClearExpiresAt() *DeviceFlowUpdateOne { - dfuo.mutation.ClearExpiresAt() - return dfuo -} - -// Mutation returns the DeviceFlowMutation object of the builder. -func (dfuo *DeviceFlowUpdateOne) Mutation() *DeviceFlowMutation { - return dfuo.mutation -} - -// Where appends a list predicates to the DeviceFlowUpdate builder. -func (dfuo *DeviceFlowUpdateOne) Where(ps ...predicate.DeviceFlow) *DeviceFlowUpdateOne { - dfuo.mutation.Where(ps...) - return dfuo -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (dfuo *DeviceFlowUpdateOne) Select(field string, fields ...string) *DeviceFlowUpdateOne { - dfuo.fields = append([]string{field}, fields...) - return dfuo -} - -// Save executes the query and returns the updated DeviceFlow entity. -func (dfuo *DeviceFlowUpdateOne) Save(ctx context.Context) (*DeviceFlow, error) { - return withHooks(ctx, dfuo.sqlSave, dfuo.mutation, dfuo.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (dfuo *DeviceFlowUpdateOne) SaveX(ctx context.Context) *DeviceFlow { - node, err := dfuo.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (dfuo *DeviceFlowUpdateOne) Exec(ctx context.Context) error { - _, err := dfuo.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (dfuo *DeviceFlowUpdateOne) ExecX(ctx context.Context) { - if err := dfuo.Exec(ctx); err != nil { - panic(err) - } -} - -func (dfuo *DeviceFlowUpdateOne) sqlSave(ctx context.Context) (_node *DeviceFlow, err error) { - _spec := sqlgraph.NewUpdateSpec(deviceflow.Table, deviceflow.Columns, sqlgraph.NewFieldSpec(deviceflow.FieldID, field.TypeInt)) - id, ok := dfuo.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "DeviceFlow.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := dfuo.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, deviceflow.FieldID) - for _, f := range fields { - if !deviceflow.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != deviceflow.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := dfuo.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := dfuo.mutation.Session(); ok { - _spec.SetField(deviceflow.FieldSession, field.TypeString, value) - } - if dfuo.mutation.SessionCleared() { - _spec.ClearField(deviceflow.FieldSession, field.TypeString) - } - if value, ok := dfuo.mutation.LastPoll(); ok { - _spec.SetField(deviceflow.FieldLastPoll, field.TypeTime, value) - } - if value, ok := dfuo.mutation.ExpiresAt(); ok { - _spec.SetField(deviceflow.FieldExpiresAt, field.TypeTime, value) - } - if dfuo.mutation.ExpiresAtCleared() { - _spec.ClearField(deviceflow.FieldExpiresAt, field.TypeTime) - } - _node = &DeviceFlow{config: dfuo.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, dfuo.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{deviceflow.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - dfuo.mutation.done = true - return _node, nil -} diff --git a/internal/ent/ent.go b/internal/ent/ent.go deleted file mode 100644 index c8546d4..0000000 --- a/internal/ent/ent.go +++ /dev/null @@ -1,630 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "reflect" - "sync" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "github.com/loopholelabs/auth/internal/ent/deviceflow" - "github.com/loopholelabs/auth/internal/ent/githubflow" - "github.com/loopholelabs/auth/internal/ent/googleflow" - "github.com/loopholelabs/auth/internal/ent/magicflow" -) - -// ent aliases to avoid import conflicts in user's code. -type ( - Op = ent.Op - Hook = ent.Hook - Value = ent.Value - Query = ent.Query - QueryContext = ent.QueryContext - Querier = ent.Querier - QuerierFunc = ent.QuerierFunc - Interceptor = ent.Interceptor - InterceptFunc = ent.InterceptFunc - Traverser = ent.Traverser - TraverseFunc = ent.TraverseFunc - Policy = ent.Policy - Mutator = ent.Mutator - Mutation = ent.Mutation - MutateFunc = ent.MutateFunc -) - -type clientCtxKey struct{} - -// 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 -} - -// NewContext returns a new context with the given Client attached. -func NewContext(parent context.Context, c *Client) context.Context { - return context.WithValue(parent, clientCtxKey{}, c) -} - -type txCtxKey struct{} - -// 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 Tx attached. -func NewTxContext(parent context.Context, tx *Tx) context.Context { - return context.WithValue(parent, txCtxKey{}, tx) -} - -// OrderFunc applies an ordering on the sql selector. -// Deprecated: Use Asc/Desc functions or the package builders instead. -type OrderFunc func(*sql.Selector) - -var ( - initCheck sync.Once - columnCheck sql.ColumnCheck -) - -// columnChecker checks if the column exists in the given table. -func checkColumn(table, column string) error { - initCheck.Do(func() { - columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ - deviceflow.Table: deviceflow.ValidColumn, - githubflow.Table: githubflow.ValidColumn, - googleflow.Table: googleflow.ValidColumn, - magicflow.Table: magicflow.ValidColumn, - }) - }) - return columnCheck(table, column) -} - -// Asc applies the given fields in ASC order. -func Asc(fields ...string) func(*sql.Selector) { - return func(s *sql.Selector) { - for _, f := range fields { - if err := checkColumn(s.TableName(), f); err != nil { - s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) - } - s.OrderBy(sql.Asc(s.C(f))) - } - } -} - -// Desc applies the given fields in DESC order. -func Desc(fields ...string) func(*sql.Selector) { - return func(s *sql.Selector) { - for _, f := range fields { - if err := checkColumn(s.TableName(), f); err != nil { - s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) - } - s.OrderBy(sql.Desc(s.C(f))) - } - } -} - -// AggregateFunc applies an aggregation step on the group-by traversal/selector. -type AggregateFunc func(*sql.Selector) string - -// As is a pseudo aggregation function for renaming another other functions with custom names. For example: -// -// GroupBy(field1, field2). -// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")). -// Scan(ctx, &v) -func As(fn AggregateFunc, end string) AggregateFunc { - return func(s *sql.Selector) string { - return sql.As(fn(s), end) - } -} - -// Count applies the "count" aggregation function on each group. -func Count() AggregateFunc { - return func(s *sql.Selector) string { - return sql.Count("*") - } -} - -// Max applies the "max" aggregation function on the given field of each group. -func Max(field string) AggregateFunc { - return func(s *sql.Selector) string { - if err := checkColumn(s.TableName(), field); err != nil { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) - return "" - } - return sql.Max(s.C(field)) - } -} - -// Mean applies the "mean" aggregation function on the given field of each group. -func Mean(field string) AggregateFunc { - return func(s *sql.Selector) string { - if err := checkColumn(s.TableName(), field); err != nil { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) - return "" - } - return sql.Avg(s.C(field)) - } -} - -// Min applies the "min" aggregation function on the given field of each group. -func Min(field string) AggregateFunc { - return func(s *sql.Selector) string { - if err := checkColumn(s.TableName(), field); err != nil { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) - return "" - } - return sql.Min(s.C(field)) - } -} - -// Sum applies the "sum" aggregation function on the given field of each group. -func Sum(field string) AggregateFunc { - return func(s *sql.Selector) string { - if err := checkColumn(s.TableName(), field); err != nil { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) - return "" - } - return sql.Sum(s.C(field)) - } -} - -// ValidationError returns when validating a field or edge fails. -type ValidationError struct { - Name string // Field or edge name. - err error -} - -// Error implements the error interface. -func (e *ValidationError) Error() string { - return e.err.Error() -} - -// Unwrap implements the errors.Wrapper interface. -func (e *ValidationError) Unwrap() error { - return e.err -} - -// IsValidationError returns a boolean indicating whether the error is a validation error. -func IsValidationError(err error) bool { - if err == nil { - return false - } - var e *ValidationError - return errors.As(err, &e) -} - -// NotFoundError returns when trying to fetch a specific entity and it was not found in the database. -type NotFoundError struct { - label string -} - -// Error implements the error interface. -func (e *NotFoundError) Error() string { - return "ent: " + e.label + " not found" -} - -// IsNotFound returns a boolean indicating whether the error is a not found error. -func IsNotFound(err error) bool { - if err == nil { - return false - } - var e *NotFoundError - return errors.As(err, &e) -} - -// MaskNotFound masks not found error. -func MaskNotFound(err error) error { - if IsNotFound(err) { - return nil - } - return err -} - -// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database. -type NotSingularError struct { - label string -} - -// Error implements the error interface. -func (e *NotSingularError) Error() string { - return "ent: " + e.label + " not singular" -} - -// IsNotSingular returns a boolean indicating whether the error is a not singular error. -func IsNotSingular(err error) bool { - if err == nil { - return false - } - var e *NotSingularError - return errors.As(err, &e) -} - -// NotLoadedError returns when trying to get a node that was not loaded by the query. -type NotLoadedError struct { - edge string -} - -// Error implements the error interface. -func (e *NotLoadedError) Error() string { - return "ent: " + e.edge + " edge was not loaded" -} - -// IsNotLoaded returns a boolean indicating whether the error is a not loaded error. -func IsNotLoaded(err error) bool { - if err == nil { - return false - } - var e *NotLoadedError - return errors.As(err, &e) -} - -// ConstraintError returns when trying to create/update one or more entities and -// one or more of their constraints failed. For example, violation of edge or -// field uniqueness. -type ConstraintError struct { - msg string - wrap error -} - -// Error implements the error interface. -func (e ConstraintError) Error() string { - return "ent: constraint failed: " + e.msg -} - -// Unwrap implements the errors.Wrapper interface. -func (e *ConstraintError) Unwrap() error { - return e.wrap -} - -// IsConstraintError returns a boolean indicating whether the error is a constraint failure. -func IsConstraintError(err error) bool { - if err == nil { - return false - } - var e *ConstraintError - return errors.As(err, &e) -} - -// selector embedded by the different Select/GroupBy builders. -type selector struct { - label string - flds *[]string - fns []AggregateFunc - scan func(context.Context, any) error -} - -// ScanX is like Scan, but panics if an error occurs. -func (s *selector) ScanX(ctx context.Context, v any) { - if err := s.scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from a selector. It is only allowed when selecting one field. -func (s *selector) Strings(ctx context.Context) ([]string, error) { - if len(*s.flds) > 1 { - return nil, errors.New("ent: Strings is not achievable when selecting more than 1 field") - } - var v []string - if err := s.scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (s *selector) StringsX(ctx context.Context) []string { - v, err := s.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a selector. It is only allowed when selecting one field. -func (s *selector) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = s.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{s.label} - default: - err = fmt.Errorf("ent: Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (s *selector) StringX(ctx context.Context) string { - v, err := s.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from a selector. It is only allowed when selecting one field. -func (s *selector) Ints(ctx context.Context) ([]int, error) { - if len(*s.flds) > 1 { - return nil, errors.New("ent: Ints is not achievable when selecting more than 1 field") - } - var v []int - if err := s.scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (s *selector) IntsX(ctx context.Context) []int { - v, err := s.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a selector. It is only allowed when selecting one field. -func (s *selector) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = s.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{s.label} - default: - err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (s *selector) IntX(ctx context.Context) int { - v, err := s.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. -func (s *selector) Float64s(ctx context.Context) ([]float64, error) { - if len(*s.flds) > 1 { - return nil, errors.New("ent: Float64s is not achievable when selecting more than 1 field") - } - var v []float64 - if err := s.scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (s *selector) Float64sX(ctx context.Context) []float64 { - v, err := s.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. -func (s *selector) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = s.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{s.label} - default: - err = fmt.Errorf("ent: Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (s *selector) Float64X(ctx context.Context) float64 { - v, err := s.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from a selector. It is only allowed when selecting one field. -func (s *selector) Bools(ctx context.Context) ([]bool, error) { - if len(*s.flds) > 1 { - return nil, errors.New("ent: Bools is not achievable when selecting more than 1 field") - } - var v []bool - if err := s.scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (s *selector) BoolsX(ctx context.Context) []bool { - v, err := s.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a selector. It is only allowed when selecting one field. -func (s *selector) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = s.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{s.label} - default: - err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (s *selector) BoolX(ctx context.Context) bool { - v, err := s.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -// withHooks invokes the builder operation with the given hooks, if any. -func withHooks[V Value, M any, PM interface { - *M - Mutation -}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) { - if len(hooks) == 0 { - return exec(ctx) - } - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutationT, ok := any(m).(PM) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - // Set the mutation to the builder. - *mutation = *mutationT - return exec(ctx) - }) - for i := len(hooks) - 1; i >= 0; i-- { - if hooks[i] == nil { - return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = hooks[i](mut) - } - v, err := mut.Mutate(ctx, mutation) - if err != nil { - return value, err - } - nv, ok := v.(V) - if !ok { - return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation) - } - return nv, nil -} - -// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist. -func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context { - if ent.QueryFromContext(ctx) == nil { - qc.Op = op - ctx = ent.NewQueryContext(ctx, qc) - } - return ctx -} - -func querierAll[V Value, Q interface { - sqlAll(context.Context, ...queryHook) (V, error) -}]() Querier { - return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { - query, ok := q.(Q) - if !ok { - return nil, fmt.Errorf("unexpected query type %T", q) - } - return query.sqlAll(ctx) - }) -} - -func querierCount[Q interface { - sqlCount(context.Context) (int, error) -}]() Querier { - return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { - query, ok := q.(Q) - if !ok { - return nil, fmt.Errorf("unexpected query type %T", q) - } - return query.sqlCount(ctx) - }) -} - -func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) { - for i := len(inters) - 1; i >= 0; i-- { - qr = inters[i].Intercept(qr) - } - rv, err := qr.Query(ctx, q) - if err != nil { - return v, err - } - vt, ok := rv.(V) - if !ok { - return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v) - } - return vt, nil -} - -func scanWithInterceptors[Q1 ent.Query, Q2 interface { - sqlScan(context.Context, Q1, any) error -}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error { - rv := reflect.ValueOf(v) - var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) { - query, ok := q.(Q1) - if !ok { - return nil, fmt.Errorf("unexpected query type %T", q) - } - if err := selectOrGroup.sqlScan(ctx, query, v); err != nil { - return nil, err - } - if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() { - return rv.Elem().Interface(), nil - } - return v, nil - }) - for i := len(inters) - 1; i >= 0; i-- { - qr = inters[i].Intercept(qr) - } - vv, err := qr.Query(ctx, rootQuery) - if err != nil { - return err - } - switch rv2 := reflect.ValueOf(vv); { - case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer: - case rv.Type() == rv2.Type(): - rv.Elem().Set(rv2.Elem()) - case rv.Elem().Type() == rv2.Type(): - rv.Elem().Set(rv2) - } - return nil -} - -// queryHook describes an internal hook for the different sqlAll methods. -type queryHook func(context.Context, *sqlgraph.QuerySpec) diff --git a/internal/ent/enttest/enttest.go b/internal/ent/enttest/enttest.go deleted file mode 100644 index cdaefba..0000000 --- a/internal/ent/enttest/enttest.go +++ /dev/null @@ -1,100 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package enttest - -import ( - "context" - - "github.com/loopholelabs/auth/internal/ent" - // required by schema hooks. - _ "github.com/loopholelabs/auth/internal/ent/runtime" - - "entgo.io/ent/dialect/sql/schema" - "github.com/loopholelabs/auth/internal/ent/migrate" -) - -type ( - // TestingT is the interface that is shared between - // testing.T and testing.B and used by enttest. - TestingT interface { - FailNow() - Error(...any) - } - - // Option configures client creation. - Option func(*options) - - options struct { - opts []ent.Option - migrateOpts []schema.MigrateOption - } -) - -// WithOptions forwards options to client creation. -func WithOptions(opts ...ent.Option) Option { - return func(o *options) { - o.opts = append(o.opts, opts...) - } -} - -// WithMigrateOptions forwards options to auto migration. -func WithMigrateOptions(opts ...schema.MigrateOption) Option { - return func(o *options) { - o.migrateOpts = append(o.migrateOpts, opts...) - } -} - -func newOptions(opts []Option) *options { - o := &options{} - for _, opt := range opts { - opt(o) - } - return o -} - -// Open calls ent.Open and auto-run migration. -func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client { - o := newOptions(opts) - c, err := ent.Open(driverName, dataSourceName, o.opts...) - if err != nil { - t.Error(err) - t.FailNow() - } - migrateSchema(t, c, o) - return c -} - -// NewClient calls ent.NewClient and auto-run migration. -func NewClient(t TestingT, opts ...Option) *ent.Client { - o := newOptions(opts) - c := ent.NewClient(o.opts...) - migrateSchema(t, c, o) - return c -} -func migrateSchema(t TestingT, c *ent.Client, o *options) { - tables, err := schema.CopyTables(migrate.Tables) - if err != nil { - t.Error(err) - t.FailNow() - } - if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil { - t.Error(err) - t.FailNow() - } -} diff --git a/internal/ent/generate.go b/internal/ent/generate.go deleted file mode 100644 index 8d71690..0000000 --- a/internal/ent/generate.go +++ /dev/null @@ -1,19 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package ent - -//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate ./schema diff --git a/internal/ent/githubflow.go b/internal/ent/githubflow.go deleted file mode 100644 index a58edac..0000000 --- a/internal/ent/githubflow.go +++ /dev/null @@ -1,188 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "github.com/loopholelabs/auth/internal/ent/githubflow" -) - -// GithubFlow is the model entity for the GithubFlow schema. -type GithubFlow struct { - config `json:"-"` - // ID of the ent. - ID int `json:"id,omitempty"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at,omitempty"` - // Identifier holds the value of the "identifier" field. - Identifier string `json:"identifier,omitempty"` - // Verifier holds the value of the "verifier" field. - Verifier string `json:"verifier,omitempty"` - // Challenge holds the value of the "challenge" field. - Challenge string `json:"challenge,omitempty"` - // NextURL holds the value of the "next_url" field. - NextURL string `json:"next_url,omitempty"` - // Organization holds the value of the "organization" field. - Organization string `json:"organization,omitempty"` - // DeviceIdentifier holds the value of the "device_identifier" field. - DeviceIdentifier string `json:"device_identifier,omitempty"` - selectValues sql.SelectValues -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*GithubFlow) scanValues(columns []string) ([]any, error) { - values := make([]any, len(columns)) - for i := range columns { - switch columns[i] { - case githubflow.FieldID: - values[i] = new(sql.NullInt64) - case githubflow.FieldIdentifier, githubflow.FieldVerifier, githubflow.FieldChallenge, githubflow.FieldNextURL, githubflow.FieldOrganization, githubflow.FieldDeviceIdentifier: - values[i] = new(sql.NullString) - case githubflow.FieldCreatedAt: - values[i] = new(sql.NullTime) - default: - values[i] = new(sql.UnknownType) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the GithubFlow fields. -func (gf *GithubFlow) assignValues(columns []string, values []any) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case githubflow.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - gf.ID = int(value.Int64) - case githubflow.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 { - gf.CreatedAt = value.Time - } - case githubflow.FieldIdentifier: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field identifier", values[i]) - } else if value.Valid { - gf.Identifier = value.String - } - case githubflow.FieldVerifier: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field verifier", values[i]) - } else if value.Valid { - gf.Verifier = value.String - } - case githubflow.FieldChallenge: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field challenge", values[i]) - } else if value.Valid { - gf.Challenge = value.String - } - case githubflow.FieldNextURL: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field next_url", values[i]) - } else if value.Valid { - gf.NextURL = value.String - } - case githubflow.FieldOrganization: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field organization", values[i]) - } else if value.Valid { - gf.Organization = value.String - } - case githubflow.FieldDeviceIdentifier: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field device_identifier", values[i]) - } else if value.Valid { - gf.DeviceIdentifier = value.String - } - default: - gf.selectValues.Set(columns[i], values[i]) - } - } - return nil -} - -// Value returns the ent.Value that was dynamically selected and assigned to the GithubFlow. -// This includes values selected through modifiers, order, etc. -func (gf *GithubFlow) Value(name string) (ent.Value, error) { - return gf.selectValues.Get(name) -} - -// Update returns a builder for updating this GithubFlow. -// Note that you need to call GithubFlow.Unwrap() before calling this method if this GithubFlow -// was returned from a transaction, and the transaction was committed or rolled back. -func (gf *GithubFlow) Update() *GithubFlowUpdateOne { - return NewGithubFlowClient(gf.config).UpdateOne(gf) -} - -// Unwrap unwraps the GithubFlow 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 (gf *GithubFlow) Unwrap() *GithubFlow { - _tx, ok := gf.config.driver.(*txDriver) - if !ok { - panic("ent: GithubFlow is not a transactional entity") - } - gf.config.driver = _tx.drv - return gf -} - -// String implements the fmt.Stringer. -func (gf *GithubFlow) String() string { - var builder strings.Builder - builder.WriteString("GithubFlow(") - builder.WriteString(fmt.Sprintf("id=%v, ", gf.ID)) - builder.WriteString("created_at=") - builder.WriteString(gf.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("identifier=") - builder.WriteString(gf.Identifier) - builder.WriteString(", ") - builder.WriteString("verifier=") - builder.WriteString(gf.Verifier) - builder.WriteString(", ") - builder.WriteString("challenge=") - builder.WriteString(gf.Challenge) - builder.WriteString(", ") - builder.WriteString("next_url=") - builder.WriteString(gf.NextURL) - builder.WriteString(", ") - builder.WriteString("organization=") - builder.WriteString(gf.Organization) - builder.WriteString(", ") - builder.WriteString("device_identifier=") - builder.WriteString(gf.DeviceIdentifier) - builder.WriteByte(')') - return builder.String() -} - -// GithubFlows is a parsable slice of GithubFlow. -type GithubFlows []*GithubFlow diff --git a/internal/ent/githubflow/githubflow.go b/internal/ent/githubflow/githubflow.go deleted file mode 100644 index a7e4200..0000000 --- a/internal/ent/githubflow/githubflow.go +++ /dev/null @@ -1,126 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package githubflow - -import ( - "time" - - "entgo.io/ent/dialect/sql" -) - -const ( - // Label holds the string label denoting the githubflow type in the database. - Label = "github_flow" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldCreatedAt holds the string denoting the created_at field in the database. - FieldCreatedAt = "created_at" - // FieldIdentifier holds the string denoting the identifier field in the database. - FieldIdentifier = "identifier" - // FieldVerifier holds the string denoting the verifier field in the database. - FieldVerifier = "verifier" - // FieldChallenge holds the string denoting the challenge field in the database. - FieldChallenge = "challenge" - // FieldNextURL holds the string denoting the next_url field in the database. - FieldNextURL = "next_url" - // FieldOrganization holds the string denoting the organization field in the database. - FieldOrganization = "organization" - // FieldDeviceIdentifier holds the string denoting the device_identifier field in the database. - FieldDeviceIdentifier = "device_identifier" - // Table holds the table name of the githubflow in the database. - Table = "github_flows" -) - -// Columns holds all SQL columns for githubflow fields. -var Columns = []string{ - FieldID, - FieldCreatedAt, - FieldIdentifier, - FieldVerifier, - FieldChallenge, - FieldNextURL, - FieldOrganization, - FieldDeviceIdentifier, -} - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} - -var ( - // DefaultCreatedAt holds the default value on creation for the "created_at" field. - DefaultCreatedAt func() time.Time - // IdentifierValidator is a validator for the "identifier" field. It is called by the builders before save. - IdentifierValidator func(string) error - // VerifierValidator is a validator for the "verifier" field. It is called by the builders before save. - VerifierValidator func(string) error - // ChallengeValidator is a validator for the "challenge" field. It is called by the builders before save. - ChallengeValidator func(string) error - // NextURLValidator is a validator for the "next_url" field. It is called by the builders before save. - NextURLValidator func(string) error -) - -// OrderOption defines the ordering options for the GithubFlow queries. -type OrderOption func(*sql.Selector) - -// ByID orders the results by the id field. -func ByID(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldID, opts...).ToFunc() -} - -// ByCreatedAt orders the results by the created_at field. -func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() -} - -// ByIdentifier orders the results by the identifier field. -func ByIdentifier(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldIdentifier, opts...).ToFunc() -} - -// ByVerifier orders the results by the verifier field. -func ByVerifier(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldVerifier, opts...).ToFunc() -} - -// ByChallenge orders the results by the challenge field. -func ByChallenge(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldChallenge, opts...).ToFunc() -} - -// ByNextURL orders the results by the next_url field. -func ByNextURL(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldNextURL, opts...).ToFunc() -} - -// ByOrganization orders the results by the organization field. -func ByOrganization(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldOrganization, opts...).ToFunc() -} - -// ByDeviceIdentifier orders the results by the device_identifier field. -func ByDeviceIdentifier(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldDeviceIdentifier, opts...).ToFunc() -} diff --git a/internal/ent/githubflow/where.go b/internal/ent/githubflow/where.go deleted file mode 100644 index 298db8c..0000000 --- a/internal/ent/githubflow/where.go +++ /dev/null @@ -1,588 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package githubflow - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id int) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldID, id)) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldID, id)) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNEQ(FieldID, id)) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldIn(FieldID, ids...)) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNotIn(FieldID, ids...)) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGT(FieldID, id)) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGTE(FieldID, id)) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLT(FieldID, id)) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLTE(FieldID, id)) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldCreatedAt, v)) -} - -// Identifier applies equality check predicate on the "identifier" field. It's identical to IdentifierEQ. -func Identifier(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldIdentifier, v)) -} - -// Verifier applies equality check predicate on the "verifier" field. It's identical to VerifierEQ. -func Verifier(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldVerifier, v)) -} - -// Challenge applies equality check predicate on the "challenge" field. It's identical to ChallengeEQ. -func Challenge(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldChallenge, v)) -} - -// NextURL applies equality check predicate on the "next_url" field. It's identical to NextURLEQ. -func NextURL(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldNextURL, v)) -} - -// Organization applies equality check predicate on the "organization" field. It's identical to OrganizationEQ. -func Organization(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldOrganization, v)) -} - -// DeviceIdentifier applies equality check predicate on the "device_identifier" field. It's identical to DeviceIdentifierEQ. -func DeviceIdentifier(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldDeviceIdentifier, v)) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldCreatedAt, v)) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNEQ(FieldCreatedAt, v)) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldIn(FieldCreatedAt, vs...)) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNotIn(FieldCreatedAt, vs...)) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGT(FieldCreatedAt, v)) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGTE(FieldCreatedAt, v)) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLT(FieldCreatedAt, v)) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLTE(FieldCreatedAt, v)) -} - -// IdentifierEQ applies the EQ predicate on the "identifier" field. -func IdentifierEQ(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldIdentifier, v)) -} - -// IdentifierNEQ applies the NEQ predicate on the "identifier" field. -func IdentifierNEQ(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNEQ(FieldIdentifier, v)) -} - -// IdentifierIn applies the In predicate on the "identifier" field. -func IdentifierIn(vs ...string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldIn(FieldIdentifier, vs...)) -} - -// IdentifierNotIn applies the NotIn predicate on the "identifier" field. -func IdentifierNotIn(vs ...string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNotIn(FieldIdentifier, vs...)) -} - -// IdentifierGT applies the GT predicate on the "identifier" field. -func IdentifierGT(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGT(FieldIdentifier, v)) -} - -// IdentifierGTE applies the GTE predicate on the "identifier" field. -func IdentifierGTE(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGTE(FieldIdentifier, v)) -} - -// IdentifierLT applies the LT predicate on the "identifier" field. -func IdentifierLT(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLT(FieldIdentifier, v)) -} - -// IdentifierLTE applies the LTE predicate on the "identifier" field. -func IdentifierLTE(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLTE(FieldIdentifier, v)) -} - -// IdentifierContains applies the Contains predicate on the "identifier" field. -func IdentifierContains(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldContains(FieldIdentifier, v)) -} - -// IdentifierHasPrefix applies the HasPrefix predicate on the "identifier" field. -func IdentifierHasPrefix(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldHasPrefix(FieldIdentifier, v)) -} - -// IdentifierHasSuffix applies the HasSuffix predicate on the "identifier" field. -func IdentifierHasSuffix(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldHasSuffix(FieldIdentifier, v)) -} - -// IdentifierEqualFold applies the EqualFold predicate on the "identifier" field. -func IdentifierEqualFold(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEqualFold(FieldIdentifier, v)) -} - -// IdentifierContainsFold applies the ContainsFold predicate on the "identifier" field. -func IdentifierContainsFold(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldContainsFold(FieldIdentifier, v)) -} - -// VerifierEQ applies the EQ predicate on the "verifier" field. -func VerifierEQ(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldVerifier, v)) -} - -// VerifierNEQ applies the NEQ predicate on the "verifier" field. -func VerifierNEQ(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNEQ(FieldVerifier, v)) -} - -// VerifierIn applies the In predicate on the "verifier" field. -func VerifierIn(vs ...string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldIn(FieldVerifier, vs...)) -} - -// VerifierNotIn applies the NotIn predicate on the "verifier" field. -func VerifierNotIn(vs ...string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNotIn(FieldVerifier, vs...)) -} - -// VerifierGT applies the GT predicate on the "verifier" field. -func VerifierGT(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGT(FieldVerifier, v)) -} - -// VerifierGTE applies the GTE predicate on the "verifier" field. -func VerifierGTE(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGTE(FieldVerifier, v)) -} - -// VerifierLT applies the LT predicate on the "verifier" field. -func VerifierLT(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLT(FieldVerifier, v)) -} - -// VerifierLTE applies the LTE predicate on the "verifier" field. -func VerifierLTE(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLTE(FieldVerifier, v)) -} - -// VerifierContains applies the Contains predicate on the "verifier" field. -func VerifierContains(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldContains(FieldVerifier, v)) -} - -// VerifierHasPrefix applies the HasPrefix predicate on the "verifier" field. -func VerifierHasPrefix(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldHasPrefix(FieldVerifier, v)) -} - -// VerifierHasSuffix applies the HasSuffix predicate on the "verifier" field. -func VerifierHasSuffix(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldHasSuffix(FieldVerifier, v)) -} - -// VerifierEqualFold applies the EqualFold predicate on the "verifier" field. -func VerifierEqualFold(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEqualFold(FieldVerifier, v)) -} - -// VerifierContainsFold applies the ContainsFold predicate on the "verifier" field. -func VerifierContainsFold(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldContainsFold(FieldVerifier, v)) -} - -// ChallengeEQ applies the EQ predicate on the "challenge" field. -func ChallengeEQ(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldChallenge, v)) -} - -// ChallengeNEQ applies the NEQ predicate on the "challenge" field. -func ChallengeNEQ(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNEQ(FieldChallenge, v)) -} - -// ChallengeIn applies the In predicate on the "challenge" field. -func ChallengeIn(vs ...string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldIn(FieldChallenge, vs...)) -} - -// ChallengeNotIn applies the NotIn predicate on the "challenge" field. -func ChallengeNotIn(vs ...string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNotIn(FieldChallenge, vs...)) -} - -// ChallengeGT applies the GT predicate on the "challenge" field. -func ChallengeGT(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGT(FieldChallenge, v)) -} - -// ChallengeGTE applies the GTE predicate on the "challenge" field. -func ChallengeGTE(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGTE(FieldChallenge, v)) -} - -// ChallengeLT applies the LT predicate on the "challenge" field. -func ChallengeLT(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLT(FieldChallenge, v)) -} - -// ChallengeLTE applies the LTE predicate on the "challenge" field. -func ChallengeLTE(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLTE(FieldChallenge, v)) -} - -// ChallengeContains applies the Contains predicate on the "challenge" field. -func ChallengeContains(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldContains(FieldChallenge, v)) -} - -// ChallengeHasPrefix applies the HasPrefix predicate on the "challenge" field. -func ChallengeHasPrefix(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldHasPrefix(FieldChallenge, v)) -} - -// ChallengeHasSuffix applies the HasSuffix predicate on the "challenge" field. -func ChallengeHasSuffix(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldHasSuffix(FieldChallenge, v)) -} - -// ChallengeEqualFold applies the EqualFold predicate on the "challenge" field. -func ChallengeEqualFold(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEqualFold(FieldChallenge, v)) -} - -// ChallengeContainsFold applies the ContainsFold predicate on the "challenge" field. -func ChallengeContainsFold(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldContainsFold(FieldChallenge, v)) -} - -// NextURLEQ applies the EQ predicate on the "next_url" field. -func NextURLEQ(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldNextURL, v)) -} - -// NextURLNEQ applies the NEQ predicate on the "next_url" field. -func NextURLNEQ(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNEQ(FieldNextURL, v)) -} - -// NextURLIn applies the In predicate on the "next_url" field. -func NextURLIn(vs ...string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldIn(FieldNextURL, vs...)) -} - -// NextURLNotIn applies the NotIn predicate on the "next_url" field. -func NextURLNotIn(vs ...string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNotIn(FieldNextURL, vs...)) -} - -// NextURLGT applies the GT predicate on the "next_url" field. -func NextURLGT(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGT(FieldNextURL, v)) -} - -// NextURLGTE applies the GTE predicate on the "next_url" field. -func NextURLGTE(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGTE(FieldNextURL, v)) -} - -// NextURLLT applies the LT predicate on the "next_url" field. -func NextURLLT(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLT(FieldNextURL, v)) -} - -// NextURLLTE applies the LTE predicate on the "next_url" field. -func NextURLLTE(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLTE(FieldNextURL, v)) -} - -// NextURLContains applies the Contains predicate on the "next_url" field. -func NextURLContains(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldContains(FieldNextURL, v)) -} - -// NextURLHasPrefix applies the HasPrefix predicate on the "next_url" field. -func NextURLHasPrefix(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldHasPrefix(FieldNextURL, v)) -} - -// NextURLHasSuffix applies the HasSuffix predicate on the "next_url" field. -func NextURLHasSuffix(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldHasSuffix(FieldNextURL, v)) -} - -// NextURLEqualFold applies the EqualFold predicate on the "next_url" field. -func NextURLEqualFold(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEqualFold(FieldNextURL, v)) -} - -// NextURLContainsFold applies the ContainsFold predicate on the "next_url" field. -func NextURLContainsFold(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldContainsFold(FieldNextURL, v)) -} - -// OrganizationEQ applies the EQ predicate on the "organization" field. -func OrganizationEQ(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldOrganization, v)) -} - -// OrganizationNEQ applies the NEQ predicate on the "organization" field. -func OrganizationNEQ(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNEQ(FieldOrganization, v)) -} - -// OrganizationIn applies the In predicate on the "organization" field. -func OrganizationIn(vs ...string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldIn(FieldOrganization, vs...)) -} - -// OrganizationNotIn applies the NotIn predicate on the "organization" field. -func OrganizationNotIn(vs ...string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNotIn(FieldOrganization, vs...)) -} - -// OrganizationGT applies the GT predicate on the "organization" field. -func OrganizationGT(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGT(FieldOrganization, v)) -} - -// OrganizationGTE applies the GTE predicate on the "organization" field. -func OrganizationGTE(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGTE(FieldOrganization, v)) -} - -// OrganizationLT applies the LT predicate on the "organization" field. -func OrganizationLT(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLT(FieldOrganization, v)) -} - -// OrganizationLTE applies the LTE predicate on the "organization" field. -func OrganizationLTE(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLTE(FieldOrganization, v)) -} - -// OrganizationContains applies the Contains predicate on the "organization" field. -func OrganizationContains(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldContains(FieldOrganization, v)) -} - -// OrganizationHasPrefix applies the HasPrefix predicate on the "organization" field. -func OrganizationHasPrefix(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldHasPrefix(FieldOrganization, v)) -} - -// OrganizationHasSuffix applies the HasSuffix predicate on the "organization" field. -func OrganizationHasSuffix(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldHasSuffix(FieldOrganization, v)) -} - -// OrganizationIsNil applies the IsNil predicate on the "organization" field. -func OrganizationIsNil() predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldIsNull(FieldOrganization)) -} - -// OrganizationNotNil applies the NotNil predicate on the "organization" field. -func OrganizationNotNil() predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNotNull(FieldOrganization)) -} - -// OrganizationEqualFold applies the EqualFold predicate on the "organization" field. -func OrganizationEqualFold(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEqualFold(FieldOrganization, v)) -} - -// OrganizationContainsFold applies the ContainsFold predicate on the "organization" field. -func OrganizationContainsFold(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldContainsFold(FieldOrganization, v)) -} - -// DeviceIdentifierEQ applies the EQ predicate on the "device_identifier" field. -func DeviceIdentifierEQ(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEQ(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierNEQ applies the NEQ predicate on the "device_identifier" field. -func DeviceIdentifierNEQ(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNEQ(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierIn applies the In predicate on the "device_identifier" field. -func DeviceIdentifierIn(vs ...string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldIn(FieldDeviceIdentifier, vs...)) -} - -// DeviceIdentifierNotIn applies the NotIn predicate on the "device_identifier" field. -func DeviceIdentifierNotIn(vs ...string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNotIn(FieldDeviceIdentifier, vs...)) -} - -// DeviceIdentifierGT applies the GT predicate on the "device_identifier" field. -func DeviceIdentifierGT(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGT(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierGTE applies the GTE predicate on the "device_identifier" field. -func DeviceIdentifierGTE(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldGTE(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierLT applies the LT predicate on the "device_identifier" field. -func DeviceIdentifierLT(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLT(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierLTE applies the LTE predicate on the "device_identifier" field. -func DeviceIdentifierLTE(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldLTE(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierContains applies the Contains predicate on the "device_identifier" field. -func DeviceIdentifierContains(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldContains(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierHasPrefix applies the HasPrefix predicate on the "device_identifier" field. -func DeviceIdentifierHasPrefix(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldHasPrefix(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierHasSuffix applies the HasSuffix predicate on the "device_identifier" field. -func DeviceIdentifierHasSuffix(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldHasSuffix(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierIsNil applies the IsNil predicate on the "device_identifier" field. -func DeviceIdentifierIsNil() predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldIsNull(FieldDeviceIdentifier)) -} - -// DeviceIdentifierNotNil applies the NotNil predicate on the "device_identifier" field. -func DeviceIdentifierNotNil() predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldNotNull(FieldDeviceIdentifier)) -} - -// DeviceIdentifierEqualFold applies the EqualFold predicate on the "device_identifier" field. -func DeviceIdentifierEqualFold(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldEqualFold(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierContainsFold applies the ContainsFold predicate on the "device_identifier" field. -func DeviceIdentifierContainsFold(v string) predicate.GithubFlow { - return predicate.GithubFlow(sql.FieldContainsFold(FieldDeviceIdentifier, v)) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.GithubFlow) predicate.GithubFlow { - return predicate.GithubFlow(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.GithubFlow) predicate.GithubFlow { - return predicate.GithubFlow(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.GithubFlow) predicate.GithubFlow { - return predicate.GithubFlow(func(s *sql.Selector) { - p(s.Not()) - }) -} diff --git a/internal/ent/githubflow_create.go b/internal/ent/githubflow_create.go deleted file mode 100644 index fa4d2cb..0000000 --- a/internal/ent/githubflow_create.go +++ /dev/null @@ -1,322 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/githubflow" -) - -// GithubFlowCreate is the builder for creating a GithubFlow entity. -type GithubFlowCreate struct { - config - mutation *GithubFlowMutation - hooks []Hook -} - -// SetCreatedAt sets the "created_at" field. -func (gfc *GithubFlowCreate) SetCreatedAt(t time.Time) *GithubFlowCreate { - gfc.mutation.SetCreatedAt(t) - return gfc -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (gfc *GithubFlowCreate) SetNillableCreatedAt(t *time.Time) *GithubFlowCreate { - if t != nil { - gfc.SetCreatedAt(*t) - } - return gfc -} - -// SetIdentifier sets the "identifier" field. -func (gfc *GithubFlowCreate) SetIdentifier(s string) *GithubFlowCreate { - gfc.mutation.SetIdentifier(s) - return gfc -} - -// SetVerifier sets the "verifier" field. -func (gfc *GithubFlowCreate) SetVerifier(s string) *GithubFlowCreate { - gfc.mutation.SetVerifier(s) - return gfc -} - -// SetChallenge sets the "challenge" field. -func (gfc *GithubFlowCreate) SetChallenge(s string) *GithubFlowCreate { - gfc.mutation.SetChallenge(s) - return gfc -} - -// SetNextURL sets the "next_url" field. -func (gfc *GithubFlowCreate) SetNextURL(s string) *GithubFlowCreate { - gfc.mutation.SetNextURL(s) - return gfc -} - -// SetOrganization sets the "organization" field. -func (gfc *GithubFlowCreate) SetOrganization(s string) *GithubFlowCreate { - gfc.mutation.SetOrganization(s) - return gfc -} - -// SetNillableOrganization sets the "organization" field if the given value is not nil. -func (gfc *GithubFlowCreate) SetNillableOrganization(s *string) *GithubFlowCreate { - if s != nil { - gfc.SetOrganization(*s) - } - return gfc -} - -// SetDeviceIdentifier sets the "device_identifier" field. -func (gfc *GithubFlowCreate) SetDeviceIdentifier(s string) *GithubFlowCreate { - gfc.mutation.SetDeviceIdentifier(s) - return gfc -} - -// SetNillableDeviceIdentifier sets the "device_identifier" field if the given value is not nil. -func (gfc *GithubFlowCreate) SetNillableDeviceIdentifier(s *string) *GithubFlowCreate { - if s != nil { - gfc.SetDeviceIdentifier(*s) - } - return gfc -} - -// Mutation returns the GithubFlowMutation object of the builder. -func (gfc *GithubFlowCreate) Mutation() *GithubFlowMutation { - return gfc.mutation -} - -// Save creates the GithubFlow in the database. -func (gfc *GithubFlowCreate) Save(ctx context.Context) (*GithubFlow, error) { - gfc.defaults() - return withHooks(ctx, gfc.sqlSave, gfc.mutation, gfc.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (gfc *GithubFlowCreate) SaveX(ctx context.Context) *GithubFlow { - v, err := gfc.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (gfc *GithubFlowCreate) Exec(ctx context.Context) error { - _, err := gfc.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (gfc *GithubFlowCreate) ExecX(ctx context.Context) { - if err := gfc.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (gfc *GithubFlowCreate) defaults() { - if _, ok := gfc.mutation.CreatedAt(); !ok { - v := githubflow.DefaultCreatedAt() - gfc.mutation.SetCreatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (gfc *GithubFlowCreate) check() error { - if _, ok := gfc.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "GithubFlow.created_at"`)} - } - if _, ok := gfc.mutation.Identifier(); !ok { - return &ValidationError{Name: "identifier", err: errors.New(`ent: missing required field "GithubFlow.identifier"`)} - } - if v, ok := gfc.mutation.Identifier(); ok { - if err := githubflow.IdentifierValidator(v); err != nil { - return &ValidationError{Name: "identifier", err: fmt.Errorf(`ent: validator failed for field "GithubFlow.identifier": %w`, err)} - } - } - if _, ok := gfc.mutation.Verifier(); !ok { - return &ValidationError{Name: "verifier", err: errors.New(`ent: missing required field "GithubFlow.verifier"`)} - } - if v, ok := gfc.mutation.Verifier(); ok { - if err := githubflow.VerifierValidator(v); err != nil { - return &ValidationError{Name: "verifier", err: fmt.Errorf(`ent: validator failed for field "GithubFlow.verifier": %w`, err)} - } - } - if _, ok := gfc.mutation.Challenge(); !ok { - return &ValidationError{Name: "challenge", err: errors.New(`ent: missing required field "GithubFlow.challenge"`)} - } - if v, ok := gfc.mutation.Challenge(); ok { - if err := githubflow.ChallengeValidator(v); err != nil { - return &ValidationError{Name: "challenge", err: fmt.Errorf(`ent: validator failed for field "GithubFlow.challenge": %w`, err)} - } - } - if _, ok := gfc.mutation.NextURL(); !ok { - return &ValidationError{Name: "next_url", err: errors.New(`ent: missing required field "GithubFlow.next_url"`)} - } - if v, ok := gfc.mutation.NextURL(); ok { - if err := githubflow.NextURLValidator(v); err != nil { - return &ValidationError{Name: "next_url", err: fmt.Errorf(`ent: validator failed for field "GithubFlow.next_url": %w`, err)} - } - } - return nil -} - -func (gfc *GithubFlowCreate) sqlSave(ctx context.Context) (*GithubFlow, error) { - if err := gfc.check(); err != nil { - return nil, err - } - _node, _spec := gfc.createSpec() - if err := sqlgraph.CreateNode(ctx, gfc.driver, _spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - id := _spec.ID.Value.(int64) - _node.ID = int(id) - gfc.mutation.id = &_node.ID - gfc.mutation.done = true - return _node, nil -} - -func (gfc *GithubFlowCreate) createSpec() (*GithubFlow, *sqlgraph.CreateSpec) { - var ( - _node = &GithubFlow{config: gfc.config} - _spec = sqlgraph.NewCreateSpec(githubflow.Table, sqlgraph.NewFieldSpec(githubflow.FieldID, field.TypeInt)) - ) - if value, ok := gfc.mutation.CreatedAt(); ok { - _spec.SetField(githubflow.FieldCreatedAt, field.TypeTime, value) - _node.CreatedAt = value - } - if value, ok := gfc.mutation.Identifier(); ok { - _spec.SetField(githubflow.FieldIdentifier, field.TypeString, value) - _node.Identifier = value - } - if value, ok := gfc.mutation.Verifier(); ok { - _spec.SetField(githubflow.FieldVerifier, field.TypeString, value) - _node.Verifier = value - } - if value, ok := gfc.mutation.Challenge(); ok { - _spec.SetField(githubflow.FieldChallenge, field.TypeString, value) - _node.Challenge = value - } - if value, ok := gfc.mutation.NextURL(); ok { - _spec.SetField(githubflow.FieldNextURL, field.TypeString, value) - _node.NextURL = value - } - if value, ok := gfc.mutation.Organization(); ok { - _spec.SetField(githubflow.FieldOrganization, field.TypeString, value) - _node.Organization = value - } - if value, ok := gfc.mutation.DeviceIdentifier(); ok { - _spec.SetField(githubflow.FieldDeviceIdentifier, field.TypeString, value) - _node.DeviceIdentifier = value - } - return _node, _spec -} - -// GithubFlowCreateBulk is the builder for creating many GithubFlow entities in bulk. -type GithubFlowCreateBulk struct { - config - builders []*GithubFlowCreate -} - -// Save creates the GithubFlow entities in the database. -func (gfcb *GithubFlowCreateBulk) Save(ctx context.Context) ([]*GithubFlow, error) { - specs := make([]*sqlgraph.CreateSpec, len(gfcb.builders)) - nodes := make([]*GithubFlow, len(gfcb.builders)) - mutators := make([]Mutator, len(gfcb.builders)) - for i := range gfcb.builders { - func(i int, root context.Context) { - builder := gfcb.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*GithubFlowMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - var err error - nodes[i], specs[i] = builder.createSpec() - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, gfcb.builders[i+1].mutation) - } else { - spec := &sqlgraph.BatchCreateSpec{Nodes: specs} - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, gfcb.driver, spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - } - } - if err != nil { - return nil, err - } - mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) - } - mutation.done = true - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, gfcb.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (gfcb *GithubFlowCreateBulk) SaveX(ctx context.Context) []*GithubFlow { - v, err := gfcb.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (gfcb *GithubFlowCreateBulk) Exec(ctx context.Context) error { - _, err := gfcb.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (gfcb *GithubFlowCreateBulk) ExecX(ctx context.Context) { - if err := gfcb.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/internal/ent/githubflow_delete.go b/internal/ent/githubflow_delete.go deleted file mode 100644 index ba5cfa2..0000000 --- a/internal/ent/githubflow_delete.go +++ /dev/null @@ -1,104 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/githubflow" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// GithubFlowDelete is the builder for deleting a GithubFlow entity. -type GithubFlowDelete struct { - config - hooks []Hook - mutation *GithubFlowMutation -} - -// Where appends a list predicates to the GithubFlowDelete builder. -func (gfd *GithubFlowDelete) Where(ps ...predicate.GithubFlow) *GithubFlowDelete { - gfd.mutation.Where(ps...) - return gfd -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (gfd *GithubFlowDelete) Exec(ctx context.Context) (int, error) { - return withHooks(ctx, gfd.sqlExec, gfd.mutation, gfd.hooks) -} - -// ExecX is like Exec, but panics if an error occurs. -func (gfd *GithubFlowDelete) ExecX(ctx context.Context) int { - n, err := gfd.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (gfd *GithubFlowDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(githubflow.Table, sqlgraph.NewFieldSpec(githubflow.FieldID, field.TypeInt)) - if ps := gfd.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - affected, err := sqlgraph.DeleteNodes(ctx, gfd.driver, _spec) - if err != nil && sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - gfd.mutation.done = true - return affected, err -} - -// GithubFlowDeleteOne is the builder for deleting a single GithubFlow entity. -type GithubFlowDeleteOne struct { - gfd *GithubFlowDelete -} - -// Where appends a list predicates to the GithubFlowDelete builder. -func (gfdo *GithubFlowDeleteOne) Where(ps ...predicate.GithubFlow) *GithubFlowDeleteOne { - gfdo.gfd.mutation.Where(ps...) - return gfdo -} - -// Exec executes the deletion query. -func (gfdo *GithubFlowDeleteOne) Exec(ctx context.Context) error { - n, err := gfdo.gfd.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{githubflow.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (gfdo *GithubFlowDeleteOne) ExecX(ctx context.Context) { - if err := gfdo.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/internal/ent/githubflow_query.go b/internal/ent/githubflow_query.go deleted file mode 100644 index 5e7bd8a..0000000 --- a/internal/ent/githubflow_query.go +++ /dev/null @@ -1,542 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "math" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/githubflow" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// GithubFlowQuery is the builder for querying GithubFlow entities. -type GithubFlowQuery struct { - config - ctx *QueryContext - order []githubflow.OrderOption - inters []Interceptor - predicates []predicate.GithubFlow - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the GithubFlowQuery builder. -func (gfq *GithubFlowQuery) Where(ps ...predicate.GithubFlow) *GithubFlowQuery { - gfq.predicates = append(gfq.predicates, ps...) - return gfq -} - -// Limit the number of records to be returned by this query. -func (gfq *GithubFlowQuery) Limit(limit int) *GithubFlowQuery { - gfq.ctx.Limit = &limit - return gfq -} - -// Offset to start from. -func (gfq *GithubFlowQuery) Offset(offset int) *GithubFlowQuery { - gfq.ctx.Offset = &offset - return gfq -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (gfq *GithubFlowQuery) Unique(unique bool) *GithubFlowQuery { - gfq.ctx.Unique = &unique - return gfq -} - -// Order specifies how the records should be ordered. -func (gfq *GithubFlowQuery) Order(o ...githubflow.OrderOption) *GithubFlowQuery { - gfq.order = append(gfq.order, o...) - return gfq -} - -// First returns the first GithubFlow entity from the query. -// Returns a *NotFoundError when no GithubFlow was found. -func (gfq *GithubFlowQuery) First(ctx context.Context) (*GithubFlow, error) { - nodes, err := gfq.Limit(1).All(setContextOp(ctx, gfq.ctx, "First")) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{githubflow.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (gfq *GithubFlowQuery) FirstX(ctx context.Context) *GithubFlow { - node, err := gfq.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first GithubFlow ID from the query. -// Returns a *NotFoundError when no GithubFlow ID was found. -func (gfq *GithubFlowQuery) FirstID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = gfq.Limit(1).IDs(setContextOp(ctx, gfq.ctx, "FirstID")); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{githubflow.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (gfq *GithubFlowQuery) FirstIDX(ctx context.Context) int { - id, err := gfq.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single GithubFlow entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one GithubFlow entity is found. -// Returns a *NotFoundError when no GithubFlow entities are found. -func (gfq *GithubFlowQuery) Only(ctx context.Context) (*GithubFlow, error) { - nodes, err := gfq.Limit(2).All(setContextOp(ctx, gfq.ctx, "Only")) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{githubflow.Label} - default: - return nil, &NotSingularError{githubflow.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (gfq *GithubFlowQuery) OnlyX(ctx context.Context) *GithubFlow { - node, err := gfq.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only GithubFlow ID in the query. -// Returns a *NotSingularError when more than one GithubFlow ID is found. -// Returns a *NotFoundError when no entities are found. -func (gfq *GithubFlowQuery) OnlyID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = gfq.Limit(2).IDs(setContextOp(ctx, gfq.ctx, "OnlyID")); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{githubflow.Label} - default: - err = &NotSingularError{githubflow.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (gfq *GithubFlowQuery) OnlyIDX(ctx context.Context) int { - id, err := gfq.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of GithubFlows. -func (gfq *GithubFlowQuery) All(ctx context.Context) ([]*GithubFlow, error) { - ctx = setContextOp(ctx, gfq.ctx, "All") - if err := gfq.prepareQuery(ctx); err != nil { - return nil, err - } - qr := querierAll[[]*GithubFlow, *GithubFlowQuery]() - return withInterceptors[[]*GithubFlow](ctx, gfq, qr, gfq.inters) -} - -// AllX is like All, but panics if an error occurs. -func (gfq *GithubFlowQuery) AllX(ctx context.Context) []*GithubFlow { - nodes, err := gfq.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of GithubFlow IDs. -func (gfq *GithubFlowQuery) IDs(ctx context.Context) (ids []int, err error) { - if gfq.ctx.Unique == nil && gfq.path != nil { - gfq.Unique(true) - } - ctx = setContextOp(ctx, gfq.ctx, "IDs") - if err = gfq.Select(githubflow.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (gfq *GithubFlowQuery) IDsX(ctx context.Context) []int { - ids, err := gfq.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (gfq *GithubFlowQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, gfq.ctx, "Count") - if err := gfq.prepareQuery(ctx); err != nil { - return 0, err - } - return withInterceptors[int](ctx, gfq, querierCount[*GithubFlowQuery](), gfq.inters) -} - -// CountX is like Count, but panics if an error occurs. -func (gfq *GithubFlowQuery) CountX(ctx context.Context) int { - count, err := gfq.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (gfq *GithubFlowQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, gfq.ctx, "Exist") - switch _, err := gfq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - -// ExistX is like Exist, but panics if an error occurs. -func (gfq *GithubFlowQuery) ExistX(ctx context.Context) bool { - exist, err := gfq.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the GithubFlowQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (gfq *GithubFlowQuery) Clone() *GithubFlowQuery { - if gfq == nil { - return nil - } - return &GithubFlowQuery{ - config: gfq.config, - ctx: gfq.ctx.Clone(), - order: append([]githubflow.OrderOption{}, gfq.order...), - inters: append([]Interceptor{}, gfq.inters...), - predicates: append([]predicate.GithubFlow{}, gfq.predicates...), - // clone intermediate query. - sql: gfq.sql.Clone(), - path: gfq.path, - } -} - -// 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: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.GithubFlow.Query(). -// GroupBy(githubflow.FieldCreatedAt). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -func (gfq *GithubFlowQuery) GroupBy(field string, fields ...string) *GithubFlowGroupBy { - gfq.ctx.Fields = append([]string{field}, fields...) - grbuild := &GithubFlowGroupBy{build: gfq} - grbuild.flds = &gfq.ctx.Fields - grbuild.label = githubflow.Label - grbuild.scan = grbuild.Scan - return grbuild -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// } -// -// client.GithubFlow.Query(). -// Select(githubflow.FieldCreatedAt). -// Scan(ctx, &v) -func (gfq *GithubFlowQuery) Select(fields ...string) *GithubFlowSelect { - gfq.ctx.Fields = append(gfq.ctx.Fields, fields...) - sbuild := &GithubFlowSelect{GithubFlowQuery: gfq} - sbuild.label = githubflow.Label - sbuild.flds, sbuild.scan = &gfq.ctx.Fields, sbuild.Scan - return sbuild -} - -// Aggregate returns a GithubFlowSelect configured with the given aggregations. -func (gfq *GithubFlowQuery) Aggregate(fns ...AggregateFunc) *GithubFlowSelect { - return gfq.Select().Aggregate(fns...) -} - -func (gfq *GithubFlowQuery) prepareQuery(ctx context.Context) error { - for _, inter := range gfq.inters { - if inter == nil { - return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") - } - if trv, ok := inter.(Traverser); ok { - if err := trv.Traverse(ctx, gfq); err != nil { - return err - } - } - } - for _, f := range gfq.ctx.Fields { - if !githubflow.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if gfq.path != nil { - prev, err := gfq.path(ctx) - if err != nil { - return err - } - gfq.sql = prev - } - return nil -} - -func (gfq *GithubFlowQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*GithubFlow, error) { - var ( - nodes = []*GithubFlow{} - _spec = gfq.querySpec() - ) - _spec.ScanValues = func(columns []string) ([]any, error) { - return (*GithubFlow).scanValues(nil, columns) - } - _spec.Assign = func(columns []string, values []any) error { - node := &GithubFlow{config: gfq.config} - nodes = append(nodes, node) - return node.assignValues(columns, values) - } - for i := range hooks { - hooks[i](ctx, _spec) - } - if err := sqlgraph.QueryNodes(ctx, gfq.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - return nodes, nil -} - -func (gfq *GithubFlowQuery) sqlCount(ctx context.Context) (int, error) { - _spec := gfq.querySpec() - _spec.Node.Columns = gfq.ctx.Fields - if len(gfq.ctx.Fields) > 0 { - _spec.Unique = gfq.ctx.Unique != nil && *gfq.ctx.Unique - } - return sqlgraph.CountNodes(ctx, gfq.driver, _spec) -} - -func (gfq *GithubFlowQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(githubflow.Table, githubflow.Columns, sqlgraph.NewFieldSpec(githubflow.FieldID, field.TypeInt)) - _spec.From = gfq.sql - if unique := gfq.ctx.Unique; unique != nil { - _spec.Unique = *unique - } else if gfq.path != nil { - _spec.Unique = true - } - if fields := gfq.ctx.Fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, githubflow.FieldID) - for i := range fields { - if fields[i] != githubflow.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := gfq.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := gfq.ctx.Limit; limit != nil { - _spec.Limit = *limit - } - if offset := gfq.ctx.Offset; offset != nil { - _spec.Offset = *offset - } - if ps := gfq.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (gfq *GithubFlowQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(gfq.driver.Dialect()) - t1 := builder.Table(githubflow.Table) - columns := gfq.ctx.Fields - if len(columns) == 0 { - columns = githubflow.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if gfq.sql != nil { - selector = gfq.sql - selector.Select(selector.Columns(columns...)...) - } - if gfq.ctx.Unique != nil && *gfq.ctx.Unique { - selector.Distinct() - } - for _, p := range gfq.predicates { - p(selector) - } - for _, p := range gfq.order { - p(selector) - } - if offset := gfq.ctx.Offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := gfq.ctx.Limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// GithubFlowGroupBy is the group-by builder for GithubFlow entities. -type GithubFlowGroupBy struct { - selector - build *GithubFlowQuery -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (gfgb *GithubFlowGroupBy) Aggregate(fns ...AggregateFunc) *GithubFlowGroupBy { - gfgb.fns = append(gfgb.fns, fns...) - return gfgb -} - -// Scan applies the selector query and scans the result into the given value. -func (gfgb *GithubFlowGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, gfgb.build.ctx, "GroupBy") - if err := gfgb.build.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*GithubFlowQuery, *GithubFlowGroupBy](ctx, gfgb.build, gfgb, gfgb.build.inters, v) -} - -func (gfgb *GithubFlowGroupBy) sqlScan(ctx context.Context, root *GithubFlowQuery, v any) error { - selector := root.sqlQuery(ctx).Select() - aggregation := make([]string, 0, len(gfgb.fns)) - for _, fn := range gfgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(*gfgb.flds)+len(gfgb.fns)) - for _, f := range *gfgb.flds { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - selector.GroupBy(selector.Columns(*gfgb.flds...)...) - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := gfgb.build.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -// GithubFlowSelect is the builder for selecting fields of GithubFlow entities. -type GithubFlowSelect struct { - *GithubFlowQuery - selector -} - -// Aggregate adds the given aggregation functions to the selector query. -func (gfs *GithubFlowSelect) Aggregate(fns ...AggregateFunc) *GithubFlowSelect { - gfs.fns = append(gfs.fns, fns...) - return gfs -} - -// Scan applies the selector query and scans the result into the given value. -func (gfs *GithubFlowSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, gfs.ctx, "Select") - if err := gfs.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*GithubFlowQuery, *GithubFlowSelect](ctx, gfs.GithubFlowQuery, gfs, gfs.inters, v) -} - -func (gfs *GithubFlowSelect) sqlScan(ctx context.Context, root *GithubFlowQuery, v any) error { - selector := root.sqlQuery(ctx) - aggregation := make([]string, 0, len(gfs.fns)) - for _, fn := range gfs.fns { - aggregation = append(aggregation, fn(selector)) - } - switch n := len(*gfs.selector.flds); { - case n == 0 && len(aggregation) > 0: - selector.Select(aggregation...) - case n != 0 && len(aggregation) > 0: - selector.AppendSelect(aggregation...) - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := gfs.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/internal/ent/githubflow_update.go b/internal/ent/githubflow_update.go deleted file mode 100644 index a2b59f9..0000000 --- a/internal/ent/githubflow_update.go +++ /dev/null @@ -1,203 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/githubflow" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// GithubFlowUpdate is the builder for updating GithubFlow entities. -type GithubFlowUpdate struct { - config - hooks []Hook - mutation *GithubFlowMutation -} - -// Where appends a list predicates to the GithubFlowUpdate builder. -func (gfu *GithubFlowUpdate) Where(ps ...predicate.GithubFlow) *GithubFlowUpdate { - gfu.mutation.Where(ps...) - return gfu -} - -// Mutation returns the GithubFlowMutation object of the builder. -func (gfu *GithubFlowUpdate) Mutation() *GithubFlowMutation { - return gfu.mutation -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (gfu *GithubFlowUpdate) Save(ctx context.Context) (int, error) { - return withHooks(ctx, gfu.sqlSave, gfu.mutation, gfu.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (gfu *GithubFlowUpdate) SaveX(ctx context.Context) int { - affected, err := gfu.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (gfu *GithubFlowUpdate) Exec(ctx context.Context) error { - _, err := gfu.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (gfu *GithubFlowUpdate) ExecX(ctx context.Context) { - if err := gfu.Exec(ctx); err != nil { - panic(err) - } -} - -func (gfu *GithubFlowUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := sqlgraph.NewUpdateSpec(githubflow.Table, githubflow.Columns, sqlgraph.NewFieldSpec(githubflow.FieldID, field.TypeInt)) - if ps := gfu.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if gfu.mutation.OrganizationCleared() { - _spec.ClearField(githubflow.FieldOrganization, field.TypeString) - } - if gfu.mutation.DeviceIdentifierCleared() { - _spec.ClearField(githubflow.FieldDeviceIdentifier, field.TypeString) - } - if n, err = sqlgraph.UpdateNodes(ctx, gfu.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{githubflow.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - gfu.mutation.done = true - return n, nil -} - -// GithubFlowUpdateOne is the builder for updating a single GithubFlow entity. -type GithubFlowUpdateOne struct { - config - fields []string - hooks []Hook - mutation *GithubFlowMutation -} - -// Mutation returns the GithubFlowMutation object of the builder. -func (gfuo *GithubFlowUpdateOne) Mutation() *GithubFlowMutation { - return gfuo.mutation -} - -// Where appends a list predicates to the GithubFlowUpdate builder. -func (gfuo *GithubFlowUpdateOne) Where(ps ...predicate.GithubFlow) *GithubFlowUpdateOne { - gfuo.mutation.Where(ps...) - return gfuo -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (gfuo *GithubFlowUpdateOne) Select(field string, fields ...string) *GithubFlowUpdateOne { - gfuo.fields = append([]string{field}, fields...) - return gfuo -} - -// Save executes the query and returns the updated GithubFlow entity. -func (gfuo *GithubFlowUpdateOne) Save(ctx context.Context) (*GithubFlow, error) { - return withHooks(ctx, gfuo.sqlSave, gfuo.mutation, gfuo.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (gfuo *GithubFlowUpdateOne) SaveX(ctx context.Context) *GithubFlow { - node, err := gfuo.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (gfuo *GithubFlowUpdateOne) Exec(ctx context.Context) error { - _, err := gfuo.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (gfuo *GithubFlowUpdateOne) ExecX(ctx context.Context) { - if err := gfuo.Exec(ctx); err != nil { - panic(err) - } -} - -func (gfuo *GithubFlowUpdateOne) sqlSave(ctx context.Context) (_node *GithubFlow, err error) { - _spec := sqlgraph.NewUpdateSpec(githubflow.Table, githubflow.Columns, sqlgraph.NewFieldSpec(githubflow.FieldID, field.TypeInt)) - id, ok := gfuo.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "GithubFlow.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := gfuo.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, githubflow.FieldID) - for _, f := range fields { - if !githubflow.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != githubflow.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := gfuo.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if gfuo.mutation.OrganizationCleared() { - _spec.ClearField(githubflow.FieldOrganization, field.TypeString) - } - if gfuo.mutation.DeviceIdentifierCleared() { - _spec.ClearField(githubflow.FieldDeviceIdentifier, field.TypeString) - } - _node = &GithubFlow{config: gfuo.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, gfuo.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{githubflow.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - gfuo.mutation.done = true - return _node, nil -} diff --git a/internal/ent/googleflow.go b/internal/ent/googleflow.go deleted file mode 100644 index 87546ef..0000000 --- a/internal/ent/googleflow.go +++ /dev/null @@ -1,188 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "github.com/loopholelabs/auth/internal/ent/googleflow" -) - -// GoogleFlow is the model entity for the GoogleFlow schema. -type GoogleFlow struct { - config `json:"-"` - // ID of the ent. - ID int `json:"id,omitempty"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at,omitempty"` - // Identifier holds the value of the "identifier" field. - Identifier string `json:"identifier,omitempty"` - // Verifier holds the value of the "verifier" field. - Verifier string `json:"verifier,omitempty"` - // Challenge holds the value of the "challenge" field. - Challenge string `json:"challenge,omitempty"` - // NextURL holds the value of the "next_url" field. - NextURL string `json:"next_url,omitempty"` - // Organization holds the value of the "organization" field. - Organization string `json:"organization,omitempty"` - // DeviceIdentifier holds the value of the "device_identifier" field. - DeviceIdentifier string `json:"device_identifier,omitempty"` - selectValues sql.SelectValues -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*GoogleFlow) scanValues(columns []string) ([]any, error) { - values := make([]any, len(columns)) - for i := range columns { - switch columns[i] { - case googleflow.FieldID: - values[i] = new(sql.NullInt64) - case googleflow.FieldIdentifier, googleflow.FieldVerifier, googleflow.FieldChallenge, googleflow.FieldNextURL, googleflow.FieldOrganization, googleflow.FieldDeviceIdentifier: - values[i] = new(sql.NullString) - case googleflow.FieldCreatedAt: - values[i] = new(sql.NullTime) - default: - values[i] = new(sql.UnknownType) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the GoogleFlow fields. -func (gf *GoogleFlow) assignValues(columns []string, values []any) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case googleflow.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - gf.ID = int(value.Int64) - case googleflow.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 { - gf.CreatedAt = value.Time - } - case googleflow.FieldIdentifier: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field identifier", values[i]) - } else if value.Valid { - gf.Identifier = value.String - } - case googleflow.FieldVerifier: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field verifier", values[i]) - } else if value.Valid { - gf.Verifier = value.String - } - case googleflow.FieldChallenge: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field challenge", values[i]) - } else if value.Valid { - gf.Challenge = value.String - } - case googleflow.FieldNextURL: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field next_url", values[i]) - } else if value.Valid { - gf.NextURL = value.String - } - case googleflow.FieldOrganization: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field organization", values[i]) - } else if value.Valid { - gf.Organization = value.String - } - case googleflow.FieldDeviceIdentifier: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field device_identifier", values[i]) - } else if value.Valid { - gf.DeviceIdentifier = value.String - } - default: - gf.selectValues.Set(columns[i], values[i]) - } - } - return nil -} - -// Value returns the ent.Value that was dynamically selected and assigned to the GoogleFlow. -// This includes values selected through modifiers, order, etc. -func (gf *GoogleFlow) Value(name string) (ent.Value, error) { - return gf.selectValues.Get(name) -} - -// Update returns a builder for updating this GoogleFlow. -// Note that you need to call GoogleFlow.Unwrap() before calling this method if this GoogleFlow -// was returned from a transaction, and the transaction was committed or rolled back. -func (gf *GoogleFlow) Update() *GoogleFlowUpdateOne { - return NewGoogleFlowClient(gf.config).UpdateOne(gf) -} - -// Unwrap unwraps the GoogleFlow 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 (gf *GoogleFlow) Unwrap() *GoogleFlow { - _tx, ok := gf.config.driver.(*txDriver) - if !ok { - panic("ent: GoogleFlow is not a transactional entity") - } - gf.config.driver = _tx.drv - return gf -} - -// String implements the fmt.Stringer. -func (gf *GoogleFlow) String() string { - var builder strings.Builder - builder.WriteString("GoogleFlow(") - builder.WriteString(fmt.Sprintf("id=%v, ", gf.ID)) - builder.WriteString("created_at=") - builder.WriteString(gf.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("identifier=") - builder.WriteString(gf.Identifier) - builder.WriteString(", ") - builder.WriteString("verifier=") - builder.WriteString(gf.Verifier) - builder.WriteString(", ") - builder.WriteString("challenge=") - builder.WriteString(gf.Challenge) - builder.WriteString(", ") - builder.WriteString("next_url=") - builder.WriteString(gf.NextURL) - builder.WriteString(", ") - builder.WriteString("organization=") - builder.WriteString(gf.Organization) - builder.WriteString(", ") - builder.WriteString("device_identifier=") - builder.WriteString(gf.DeviceIdentifier) - builder.WriteByte(')') - return builder.String() -} - -// GoogleFlows is a parsable slice of GoogleFlow. -type GoogleFlows []*GoogleFlow diff --git a/internal/ent/googleflow/googleflow.go b/internal/ent/googleflow/googleflow.go deleted file mode 100644 index ce67eaf..0000000 --- a/internal/ent/googleflow/googleflow.go +++ /dev/null @@ -1,126 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package googleflow - -import ( - "time" - - "entgo.io/ent/dialect/sql" -) - -const ( - // Label holds the string label denoting the googleflow type in the database. - Label = "google_flow" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldCreatedAt holds the string denoting the created_at field in the database. - FieldCreatedAt = "created_at" - // FieldIdentifier holds the string denoting the identifier field in the database. - FieldIdentifier = "identifier" - // FieldVerifier holds the string denoting the verifier field in the database. - FieldVerifier = "verifier" - // FieldChallenge holds the string denoting the challenge field in the database. - FieldChallenge = "challenge" - // FieldNextURL holds the string denoting the next_url field in the database. - FieldNextURL = "next_url" - // FieldOrganization holds the string denoting the organization field in the database. - FieldOrganization = "organization" - // FieldDeviceIdentifier holds the string denoting the device_identifier field in the database. - FieldDeviceIdentifier = "device_identifier" - // Table holds the table name of the googleflow in the database. - Table = "google_flows" -) - -// Columns holds all SQL columns for googleflow fields. -var Columns = []string{ - FieldID, - FieldCreatedAt, - FieldIdentifier, - FieldVerifier, - FieldChallenge, - FieldNextURL, - FieldOrganization, - FieldDeviceIdentifier, -} - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} - -var ( - // DefaultCreatedAt holds the default value on creation for the "created_at" field. - DefaultCreatedAt func() time.Time - // IdentifierValidator is a validator for the "identifier" field. It is called by the builders before save. - IdentifierValidator func(string) error - // VerifierValidator is a validator for the "verifier" field. It is called by the builders before save. - VerifierValidator func(string) error - // ChallengeValidator is a validator for the "challenge" field. It is called by the builders before save. - ChallengeValidator func(string) error - // NextURLValidator is a validator for the "next_url" field. It is called by the builders before save. - NextURLValidator func(string) error -) - -// OrderOption defines the ordering options for the GoogleFlow queries. -type OrderOption func(*sql.Selector) - -// ByID orders the results by the id field. -func ByID(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldID, opts...).ToFunc() -} - -// ByCreatedAt orders the results by the created_at field. -func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() -} - -// ByIdentifier orders the results by the identifier field. -func ByIdentifier(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldIdentifier, opts...).ToFunc() -} - -// ByVerifier orders the results by the verifier field. -func ByVerifier(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldVerifier, opts...).ToFunc() -} - -// ByChallenge orders the results by the challenge field. -func ByChallenge(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldChallenge, opts...).ToFunc() -} - -// ByNextURL orders the results by the next_url field. -func ByNextURL(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldNextURL, opts...).ToFunc() -} - -// ByOrganization orders the results by the organization field. -func ByOrganization(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldOrganization, opts...).ToFunc() -} - -// ByDeviceIdentifier orders the results by the device_identifier field. -func ByDeviceIdentifier(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldDeviceIdentifier, opts...).ToFunc() -} diff --git a/internal/ent/googleflow/where.go b/internal/ent/googleflow/where.go deleted file mode 100644 index cf6dbed..0000000 --- a/internal/ent/googleflow/where.go +++ /dev/null @@ -1,588 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package googleflow - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id int) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldID, id)) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldID, id)) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNEQ(FieldID, id)) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldIn(FieldID, ids...)) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNotIn(FieldID, ids...)) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGT(FieldID, id)) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGTE(FieldID, id)) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLT(FieldID, id)) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLTE(FieldID, id)) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldCreatedAt, v)) -} - -// Identifier applies equality check predicate on the "identifier" field. It's identical to IdentifierEQ. -func Identifier(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldIdentifier, v)) -} - -// Verifier applies equality check predicate on the "verifier" field. It's identical to VerifierEQ. -func Verifier(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldVerifier, v)) -} - -// Challenge applies equality check predicate on the "challenge" field. It's identical to ChallengeEQ. -func Challenge(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldChallenge, v)) -} - -// NextURL applies equality check predicate on the "next_url" field. It's identical to NextURLEQ. -func NextURL(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldNextURL, v)) -} - -// Organization applies equality check predicate on the "organization" field. It's identical to OrganizationEQ. -func Organization(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldOrganization, v)) -} - -// DeviceIdentifier applies equality check predicate on the "device_identifier" field. It's identical to DeviceIdentifierEQ. -func DeviceIdentifier(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldDeviceIdentifier, v)) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldCreatedAt, v)) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNEQ(FieldCreatedAt, v)) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldIn(FieldCreatedAt, vs...)) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNotIn(FieldCreatedAt, vs...)) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGT(FieldCreatedAt, v)) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGTE(FieldCreatedAt, v)) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLT(FieldCreatedAt, v)) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLTE(FieldCreatedAt, v)) -} - -// IdentifierEQ applies the EQ predicate on the "identifier" field. -func IdentifierEQ(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldIdentifier, v)) -} - -// IdentifierNEQ applies the NEQ predicate on the "identifier" field. -func IdentifierNEQ(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNEQ(FieldIdentifier, v)) -} - -// IdentifierIn applies the In predicate on the "identifier" field. -func IdentifierIn(vs ...string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldIn(FieldIdentifier, vs...)) -} - -// IdentifierNotIn applies the NotIn predicate on the "identifier" field. -func IdentifierNotIn(vs ...string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNotIn(FieldIdentifier, vs...)) -} - -// IdentifierGT applies the GT predicate on the "identifier" field. -func IdentifierGT(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGT(FieldIdentifier, v)) -} - -// IdentifierGTE applies the GTE predicate on the "identifier" field. -func IdentifierGTE(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGTE(FieldIdentifier, v)) -} - -// IdentifierLT applies the LT predicate on the "identifier" field. -func IdentifierLT(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLT(FieldIdentifier, v)) -} - -// IdentifierLTE applies the LTE predicate on the "identifier" field. -func IdentifierLTE(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLTE(FieldIdentifier, v)) -} - -// IdentifierContains applies the Contains predicate on the "identifier" field. -func IdentifierContains(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldContains(FieldIdentifier, v)) -} - -// IdentifierHasPrefix applies the HasPrefix predicate on the "identifier" field. -func IdentifierHasPrefix(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldHasPrefix(FieldIdentifier, v)) -} - -// IdentifierHasSuffix applies the HasSuffix predicate on the "identifier" field. -func IdentifierHasSuffix(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldHasSuffix(FieldIdentifier, v)) -} - -// IdentifierEqualFold applies the EqualFold predicate on the "identifier" field. -func IdentifierEqualFold(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEqualFold(FieldIdentifier, v)) -} - -// IdentifierContainsFold applies the ContainsFold predicate on the "identifier" field. -func IdentifierContainsFold(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldContainsFold(FieldIdentifier, v)) -} - -// VerifierEQ applies the EQ predicate on the "verifier" field. -func VerifierEQ(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldVerifier, v)) -} - -// VerifierNEQ applies the NEQ predicate on the "verifier" field. -func VerifierNEQ(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNEQ(FieldVerifier, v)) -} - -// VerifierIn applies the In predicate on the "verifier" field. -func VerifierIn(vs ...string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldIn(FieldVerifier, vs...)) -} - -// VerifierNotIn applies the NotIn predicate on the "verifier" field. -func VerifierNotIn(vs ...string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNotIn(FieldVerifier, vs...)) -} - -// VerifierGT applies the GT predicate on the "verifier" field. -func VerifierGT(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGT(FieldVerifier, v)) -} - -// VerifierGTE applies the GTE predicate on the "verifier" field. -func VerifierGTE(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGTE(FieldVerifier, v)) -} - -// VerifierLT applies the LT predicate on the "verifier" field. -func VerifierLT(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLT(FieldVerifier, v)) -} - -// VerifierLTE applies the LTE predicate on the "verifier" field. -func VerifierLTE(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLTE(FieldVerifier, v)) -} - -// VerifierContains applies the Contains predicate on the "verifier" field. -func VerifierContains(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldContains(FieldVerifier, v)) -} - -// VerifierHasPrefix applies the HasPrefix predicate on the "verifier" field. -func VerifierHasPrefix(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldHasPrefix(FieldVerifier, v)) -} - -// VerifierHasSuffix applies the HasSuffix predicate on the "verifier" field. -func VerifierHasSuffix(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldHasSuffix(FieldVerifier, v)) -} - -// VerifierEqualFold applies the EqualFold predicate on the "verifier" field. -func VerifierEqualFold(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEqualFold(FieldVerifier, v)) -} - -// VerifierContainsFold applies the ContainsFold predicate on the "verifier" field. -func VerifierContainsFold(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldContainsFold(FieldVerifier, v)) -} - -// ChallengeEQ applies the EQ predicate on the "challenge" field. -func ChallengeEQ(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldChallenge, v)) -} - -// ChallengeNEQ applies the NEQ predicate on the "challenge" field. -func ChallengeNEQ(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNEQ(FieldChallenge, v)) -} - -// ChallengeIn applies the In predicate on the "challenge" field. -func ChallengeIn(vs ...string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldIn(FieldChallenge, vs...)) -} - -// ChallengeNotIn applies the NotIn predicate on the "challenge" field. -func ChallengeNotIn(vs ...string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNotIn(FieldChallenge, vs...)) -} - -// ChallengeGT applies the GT predicate on the "challenge" field. -func ChallengeGT(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGT(FieldChallenge, v)) -} - -// ChallengeGTE applies the GTE predicate on the "challenge" field. -func ChallengeGTE(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGTE(FieldChallenge, v)) -} - -// ChallengeLT applies the LT predicate on the "challenge" field. -func ChallengeLT(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLT(FieldChallenge, v)) -} - -// ChallengeLTE applies the LTE predicate on the "challenge" field. -func ChallengeLTE(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLTE(FieldChallenge, v)) -} - -// ChallengeContains applies the Contains predicate on the "challenge" field. -func ChallengeContains(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldContains(FieldChallenge, v)) -} - -// ChallengeHasPrefix applies the HasPrefix predicate on the "challenge" field. -func ChallengeHasPrefix(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldHasPrefix(FieldChallenge, v)) -} - -// ChallengeHasSuffix applies the HasSuffix predicate on the "challenge" field. -func ChallengeHasSuffix(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldHasSuffix(FieldChallenge, v)) -} - -// ChallengeEqualFold applies the EqualFold predicate on the "challenge" field. -func ChallengeEqualFold(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEqualFold(FieldChallenge, v)) -} - -// ChallengeContainsFold applies the ContainsFold predicate on the "challenge" field. -func ChallengeContainsFold(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldContainsFold(FieldChallenge, v)) -} - -// NextURLEQ applies the EQ predicate on the "next_url" field. -func NextURLEQ(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldNextURL, v)) -} - -// NextURLNEQ applies the NEQ predicate on the "next_url" field. -func NextURLNEQ(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNEQ(FieldNextURL, v)) -} - -// NextURLIn applies the In predicate on the "next_url" field. -func NextURLIn(vs ...string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldIn(FieldNextURL, vs...)) -} - -// NextURLNotIn applies the NotIn predicate on the "next_url" field. -func NextURLNotIn(vs ...string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNotIn(FieldNextURL, vs...)) -} - -// NextURLGT applies the GT predicate on the "next_url" field. -func NextURLGT(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGT(FieldNextURL, v)) -} - -// NextURLGTE applies the GTE predicate on the "next_url" field. -func NextURLGTE(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGTE(FieldNextURL, v)) -} - -// NextURLLT applies the LT predicate on the "next_url" field. -func NextURLLT(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLT(FieldNextURL, v)) -} - -// NextURLLTE applies the LTE predicate on the "next_url" field. -func NextURLLTE(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLTE(FieldNextURL, v)) -} - -// NextURLContains applies the Contains predicate on the "next_url" field. -func NextURLContains(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldContains(FieldNextURL, v)) -} - -// NextURLHasPrefix applies the HasPrefix predicate on the "next_url" field. -func NextURLHasPrefix(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldHasPrefix(FieldNextURL, v)) -} - -// NextURLHasSuffix applies the HasSuffix predicate on the "next_url" field. -func NextURLHasSuffix(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldHasSuffix(FieldNextURL, v)) -} - -// NextURLEqualFold applies the EqualFold predicate on the "next_url" field. -func NextURLEqualFold(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEqualFold(FieldNextURL, v)) -} - -// NextURLContainsFold applies the ContainsFold predicate on the "next_url" field. -func NextURLContainsFold(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldContainsFold(FieldNextURL, v)) -} - -// OrganizationEQ applies the EQ predicate on the "organization" field. -func OrganizationEQ(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldOrganization, v)) -} - -// OrganizationNEQ applies the NEQ predicate on the "organization" field. -func OrganizationNEQ(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNEQ(FieldOrganization, v)) -} - -// OrganizationIn applies the In predicate on the "organization" field. -func OrganizationIn(vs ...string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldIn(FieldOrganization, vs...)) -} - -// OrganizationNotIn applies the NotIn predicate on the "organization" field. -func OrganizationNotIn(vs ...string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNotIn(FieldOrganization, vs...)) -} - -// OrganizationGT applies the GT predicate on the "organization" field. -func OrganizationGT(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGT(FieldOrganization, v)) -} - -// OrganizationGTE applies the GTE predicate on the "organization" field. -func OrganizationGTE(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGTE(FieldOrganization, v)) -} - -// OrganizationLT applies the LT predicate on the "organization" field. -func OrganizationLT(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLT(FieldOrganization, v)) -} - -// OrganizationLTE applies the LTE predicate on the "organization" field. -func OrganizationLTE(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLTE(FieldOrganization, v)) -} - -// OrganizationContains applies the Contains predicate on the "organization" field. -func OrganizationContains(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldContains(FieldOrganization, v)) -} - -// OrganizationHasPrefix applies the HasPrefix predicate on the "organization" field. -func OrganizationHasPrefix(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldHasPrefix(FieldOrganization, v)) -} - -// OrganizationHasSuffix applies the HasSuffix predicate on the "organization" field. -func OrganizationHasSuffix(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldHasSuffix(FieldOrganization, v)) -} - -// OrganizationIsNil applies the IsNil predicate on the "organization" field. -func OrganizationIsNil() predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldIsNull(FieldOrganization)) -} - -// OrganizationNotNil applies the NotNil predicate on the "organization" field. -func OrganizationNotNil() predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNotNull(FieldOrganization)) -} - -// OrganizationEqualFold applies the EqualFold predicate on the "organization" field. -func OrganizationEqualFold(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEqualFold(FieldOrganization, v)) -} - -// OrganizationContainsFold applies the ContainsFold predicate on the "organization" field. -func OrganizationContainsFold(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldContainsFold(FieldOrganization, v)) -} - -// DeviceIdentifierEQ applies the EQ predicate on the "device_identifier" field. -func DeviceIdentifierEQ(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEQ(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierNEQ applies the NEQ predicate on the "device_identifier" field. -func DeviceIdentifierNEQ(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNEQ(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierIn applies the In predicate on the "device_identifier" field. -func DeviceIdentifierIn(vs ...string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldIn(FieldDeviceIdentifier, vs...)) -} - -// DeviceIdentifierNotIn applies the NotIn predicate on the "device_identifier" field. -func DeviceIdentifierNotIn(vs ...string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNotIn(FieldDeviceIdentifier, vs...)) -} - -// DeviceIdentifierGT applies the GT predicate on the "device_identifier" field. -func DeviceIdentifierGT(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGT(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierGTE applies the GTE predicate on the "device_identifier" field. -func DeviceIdentifierGTE(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldGTE(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierLT applies the LT predicate on the "device_identifier" field. -func DeviceIdentifierLT(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLT(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierLTE applies the LTE predicate on the "device_identifier" field. -func DeviceIdentifierLTE(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldLTE(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierContains applies the Contains predicate on the "device_identifier" field. -func DeviceIdentifierContains(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldContains(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierHasPrefix applies the HasPrefix predicate on the "device_identifier" field. -func DeviceIdentifierHasPrefix(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldHasPrefix(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierHasSuffix applies the HasSuffix predicate on the "device_identifier" field. -func DeviceIdentifierHasSuffix(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldHasSuffix(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierIsNil applies the IsNil predicate on the "device_identifier" field. -func DeviceIdentifierIsNil() predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldIsNull(FieldDeviceIdentifier)) -} - -// DeviceIdentifierNotNil applies the NotNil predicate on the "device_identifier" field. -func DeviceIdentifierNotNil() predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldNotNull(FieldDeviceIdentifier)) -} - -// DeviceIdentifierEqualFold applies the EqualFold predicate on the "device_identifier" field. -func DeviceIdentifierEqualFold(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldEqualFold(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierContainsFold applies the ContainsFold predicate on the "device_identifier" field. -func DeviceIdentifierContainsFold(v string) predicate.GoogleFlow { - return predicate.GoogleFlow(sql.FieldContainsFold(FieldDeviceIdentifier, v)) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.GoogleFlow) predicate.GoogleFlow { - return predicate.GoogleFlow(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.GoogleFlow) predicate.GoogleFlow { - return predicate.GoogleFlow(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.GoogleFlow) predicate.GoogleFlow { - return predicate.GoogleFlow(func(s *sql.Selector) { - p(s.Not()) - }) -} diff --git a/internal/ent/googleflow_create.go b/internal/ent/googleflow_create.go deleted file mode 100644 index de65ea5..0000000 --- a/internal/ent/googleflow_create.go +++ /dev/null @@ -1,322 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/googleflow" -) - -// GoogleFlowCreate is the builder for creating a GoogleFlow entity. -type GoogleFlowCreate struct { - config - mutation *GoogleFlowMutation - hooks []Hook -} - -// SetCreatedAt sets the "created_at" field. -func (gfc *GoogleFlowCreate) SetCreatedAt(t time.Time) *GoogleFlowCreate { - gfc.mutation.SetCreatedAt(t) - return gfc -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (gfc *GoogleFlowCreate) SetNillableCreatedAt(t *time.Time) *GoogleFlowCreate { - if t != nil { - gfc.SetCreatedAt(*t) - } - return gfc -} - -// SetIdentifier sets the "identifier" field. -func (gfc *GoogleFlowCreate) SetIdentifier(s string) *GoogleFlowCreate { - gfc.mutation.SetIdentifier(s) - return gfc -} - -// SetVerifier sets the "verifier" field. -func (gfc *GoogleFlowCreate) SetVerifier(s string) *GoogleFlowCreate { - gfc.mutation.SetVerifier(s) - return gfc -} - -// SetChallenge sets the "challenge" field. -func (gfc *GoogleFlowCreate) SetChallenge(s string) *GoogleFlowCreate { - gfc.mutation.SetChallenge(s) - return gfc -} - -// SetNextURL sets the "next_url" field. -func (gfc *GoogleFlowCreate) SetNextURL(s string) *GoogleFlowCreate { - gfc.mutation.SetNextURL(s) - return gfc -} - -// SetOrganization sets the "organization" field. -func (gfc *GoogleFlowCreate) SetOrganization(s string) *GoogleFlowCreate { - gfc.mutation.SetOrganization(s) - return gfc -} - -// SetNillableOrganization sets the "organization" field if the given value is not nil. -func (gfc *GoogleFlowCreate) SetNillableOrganization(s *string) *GoogleFlowCreate { - if s != nil { - gfc.SetOrganization(*s) - } - return gfc -} - -// SetDeviceIdentifier sets the "device_identifier" field. -func (gfc *GoogleFlowCreate) SetDeviceIdentifier(s string) *GoogleFlowCreate { - gfc.mutation.SetDeviceIdentifier(s) - return gfc -} - -// SetNillableDeviceIdentifier sets the "device_identifier" field if the given value is not nil. -func (gfc *GoogleFlowCreate) SetNillableDeviceIdentifier(s *string) *GoogleFlowCreate { - if s != nil { - gfc.SetDeviceIdentifier(*s) - } - return gfc -} - -// Mutation returns the GoogleFlowMutation object of the builder. -func (gfc *GoogleFlowCreate) Mutation() *GoogleFlowMutation { - return gfc.mutation -} - -// Save creates the GoogleFlow in the database. -func (gfc *GoogleFlowCreate) Save(ctx context.Context) (*GoogleFlow, error) { - gfc.defaults() - return withHooks(ctx, gfc.sqlSave, gfc.mutation, gfc.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (gfc *GoogleFlowCreate) SaveX(ctx context.Context) *GoogleFlow { - v, err := gfc.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (gfc *GoogleFlowCreate) Exec(ctx context.Context) error { - _, err := gfc.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (gfc *GoogleFlowCreate) ExecX(ctx context.Context) { - if err := gfc.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (gfc *GoogleFlowCreate) defaults() { - if _, ok := gfc.mutation.CreatedAt(); !ok { - v := googleflow.DefaultCreatedAt() - gfc.mutation.SetCreatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (gfc *GoogleFlowCreate) check() error { - if _, ok := gfc.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "GoogleFlow.created_at"`)} - } - if _, ok := gfc.mutation.Identifier(); !ok { - return &ValidationError{Name: "identifier", err: errors.New(`ent: missing required field "GoogleFlow.identifier"`)} - } - if v, ok := gfc.mutation.Identifier(); ok { - if err := googleflow.IdentifierValidator(v); err != nil { - return &ValidationError{Name: "identifier", err: fmt.Errorf(`ent: validator failed for field "GoogleFlow.identifier": %w`, err)} - } - } - if _, ok := gfc.mutation.Verifier(); !ok { - return &ValidationError{Name: "verifier", err: errors.New(`ent: missing required field "GoogleFlow.verifier"`)} - } - if v, ok := gfc.mutation.Verifier(); ok { - if err := googleflow.VerifierValidator(v); err != nil { - return &ValidationError{Name: "verifier", err: fmt.Errorf(`ent: validator failed for field "GoogleFlow.verifier": %w`, err)} - } - } - if _, ok := gfc.mutation.Challenge(); !ok { - return &ValidationError{Name: "challenge", err: errors.New(`ent: missing required field "GoogleFlow.challenge"`)} - } - if v, ok := gfc.mutation.Challenge(); ok { - if err := googleflow.ChallengeValidator(v); err != nil { - return &ValidationError{Name: "challenge", err: fmt.Errorf(`ent: validator failed for field "GoogleFlow.challenge": %w`, err)} - } - } - if _, ok := gfc.mutation.NextURL(); !ok { - return &ValidationError{Name: "next_url", err: errors.New(`ent: missing required field "GoogleFlow.next_url"`)} - } - if v, ok := gfc.mutation.NextURL(); ok { - if err := googleflow.NextURLValidator(v); err != nil { - return &ValidationError{Name: "next_url", err: fmt.Errorf(`ent: validator failed for field "GoogleFlow.next_url": %w`, err)} - } - } - return nil -} - -func (gfc *GoogleFlowCreate) sqlSave(ctx context.Context) (*GoogleFlow, error) { - if err := gfc.check(); err != nil { - return nil, err - } - _node, _spec := gfc.createSpec() - if err := sqlgraph.CreateNode(ctx, gfc.driver, _spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - id := _spec.ID.Value.(int64) - _node.ID = int(id) - gfc.mutation.id = &_node.ID - gfc.mutation.done = true - return _node, nil -} - -func (gfc *GoogleFlowCreate) createSpec() (*GoogleFlow, *sqlgraph.CreateSpec) { - var ( - _node = &GoogleFlow{config: gfc.config} - _spec = sqlgraph.NewCreateSpec(googleflow.Table, sqlgraph.NewFieldSpec(googleflow.FieldID, field.TypeInt)) - ) - if value, ok := gfc.mutation.CreatedAt(); ok { - _spec.SetField(googleflow.FieldCreatedAt, field.TypeTime, value) - _node.CreatedAt = value - } - if value, ok := gfc.mutation.Identifier(); ok { - _spec.SetField(googleflow.FieldIdentifier, field.TypeString, value) - _node.Identifier = value - } - if value, ok := gfc.mutation.Verifier(); ok { - _spec.SetField(googleflow.FieldVerifier, field.TypeString, value) - _node.Verifier = value - } - if value, ok := gfc.mutation.Challenge(); ok { - _spec.SetField(googleflow.FieldChallenge, field.TypeString, value) - _node.Challenge = value - } - if value, ok := gfc.mutation.NextURL(); ok { - _spec.SetField(googleflow.FieldNextURL, field.TypeString, value) - _node.NextURL = value - } - if value, ok := gfc.mutation.Organization(); ok { - _spec.SetField(googleflow.FieldOrganization, field.TypeString, value) - _node.Organization = value - } - if value, ok := gfc.mutation.DeviceIdentifier(); ok { - _spec.SetField(googleflow.FieldDeviceIdentifier, field.TypeString, value) - _node.DeviceIdentifier = value - } - return _node, _spec -} - -// GoogleFlowCreateBulk is the builder for creating many GoogleFlow entities in bulk. -type GoogleFlowCreateBulk struct { - config - builders []*GoogleFlowCreate -} - -// Save creates the GoogleFlow entities in the database. -func (gfcb *GoogleFlowCreateBulk) Save(ctx context.Context) ([]*GoogleFlow, error) { - specs := make([]*sqlgraph.CreateSpec, len(gfcb.builders)) - nodes := make([]*GoogleFlow, len(gfcb.builders)) - mutators := make([]Mutator, len(gfcb.builders)) - for i := range gfcb.builders { - func(i int, root context.Context) { - builder := gfcb.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*GoogleFlowMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - var err error - nodes[i], specs[i] = builder.createSpec() - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, gfcb.builders[i+1].mutation) - } else { - spec := &sqlgraph.BatchCreateSpec{Nodes: specs} - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, gfcb.driver, spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - } - } - if err != nil { - return nil, err - } - mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) - } - mutation.done = true - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, gfcb.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (gfcb *GoogleFlowCreateBulk) SaveX(ctx context.Context) []*GoogleFlow { - v, err := gfcb.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (gfcb *GoogleFlowCreateBulk) Exec(ctx context.Context) error { - _, err := gfcb.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (gfcb *GoogleFlowCreateBulk) ExecX(ctx context.Context) { - if err := gfcb.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/internal/ent/googleflow_delete.go b/internal/ent/googleflow_delete.go deleted file mode 100644 index 150a9f4..0000000 --- a/internal/ent/googleflow_delete.go +++ /dev/null @@ -1,104 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/googleflow" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// GoogleFlowDelete is the builder for deleting a GoogleFlow entity. -type GoogleFlowDelete struct { - config - hooks []Hook - mutation *GoogleFlowMutation -} - -// Where appends a list predicates to the GoogleFlowDelete builder. -func (gfd *GoogleFlowDelete) Where(ps ...predicate.GoogleFlow) *GoogleFlowDelete { - gfd.mutation.Where(ps...) - return gfd -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (gfd *GoogleFlowDelete) Exec(ctx context.Context) (int, error) { - return withHooks(ctx, gfd.sqlExec, gfd.mutation, gfd.hooks) -} - -// ExecX is like Exec, but panics if an error occurs. -func (gfd *GoogleFlowDelete) ExecX(ctx context.Context) int { - n, err := gfd.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (gfd *GoogleFlowDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(googleflow.Table, sqlgraph.NewFieldSpec(googleflow.FieldID, field.TypeInt)) - if ps := gfd.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - affected, err := sqlgraph.DeleteNodes(ctx, gfd.driver, _spec) - if err != nil && sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - gfd.mutation.done = true - return affected, err -} - -// GoogleFlowDeleteOne is the builder for deleting a single GoogleFlow entity. -type GoogleFlowDeleteOne struct { - gfd *GoogleFlowDelete -} - -// Where appends a list predicates to the GoogleFlowDelete builder. -func (gfdo *GoogleFlowDeleteOne) Where(ps ...predicate.GoogleFlow) *GoogleFlowDeleteOne { - gfdo.gfd.mutation.Where(ps...) - return gfdo -} - -// Exec executes the deletion query. -func (gfdo *GoogleFlowDeleteOne) Exec(ctx context.Context) error { - n, err := gfdo.gfd.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{googleflow.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (gfdo *GoogleFlowDeleteOne) ExecX(ctx context.Context) { - if err := gfdo.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/internal/ent/googleflow_query.go b/internal/ent/googleflow_query.go deleted file mode 100644 index c993a28..0000000 --- a/internal/ent/googleflow_query.go +++ /dev/null @@ -1,542 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "math" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/googleflow" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// GoogleFlowQuery is the builder for querying GoogleFlow entities. -type GoogleFlowQuery struct { - config - ctx *QueryContext - order []googleflow.OrderOption - inters []Interceptor - predicates []predicate.GoogleFlow - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the GoogleFlowQuery builder. -func (gfq *GoogleFlowQuery) Where(ps ...predicate.GoogleFlow) *GoogleFlowQuery { - gfq.predicates = append(gfq.predicates, ps...) - return gfq -} - -// Limit the number of records to be returned by this query. -func (gfq *GoogleFlowQuery) Limit(limit int) *GoogleFlowQuery { - gfq.ctx.Limit = &limit - return gfq -} - -// Offset to start from. -func (gfq *GoogleFlowQuery) Offset(offset int) *GoogleFlowQuery { - gfq.ctx.Offset = &offset - return gfq -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (gfq *GoogleFlowQuery) Unique(unique bool) *GoogleFlowQuery { - gfq.ctx.Unique = &unique - return gfq -} - -// Order specifies how the records should be ordered. -func (gfq *GoogleFlowQuery) Order(o ...googleflow.OrderOption) *GoogleFlowQuery { - gfq.order = append(gfq.order, o...) - return gfq -} - -// First returns the first GoogleFlow entity from the query. -// Returns a *NotFoundError when no GoogleFlow was found. -func (gfq *GoogleFlowQuery) First(ctx context.Context) (*GoogleFlow, error) { - nodes, err := gfq.Limit(1).All(setContextOp(ctx, gfq.ctx, "First")) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{googleflow.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (gfq *GoogleFlowQuery) FirstX(ctx context.Context) *GoogleFlow { - node, err := gfq.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first GoogleFlow ID from the query. -// Returns a *NotFoundError when no GoogleFlow ID was found. -func (gfq *GoogleFlowQuery) FirstID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = gfq.Limit(1).IDs(setContextOp(ctx, gfq.ctx, "FirstID")); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{googleflow.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (gfq *GoogleFlowQuery) FirstIDX(ctx context.Context) int { - id, err := gfq.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single GoogleFlow entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one GoogleFlow entity is found. -// Returns a *NotFoundError when no GoogleFlow entities are found. -func (gfq *GoogleFlowQuery) Only(ctx context.Context) (*GoogleFlow, error) { - nodes, err := gfq.Limit(2).All(setContextOp(ctx, gfq.ctx, "Only")) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{googleflow.Label} - default: - return nil, &NotSingularError{googleflow.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (gfq *GoogleFlowQuery) OnlyX(ctx context.Context) *GoogleFlow { - node, err := gfq.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only GoogleFlow ID in the query. -// Returns a *NotSingularError when more than one GoogleFlow ID is found. -// Returns a *NotFoundError when no entities are found. -func (gfq *GoogleFlowQuery) OnlyID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = gfq.Limit(2).IDs(setContextOp(ctx, gfq.ctx, "OnlyID")); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{googleflow.Label} - default: - err = &NotSingularError{googleflow.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (gfq *GoogleFlowQuery) OnlyIDX(ctx context.Context) int { - id, err := gfq.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of GoogleFlows. -func (gfq *GoogleFlowQuery) All(ctx context.Context) ([]*GoogleFlow, error) { - ctx = setContextOp(ctx, gfq.ctx, "All") - if err := gfq.prepareQuery(ctx); err != nil { - return nil, err - } - qr := querierAll[[]*GoogleFlow, *GoogleFlowQuery]() - return withInterceptors[[]*GoogleFlow](ctx, gfq, qr, gfq.inters) -} - -// AllX is like All, but panics if an error occurs. -func (gfq *GoogleFlowQuery) AllX(ctx context.Context) []*GoogleFlow { - nodes, err := gfq.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of GoogleFlow IDs. -func (gfq *GoogleFlowQuery) IDs(ctx context.Context) (ids []int, err error) { - if gfq.ctx.Unique == nil && gfq.path != nil { - gfq.Unique(true) - } - ctx = setContextOp(ctx, gfq.ctx, "IDs") - if err = gfq.Select(googleflow.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (gfq *GoogleFlowQuery) IDsX(ctx context.Context) []int { - ids, err := gfq.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (gfq *GoogleFlowQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, gfq.ctx, "Count") - if err := gfq.prepareQuery(ctx); err != nil { - return 0, err - } - return withInterceptors[int](ctx, gfq, querierCount[*GoogleFlowQuery](), gfq.inters) -} - -// CountX is like Count, but panics if an error occurs. -func (gfq *GoogleFlowQuery) CountX(ctx context.Context) int { - count, err := gfq.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (gfq *GoogleFlowQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, gfq.ctx, "Exist") - switch _, err := gfq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - -// ExistX is like Exist, but panics if an error occurs. -func (gfq *GoogleFlowQuery) ExistX(ctx context.Context) bool { - exist, err := gfq.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the GoogleFlowQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (gfq *GoogleFlowQuery) Clone() *GoogleFlowQuery { - if gfq == nil { - return nil - } - return &GoogleFlowQuery{ - config: gfq.config, - ctx: gfq.ctx.Clone(), - order: append([]googleflow.OrderOption{}, gfq.order...), - inters: append([]Interceptor{}, gfq.inters...), - predicates: append([]predicate.GoogleFlow{}, gfq.predicates...), - // clone intermediate query. - sql: gfq.sql.Clone(), - path: gfq.path, - } -} - -// 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: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.GoogleFlow.Query(). -// GroupBy(googleflow.FieldCreatedAt). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -func (gfq *GoogleFlowQuery) GroupBy(field string, fields ...string) *GoogleFlowGroupBy { - gfq.ctx.Fields = append([]string{field}, fields...) - grbuild := &GoogleFlowGroupBy{build: gfq} - grbuild.flds = &gfq.ctx.Fields - grbuild.label = googleflow.Label - grbuild.scan = grbuild.Scan - return grbuild -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// } -// -// client.GoogleFlow.Query(). -// Select(googleflow.FieldCreatedAt). -// Scan(ctx, &v) -func (gfq *GoogleFlowQuery) Select(fields ...string) *GoogleFlowSelect { - gfq.ctx.Fields = append(gfq.ctx.Fields, fields...) - sbuild := &GoogleFlowSelect{GoogleFlowQuery: gfq} - sbuild.label = googleflow.Label - sbuild.flds, sbuild.scan = &gfq.ctx.Fields, sbuild.Scan - return sbuild -} - -// Aggregate returns a GoogleFlowSelect configured with the given aggregations. -func (gfq *GoogleFlowQuery) Aggregate(fns ...AggregateFunc) *GoogleFlowSelect { - return gfq.Select().Aggregate(fns...) -} - -func (gfq *GoogleFlowQuery) prepareQuery(ctx context.Context) error { - for _, inter := range gfq.inters { - if inter == nil { - return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") - } - if trv, ok := inter.(Traverser); ok { - if err := trv.Traverse(ctx, gfq); err != nil { - return err - } - } - } - for _, f := range gfq.ctx.Fields { - if !googleflow.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if gfq.path != nil { - prev, err := gfq.path(ctx) - if err != nil { - return err - } - gfq.sql = prev - } - return nil -} - -func (gfq *GoogleFlowQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*GoogleFlow, error) { - var ( - nodes = []*GoogleFlow{} - _spec = gfq.querySpec() - ) - _spec.ScanValues = func(columns []string) ([]any, error) { - return (*GoogleFlow).scanValues(nil, columns) - } - _spec.Assign = func(columns []string, values []any) error { - node := &GoogleFlow{config: gfq.config} - nodes = append(nodes, node) - return node.assignValues(columns, values) - } - for i := range hooks { - hooks[i](ctx, _spec) - } - if err := sqlgraph.QueryNodes(ctx, gfq.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - return nodes, nil -} - -func (gfq *GoogleFlowQuery) sqlCount(ctx context.Context) (int, error) { - _spec := gfq.querySpec() - _spec.Node.Columns = gfq.ctx.Fields - if len(gfq.ctx.Fields) > 0 { - _spec.Unique = gfq.ctx.Unique != nil && *gfq.ctx.Unique - } - return sqlgraph.CountNodes(ctx, gfq.driver, _spec) -} - -func (gfq *GoogleFlowQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(googleflow.Table, googleflow.Columns, sqlgraph.NewFieldSpec(googleflow.FieldID, field.TypeInt)) - _spec.From = gfq.sql - if unique := gfq.ctx.Unique; unique != nil { - _spec.Unique = *unique - } else if gfq.path != nil { - _spec.Unique = true - } - if fields := gfq.ctx.Fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, googleflow.FieldID) - for i := range fields { - if fields[i] != googleflow.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := gfq.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := gfq.ctx.Limit; limit != nil { - _spec.Limit = *limit - } - if offset := gfq.ctx.Offset; offset != nil { - _spec.Offset = *offset - } - if ps := gfq.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (gfq *GoogleFlowQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(gfq.driver.Dialect()) - t1 := builder.Table(googleflow.Table) - columns := gfq.ctx.Fields - if len(columns) == 0 { - columns = googleflow.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if gfq.sql != nil { - selector = gfq.sql - selector.Select(selector.Columns(columns...)...) - } - if gfq.ctx.Unique != nil && *gfq.ctx.Unique { - selector.Distinct() - } - for _, p := range gfq.predicates { - p(selector) - } - for _, p := range gfq.order { - p(selector) - } - if offset := gfq.ctx.Offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := gfq.ctx.Limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// GoogleFlowGroupBy is the group-by builder for GoogleFlow entities. -type GoogleFlowGroupBy struct { - selector - build *GoogleFlowQuery -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (gfgb *GoogleFlowGroupBy) Aggregate(fns ...AggregateFunc) *GoogleFlowGroupBy { - gfgb.fns = append(gfgb.fns, fns...) - return gfgb -} - -// Scan applies the selector query and scans the result into the given value. -func (gfgb *GoogleFlowGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, gfgb.build.ctx, "GroupBy") - if err := gfgb.build.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*GoogleFlowQuery, *GoogleFlowGroupBy](ctx, gfgb.build, gfgb, gfgb.build.inters, v) -} - -func (gfgb *GoogleFlowGroupBy) sqlScan(ctx context.Context, root *GoogleFlowQuery, v any) error { - selector := root.sqlQuery(ctx).Select() - aggregation := make([]string, 0, len(gfgb.fns)) - for _, fn := range gfgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(*gfgb.flds)+len(gfgb.fns)) - for _, f := range *gfgb.flds { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - selector.GroupBy(selector.Columns(*gfgb.flds...)...) - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := gfgb.build.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -// GoogleFlowSelect is the builder for selecting fields of GoogleFlow entities. -type GoogleFlowSelect struct { - *GoogleFlowQuery - selector -} - -// Aggregate adds the given aggregation functions to the selector query. -func (gfs *GoogleFlowSelect) Aggregate(fns ...AggregateFunc) *GoogleFlowSelect { - gfs.fns = append(gfs.fns, fns...) - return gfs -} - -// Scan applies the selector query and scans the result into the given value. -func (gfs *GoogleFlowSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, gfs.ctx, "Select") - if err := gfs.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*GoogleFlowQuery, *GoogleFlowSelect](ctx, gfs.GoogleFlowQuery, gfs, gfs.inters, v) -} - -func (gfs *GoogleFlowSelect) sqlScan(ctx context.Context, root *GoogleFlowQuery, v any) error { - selector := root.sqlQuery(ctx) - aggregation := make([]string, 0, len(gfs.fns)) - for _, fn := range gfs.fns { - aggregation = append(aggregation, fn(selector)) - } - switch n := len(*gfs.selector.flds); { - case n == 0 && len(aggregation) > 0: - selector.Select(aggregation...) - case n != 0 && len(aggregation) > 0: - selector.AppendSelect(aggregation...) - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := gfs.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/internal/ent/googleflow_update.go b/internal/ent/googleflow_update.go deleted file mode 100644 index 8184379..0000000 --- a/internal/ent/googleflow_update.go +++ /dev/null @@ -1,203 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/googleflow" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// GoogleFlowUpdate is the builder for updating GoogleFlow entities. -type GoogleFlowUpdate struct { - config - hooks []Hook - mutation *GoogleFlowMutation -} - -// Where appends a list predicates to the GoogleFlowUpdate builder. -func (gfu *GoogleFlowUpdate) Where(ps ...predicate.GoogleFlow) *GoogleFlowUpdate { - gfu.mutation.Where(ps...) - return gfu -} - -// Mutation returns the GoogleFlowMutation object of the builder. -func (gfu *GoogleFlowUpdate) Mutation() *GoogleFlowMutation { - return gfu.mutation -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (gfu *GoogleFlowUpdate) Save(ctx context.Context) (int, error) { - return withHooks(ctx, gfu.sqlSave, gfu.mutation, gfu.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (gfu *GoogleFlowUpdate) SaveX(ctx context.Context) int { - affected, err := gfu.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (gfu *GoogleFlowUpdate) Exec(ctx context.Context) error { - _, err := gfu.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (gfu *GoogleFlowUpdate) ExecX(ctx context.Context) { - if err := gfu.Exec(ctx); err != nil { - panic(err) - } -} - -func (gfu *GoogleFlowUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := sqlgraph.NewUpdateSpec(googleflow.Table, googleflow.Columns, sqlgraph.NewFieldSpec(googleflow.FieldID, field.TypeInt)) - if ps := gfu.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if gfu.mutation.OrganizationCleared() { - _spec.ClearField(googleflow.FieldOrganization, field.TypeString) - } - if gfu.mutation.DeviceIdentifierCleared() { - _spec.ClearField(googleflow.FieldDeviceIdentifier, field.TypeString) - } - if n, err = sqlgraph.UpdateNodes(ctx, gfu.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{googleflow.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - gfu.mutation.done = true - return n, nil -} - -// GoogleFlowUpdateOne is the builder for updating a single GoogleFlow entity. -type GoogleFlowUpdateOne struct { - config - fields []string - hooks []Hook - mutation *GoogleFlowMutation -} - -// Mutation returns the GoogleFlowMutation object of the builder. -func (gfuo *GoogleFlowUpdateOne) Mutation() *GoogleFlowMutation { - return gfuo.mutation -} - -// Where appends a list predicates to the GoogleFlowUpdate builder. -func (gfuo *GoogleFlowUpdateOne) Where(ps ...predicate.GoogleFlow) *GoogleFlowUpdateOne { - gfuo.mutation.Where(ps...) - return gfuo -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (gfuo *GoogleFlowUpdateOne) Select(field string, fields ...string) *GoogleFlowUpdateOne { - gfuo.fields = append([]string{field}, fields...) - return gfuo -} - -// Save executes the query and returns the updated GoogleFlow entity. -func (gfuo *GoogleFlowUpdateOne) Save(ctx context.Context) (*GoogleFlow, error) { - return withHooks(ctx, gfuo.sqlSave, gfuo.mutation, gfuo.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (gfuo *GoogleFlowUpdateOne) SaveX(ctx context.Context) *GoogleFlow { - node, err := gfuo.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (gfuo *GoogleFlowUpdateOne) Exec(ctx context.Context) error { - _, err := gfuo.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (gfuo *GoogleFlowUpdateOne) ExecX(ctx context.Context) { - if err := gfuo.Exec(ctx); err != nil { - panic(err) - } -} - -func (gfuo *GoogleFlowUpdateOne) sqlSave(ctx context.Context) (_node *GoogleFlow, err error) { - _spec := sqlgraph.NewUpdateSpec(googleflow.Table, googleflow.Columns, sqlgraph.NewFieldSpec(googleflow.FieldID, field.TypeInt)) - id, ok := gfuo.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "GoogleFlow.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := gfuo.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, googleflow.FieldID) - for _, f := range fields { - if !googleflow.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != googleflow.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := gfuo.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if gfuo.mutation.OrganizationCleared() { - _spec.ClearField(googleflow.FieldOrganization, field.TypeString) - } - if gfuo.mutation.DeviceIdentifierCleared() { - _spec.ClearField(googleflow.FieldDeviceIdentifier, field.TypeString) - } - _node = &GoogleFlow{config: gfuo.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, gfuo.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{googleflow.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - gfuo.mutation.done = true - return _node, nil -} diff --git a/internal/ent/hook/hook.go b/internal/ent/hook/hook.go deleted file mode 100644 index 3247930..0000000 --- a/internal/ent/hook/hook.go +++ /dev/null @@ -1,251 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package hook - -import ( - "context" - "fmt" - - "github.com/loopholelabs/auth/internal/ent" -) - -// The DeviceFlowFunc type is an adapter to allow the use of ordinary -// function as DeviceFlow mutator. -type DeviceFlowFunc func(context.Context, *ent.DeviceFlowMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f DeviceFlowFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if mv, ok := m.(*ent.DeviceFlowMutation); ok { - return f(ctx, mv) - } - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.DeviceFlowMutation", m) -} - -// The GithubFlowFunc type is an adapter to allow the use of ordinary -// function as GithubFlow mutator. -type GithubFlowFunc func(context.Context, *ent.GithubFlowMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f GithubFlowFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if mv, ok := m.(*ent.GithubFlowMutation); ok { - return f(ctx, mv) - } - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GithubFlowMutation", m) -} - -// The GoogleFlowFunc type is an adapter to allow the use of ordinary -// function as GoogleFlow mutator. -type GoogleFlowFunc func(context.Context, *ent.GoogleFlowMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f GoogleFlowFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if mv, ok := m.(*ent.GoogleFlowMutation); ok { - return f(ctx, mv) - } - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GoogleFlowMutation", m) -} - -// The MagicFlowFunc type is an adapter to allow the use of ordinary -// function as MagicFlow mutator. -type MagicFlowFunc func(context.Context, *ent.MagicFlowMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f MagicFlowFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if mv, ok := m.(*ent.MagicFlowMutation); ok { - return f(ctx, mv) - } - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MagicFlowMutation", m) -} - -// Condition is a hook condition function. -type Condition func(context.Context, ent.Mutation) bool - -// And groups conditions with the AND operator. -func And(first, second Condition, rest ...Condition) Condition { - return func(ctx context.Context, m ent.Mutation) bool { - if !first(ctx, m) || !second(ctx, m) { - return false - } - for _, cond := range rest { - if !cond(ctx, m) { - return false - } - } - return true - } -} - -// Or groups conditions with the OR operator. -func Or(first, second Condition, rest ...Condition) Condition { - return func(ctx context.Context, m ent.Mutation) bool { - if first(ctx, m) || second(ctx, m) { - return true - } - for _, cond := range rest { - if cond(ctx, m) { - return true - } - } - return false - } -} - -// Not negates a given condition. -func Not(cond Condition) Condition { - return func(ctx context.Context, m ent.Mutation) bool { - return !cond(ctx, m) - } -} - -// HasOp is a condition testing mutation operation. -func HasOp(op ent.Op) Condition { - return func(_ context.Context, m ent.Mutation) bool { - return m.Op().Is(op) - } -} - -// HasAddedFields is a condition validating `.AddedField` on fields. -func HasAddedFields(field string, fields ...string) Condition { - return func(_ context.Context, m ent.Mutation) bool { - if _, exists := m.AddedField(field); !exists { - return false - } - for _, field := range fields { - if _, exists := m.AddedField(field); !exists { - return false - } - } - return true - } -} - -// HasClearedFields is a condition validating `.FieldCleared` on fields. -func HasClearedFields(field string, fields ...string) Condition { - return func(_ context.Context, m ent.Mutation) bool { - if exists := m.FieldCleared(field); !exists { - return false - } - for _, field := range fields { - if exists := m.FieldCleared(field); !exists { - return false - } - } - return true - } -} - -// HasFields is a condition validating `.Field` on fields. -func HasFields(field string, fields ...string) Condition { - return func(_ context.Context, m ent.Mutation) bool { - if _, exists := m.Field(field); !exists { - return false - } - for _, field := range fields { - if _, exists := m.Field(field); !exists { - return false - } - } - return true - } -} - -// If executes the given hook under condition. -// -// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...))) -func If(hk ent.Hook, cond Condition) ent.Hook { - return func(next ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if cond(ctx, m) { - return hk(next).Mutate(ctx, m) - } - return next.Mutate(ctx, m) - }) - } -} - -// On executes the given hook only for the given operation. -// -// hook.On(Log, ent.Delete|ent.Create) -func On(hk ent.Hook, op ent.Op) ent.Hook { - return If(hk, HasOp(op)) -} - -// Unless skips the given hook only for the given operation. -// -// hook.Unless(Log, ent.Update|ent.UpdateOne) -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 { -// return []ent.Hook{ -// Reject(ent.Delete|ent.Update), -// } -// } -func Reject(op ent.Op) ent.Hook { - hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) - return On(hk, op) -} - -// Chain acts as a list of hooks and is effectively immutable. -// Once created, it will always hold the same set of hooks in the same order. -type Chain struct { - hooks []ent.Hook -} - -// NewChain creates a new chain of hooks. -func NewChain(hooks ...ent.Hook) Chain { - return Chain{append([]ent.Hook(nil), hooks...)} -} - -// Hook chains the list of hooks and returns the final hook. -func (c Chain) Hook() ent.Hook { - return func(mutator ent.Mutator) ent.Mutator { - for i := len(c.hooks) - 1; i >= 0; i-- { - mutator = c.hooks[i](mutator) - } - return mutator - } -} - -// Append extends a chain, adding the specified hook -// as the last ones in the mutation flow. -func (c Chain) Append(hooks ...ent.Hook) Chain { - newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks)) - newHooks = append(newHooks, c.hooks...) - newHooks = append(newHooks, hooks...) - return Chain{newHooks} -} - -// Extend extends a chain, adding the specified chain -// as the last ones in the mutation flow. -func (c Chain) Extend(chain Chain) Chain { - return c.Append(chain.hooks...) -} diff --git a/internal/ent/magicflow.go b/internal/ent/magicflow.go deleted file mode 100644 index 633587a..0000000 --- a/internal/ent/magicflow.go +++ /dev/null @@ -1,199 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "github.com/loopholelabs/auth/internal/ent/magicflow" -) - -// MagicFlow is the model entity for the MagicFlow schema. -type MagicFlow struct { - config `json:"-"` - // ID of the ent. - ID int `json:"id,omitempty"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at,omitempty"` - // Identifier holds the value of the "identifier" field. - Identifier string `json:"identifier,omitempty"` - // Email holds the value of the "email" field. - Email string `json:"email,omitempty"` - // IPAddress holds the value of the "ip_address" field. - IPAddress string `json:"ip_address,omitempty"` - // Secret holds the value of the "secret" field. - Secret string `json:"secret,omitempty"` - // NextURL holds the value of the "next_url" field. - NextURL string `json:"next_url,omitempty"` - // Organization holds the value of the "organization" field. - Organization string `json:"organization,omitempty"` - // DeviceIdentifier holds the value of the "device_identifier" field. - DeviceIdentifier string `json:"device_identifier,omitempty"` - selectValues sql.SelectValues -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*MagicFlow) scanValues(columns []string) ([]any, error) { - values := make([]any, len(columns)) - for i := range columns { - switch columns[i] { - case magicflow.FieldID: - values[i] = new(sql.NullInt64) - case magicflow.FieldIdentifier, magicflow.FieldEmail, magicflow.FieldIPAddress, magicflow.FieldSecret, magicflow.FieldNextURL, magicflow.FieldOrganization, magicflow.FieldDeviceIdentifier: - values[i] = new(sql.NullString) - case magicflow.FieldCreatedAt: - values[i] = new(sql.NullTime) - default: - values[i] = new(sql.UnknownType) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the MagicFlow fields. -func (mf *MagicFlow) assignValues(columns []string, values []any) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case magicflow.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - mf.ID = int(value.Int64) - case magicflow.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 { - mf.CreatedAt = value.Time - } - case magicflow.FieldIdentifier: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field identifier", values[i]) - } else if value.Valid { - mf.Identifier = value.String - } - case magicflow.FieldEmail: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field email", values[i]) - } else if value.Valid { - mf.Email = value.String - } - case magicflow.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 { - mf.IPAddress = value.String - } - case magicflow.FieldSecret: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field secret", values[i]) - } else if value.Valid { - mf.Secret = value.String - } - case magicflow.FieldNextURL: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field next_url", values[i]) - } else if value.Valid { - mf.NextURL = value.String - } - case magicflow.FieldOrganization: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field organization", values[i]) - } else if value.Valid { - mf.Organization = value.String - } - case magicflow.FieldDeviceIdentifier: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field device_identifier", values[i]) - } else if value.Valid { - mf.DeviceIdentifier = value.String - } - default: - mf.selectValues.Set(columns[i], values[i]) - } - } - return nil -} - -// Value returns the ent.Value that was dynamically selected and assigned to the MagicFlow. -// This includes values selected through modifiers, order, etc. -func (mf *MagicFlow) Value(name string) (ent.Value, error) { - return mf.selectValues.Get(name) -} - -// Update returns a builder for updating this MagicFlow. -// Note that you need to call MagicFlow.Unwrap() before calling this method if this MagicFlow -// was returned from a transaction, and the transaction was committed or rolled back. -func (mf *MagicFlow) Update() *MagicFlowUpdateOne { - return NewMagicFlowClient(mf.config).UpdateOne(mf) -} - -// Unwrap unwraps the MagicFlow 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 (mf *MagicFlow) Unwrap() *MagicFlow { - _tx, ok := mf.config.driver.(*txDriver) - if !ok { - panic("ent: MagicFlow is not a transactional entity") - } - mf.config.driver = _tx.drv - return mf -} - -// String implements the fmt.Stringer. -func (mf *MagicFlow) String() string { - var builder strings.Builder - builder.WriteString("MagicFlow(") - builder.WriteString(fmt.Sprintf("id=%v, ", mf.ID)) - builder.WriteString("created_at=") - builder.WriteString(mf.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("identifier=") - builder.WriteString(mf.Identifier) - builder.WriteString(", ") - builder.WriteString("email=") - builder.WriteString(mf.Email) - builder.WriteString(", ") - builder.WriteString("ip_address=") - builder.WriteString(mf.IPAddress) - builder.WriteString(", ") - builder.WriteString("secret=") - builder.WriteString(mf.Secret) - builder.WriteString(", ") - builder.WriteString("next_url=") - builder.WriteString(mf.NextURL) - builder.WriteString(", ") - builder.WriteString("organization=") - builder.WriteString(mf.Organization) - builder.WriteString(", ") - builder.WriteString("device_identifier=") - builder.WriteString(mf.DeviceIdentifier) - builder.WriteByte(')') - return builder.String() -} - -// MagicFlows is a parsable slice of MagicFlow. -type MagicFlows []*MagicFlow diff --git a/internal/ent/magicflow/magicflow.go b/internal/ent/magicflow/magicflow.go deleted file mode 100644 index 0876aff..0000000 --- a/internal/ent/magicflow/magicflow.go +++ /dev/null @@ -1,136 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package magicflow - -import ( - "time" - - "entgo.io/ent/dialect/sql" -) - -const ( - // Label holds the string label denoting the magicflow type in the database. - Label = "magic_flow" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldCreatedAt holds the string denoting the created_at field in the database. - FieldCreatedAt = "created_at" - // FieldIdentifier holds the string denoting the identifier field in the database. - FieldIdentifier = "identifier" - // FieldEmail holds the string denoting the email field in the database. - FieldEmail = "email" - // FieldIPAddress holds the string denoting the ip_address field in the database. - FieldIPAddress = "ip_address" - // FieldSecret holds the string denoting the secret field in the database. - FieldSecret = "secret" - // FieldNextURL holds the string denoting the next_url field in the database. - FieldNextURL = "next_url" - // FieldOrganization holds the string denoting the organization field in the database. - FieldOrganization = "organization" - // FieldDeviceIdentifier holds the string denoting the device_identifier field in the database. - FieldDeviceIdentifier = "device_identifier" - // Table holds the table name of the magicflow in the database. - Table = "magic_flows" -) - -// Columns holds all SQL columns for magicflow fields. -var Columns = []string{ - FieldID, - FieldCreatedAt, - FieldIdentifier, - FieldEmail, - FieldIPAddress, - FieldSecret, - FieldNextURL, - FieldOrganization, - FieldDeviceIdentifier, -} - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} - -var ( - // DefaultCreatedAt holds the default value on creation for the "created_at" field. - DefaultCreatedAt func() time.Time - // IdentifierValidator is a validator for the "identifier" field. It is called by the builders before save. - IdentifierValidator func(string) error - // EmailValidator is a validator for the "email" field. It is called by the builders before save. - EmailValidator func(string) error - // IPAddressValidator is a validator for the "ip_address" field. It is called by the builders before save. - IPAddressValidator func(string) error - // SecretValidator is a validator for the "secret" field. It is called by the builders before save. - SecretValidator func(string) error - // NextURLValidator is a validator for the "next_url" field. It is called by the builders before save. - NextURLValidator func(string) error -) - -// OrderOption defines the ordering options for the MagicFlow queries. -type OrderOption func(*sql.Selector) - -// ByID orders the results by the id field. -func ByID(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldID, opts...).ToFunc() -} - -// ByCreatedAt orders the results by the created_at field. -func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() -} - -// ByIdentifier orders the results by the identifier field. -func ByIdentifier(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldIdentifier, opts...).ToFunc() -} - -// ByEmail orders the results by the email field. -func ByEmail(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldEmail, opts...).ToFunc() -} - -// ByIPAddress orders the results by the ip_address field. -func ByIPAddress(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldIPAddress, opts...).ToFunc() -} - -// BySecret orders the results by the secret field. -func BySecret(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldSecret, opts...).ToFunc() -} - -// ByNextURL orders the results by the next_url field. -func ByNextURL(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldNextURL, opts...).ToFunc() -} - -// ByOrganization orders the results by the organization field. -func ByOrganization(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldOrganization, opts...).ToFunc() -} - -// ByDeviceIdentifier orders the results by the device_identifier field. -func ByDeviceIdentifier(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldDeviceIdentifier, opts...).ToFunc() -} diff --git a/internal/ent/magicflow/where.go b/internal/ent/magicflow/where.go deleted file mode 100644 index 9a49e3c..0000000 --- a/internal/ent/magicflow/where.go +++ /dev/null @@ -1,658 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package magicflow - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id int) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldID, id)) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldID, id)) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNEQ(FieldID, id)) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldIn(FieldID, ids...)) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNotIn(FieldID, ids...)) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGT(FieldID, id)) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGTE(FieldID, id)) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLT(FieldID, id)) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLTE(FieldID, id)) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldCreatedAt, v)) -} - -// Identifier applies equality check predicate on the "identifier" field. It's identical to IdentifierEQ. -func Identifier(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldIdentifier, v)) -} - -// Email applies equality check predicate on the "email" field. It's identical to EmailEQ. -func Email(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldEmail, v)) -} - -// IPAddress applies equality check predicate on the "ip_address" field. It's identical to IPAddressEQ. -func IPAddress(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldIPAddress, v)) -} - -// Secret applies equality check predicate on the "secret" field. It's identical to SecretEQ. -func Secret(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldSecret, v)) -} - -// NextURL applies equality check predicate on the "next_url" field. It's identical to NextURLEQ. -func NextURL(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldNextURL, v)) -} - -// Organization applies equality check predicate on the "organization" field. It's identical to OrganizationEQ. -func Organization(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldOrganization, v)) -} - -// DeviceIdentifier applies equality check predicate on the "device_identifier" field. It's identical to DeviceIdentifierEQ. -func DeviceIdentifier(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldDeviceIdentifier, v)) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldCreatedAt, v)) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNEQ(FieldCreatedAt, v)) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldIn(FieldCreatedAt, vs...)) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNotIn(FieldCreatedAt, vs...)) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGT(FieldCreatedAt, v)) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGTE(FieldCreatedAt, v)) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLT(FieldCreatedAt, v)) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLTE(FieldCreatedAt, v)) -} - -// IdentifierEQ applies the EQ predicate on the "identifier" field. -func IdentifierEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldIdentifier, v)) -} - -// IdentifierNEQ applies the NEQ predicate on the "identifier" field. -func IdentifierNEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNEQ(FieldIdentifier, v)) -} - -// IdentifierIn applies the In predicate on the "identifier" field. -func IdentifierIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldIn(FieldIdentifier, vs...)) -} - -// IdentifierNotIn applies the NotIn predicate on the "identifier" field. -func IdentifierNotIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNotIn(FieldIdentifier, vs...)) -} - -// IdentifierGT applies the GT predicate on the "identifier" field. -func IdentifierGT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGT(FieldIdentifier, v)) -} - -// IdentifierGTE applies the GTE predicate on the "identifier" field. -func IdentifierGTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGTE(FieldIdentifier, v)) -} - -// IdentifierLT applies the LT predicate on the "identifier" field. -func IdentifierLT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLT(FieldIdentifier, v)) -} - -// IdentifierLTE applies the LTE predicate on the "identifier" field. -func IdentifierLTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLTE(FieldIdentifier, v)) -} - -// IdentifierContains applies the Contains predicate on the "identifier" field. -func IdentifierContains(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContains(FieldIdentifier, v)) -} - -// IdentifierHasPrefix applies the HasPrefix predicate on the "identifier" field. -func IdentifierHasPrefix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasPrefix(FieldIdentifier, v)) -} - -// IdentifierHasSuffix applies the HasSuffix predicate on the "identifier" field. -func IdentifierHasSuffix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasSuffix(FieldIdentifier, v)) -} - -// IdentifierEqualFold applies the EqualFold predicate on the "identifier" field. -func IdentifierEqualFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEqualFold(FieldIdentifier, v)) -} - -// IdentifierContainsFold applies the ContainsFold predicate on the "identifier" field. -func IdentifierContainsFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContainsFold(FieldIdentifier, v)) -} - -// EmailEQ applies the EQ predicate on the "email" field. -func EmailEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldEmail, v)) -} - -// EmailNEQ applies the NEQ predicate on the "email" field. -func EmailNEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNEQ(FieldEmail, v)) -} - -// EmailIn applies the In predicate on the "email" field. -func EmailIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldIn(FieldEmail, vs...)) -} - -// EmailNotIn applies the NotIn predicate on the "email" field. -func EmailNotIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNotIn(FieldEmail, vs...)) -} - -// EmailGT applies the GT predicate on the "email" field. -func EmailGT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGT(FieldEmail, v)) -} - -// EmailGTE applies the GTE predicate on the "email" field. -func EmailGTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGTE(FieldEmail, v)) -} - -// EmailLT applies the LT predicate on the "email" field. -func EmailLT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLT(FieldEmail, v)) -} - -// EmailLTE applies the LTE predicate on the "email" field. -func EmailLTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLTE(FieldEmail, v)) -} - -// EmailContains applies the Contains predicate on the "email" field. -func EmailContains(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContains(FieldEmail, v)) -} - -// EmailHasPrefix applies the HasPrefix predicate on the "email" field. -func EmailHasPrefix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasPrefix(FieldEmail, v)) -} - -// EmailHasSuffix applies the HasSuffix predicate on the "email" field. -func EmailHasSuffix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasSuffix(FieldEmail, v)) -} - -// EmailEqualFold applies the EqualFold predicate on the "email" field. -func EmailEqualFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEqualFold(FieldEmail, v)) -} - -// EmailContainsFold applies the ContainsFold predicate on the "email" field. -func EmailContainsFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContainsFold(FieldEmail, v)) -} - -// IPAddressEQ applies the EQ predicate on the "ip_address" field. -func IPAddressEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldIPAddress, v)) -} - -// IPAddressNEQ applies the NEQ predicate on the "ip_address" field. -func IPAddressNEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNEQ(FieldIPAddress, v)) -} - -// IPAddressIn applies the In predicate on the "ip_address" field. -func IPAddressIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldIn(FieldIPAddress, vs...)) -} - -// IPAddressNotIn applies the NotIn predicate on the "ip_address" field. -func IPAddressNotIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNotIn(FieldIPAddress, vs...)) -} - -// IPAddressGT applies the GT predicate on the "ip_address" field. -func IPAddressGT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGT(FieldIPAddress, v)) -} - -// IPAddressGTE applies the GTE predicate on the "ip_address" field. -func IPAddressGTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGTE(FieldIPAddress, v)) -} - -// IPAddressLT applies the LT predicate on the "ip_address" field. -func IPAddressLT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLT(FieldIPAddress, v)) -} - -// IPAddressLTE applies the LTE predicate on the "ip_address" field. -func IPAddressLTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLTE(FieldIPAddress, v)) -} - -// IPAddressContains applies the Contains predicate on the "ip_address" field. -func IPAddressContains(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContains(FieldIPAddress, v)) -} - -// IPAddressHasPrefix applies the HasPrefix predicate on the "ip_address" field. -func IPAddressHasPrefix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasPrefix(FieldIPAddress, v)) -} - -// IPAddressHasSuffix applies the HasSuffix predicate on the "ip_address" field. -func IPAddressHasSuffix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasSuffix(FieldIPAddress, v)) -} - -// IPAddressEqualFold applies the EqualFold predicate on the "ip_address" field. -func IPAddressEqualFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEqualFold(FieldIPAddress, v)) -} - -// IPAddressContainsFold applies the ContainsFold predicate on the "ip_address" field. -func IPAddressContainsFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContainsFold(FieldIPAddress, v)) -} - -// SecretEQ applies the EQ predicate on the "secret" field. -func SecretEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldSecret, v)) -} - -// SecretNEQ applies the NEQ predicate on the "secret" field. -func SecretNEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNEQ(FieldSecret, v)) -} - -// SecretIn applies the In predicate on the "secret" field. -func SecretIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldIn(FieldSecret, vs...)) -} - -// SecretNotIn applies the NotIn predicate on the "secret" field. -func SecretNotIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNotIn(FieldSecret, vs...)) -} - -// SecretGT applies the GT predicate on the "secret" field. -func SecretGT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGT(FieldSecret, v)) -} - -// SecretGTE applies the GTE predicate on the "secret" field. -func SecretGTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGTE(FieldSecret, v)) -} - -// SecretLT applies the LT predicate on the "secret" field. -func SecretLT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLT(FieldSecret, v)) -} - -// SecretLTE applies the LTE predicate on the "secret" field. -func SecretLTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLTE(FieldSecret, v)) -} - -// SecretContains applies the Contains predicate on the "secret" field. -func SecretContains(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContains(FieldSecret, v)) -} - -// SecretHasPrefix applies the HasPrefix predicate on the "secret" field. -func SecretHasPrefix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasPrefix(FieldSecret, v)) -} - -// SecretHasSuffix applies the HasSuffix predicate on the "secret" field. -func SecretHasSuffix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasSuffix(FieldSecret, v)) -} - -// SecretEqualFold applies the EqualFold predicate on the "secret" field. -func SecretEqualFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEqualFold(FieldSecret, v)) -} - -// SecretContainsFold applies the ContainsFold predicate on the "secret" field. -func SecretContainsFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContainsFold(FieldSecret, v)) -} - -// NextURLEQ applies the EQ predicate on the "next_url" field. -func NextURLEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldNextURL, v)) -} - -// NextURLNEQ applies the NEQ predicate on the "next_url" field. -func NextURLNEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNEQ(FieldNextURL, v)) -} - -// NextURLIn applies the In predicate on the "next_url" field. -func NextURLIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldIn(FieldNextURL, vs...)) -} - -// NextURLNotIn applies the NotIn predicate on the "next_url" field. -func NextURLNotIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNotIn(FieldNextURL, vs...)) -} - -// NextURLGT applies the GT predicate on the "next_url" field. -func NextURLGT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGT(FieldNextURL, v)) -} - -// NextURLGTE applies the GTE predicate on the "next_url" field. -func NextURLGTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGTE(FieldNextURL, v)) -} - -// NextURLLT applies the LT predicate on the "next_url" field. -func NextURLLT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLT(FieldNextURL, v)) -} - -// NextURLLTE applies the LTE predicate on the "next_url" field. -func NextURLLTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLTE(FieldNextURL, v)) -} - -// NextURLContains applies the Contains predicate on the "next_url" field. -func NextURLContains(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContains(FieldNextURL, v)) -} - -// NextURLHasPrefix applies the HasPrefix predicate on the "next_url" field. -func NextURLHasPrefix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasPrefix(FieldNextURL, v)) -} - -// NextURLHasSuffix applies the HasSuffix predicate on the "next_url" field. -func NextURLHasSuffix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasSuffix(FieldNextURL, v)) -} - -// NextURLEqualFold applies the EqualFold predicate on the "next_url" field. -func NextURLEqualFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEqualFold(FieldNextURL, v)) -} - -// NextURLContainsFold applies the ContainsFold predicate on the "next_url" field. -func NextURLContainsFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContainsFold(FieldNextURL, v)) -} - -// OrganizationEQ applies the EQ predicate on the "organization" field. -func OrganizationEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldOrganization, v)) -} - -// OrganizationNEQ applies the NEQ predicate on the "organization" field. -func OrganizationNEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNEQ(FieldOrganization, v)) -} - -// OrganizationIn applies the In predicate on the "organization" field. -func OrganizationIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldIn(FieldOrganization, vs...)) -} - -// OrganizationNotIn applies the NotIn predicate on the "organization" field. -func OrganizationNotIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNotIn(FieldOrganization, vs...)) -} - -// OrganizationGT applies the GT predicate on the "organization" field. -func OrganizationGT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGT(FieldOrganization, v)) -} - -// OrganizationGTE applies the GTE predicate on the "organization" field. -func OrganizationGTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGTE(FieldOrganization, v)) -} - -// OrganizationLT applies the LT predicate on the "organization" field. -func OrganizationLT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLT(FieldOrganization, v)) -} - -// OrganizationLTE applies the LTE predicate on the "organization" field. -func OrganizationLTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLTE(FieldOrganization, v)) -} - -// OrganizationContains applies the Contains predicate on the "organization" field. -func OrganizationContains(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContains(FieldOrganization, v)) -} - -// OrganizationHasPrefix applies the HasPrefix predicate on the "organization" field. -func OrganizationHasPrefix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasPrefix(FieldOrganization, v)) -} - -// OrganizationHasSuffix applies the HasSuffix predicate on the "organization" field. -func OrganizationHasSuffix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasSuffix(FieldOrganization, v)) -} - -// OrganizationIsNil applies the IsNil predicate on the "organization" field. -func OrganizationIsNil() predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldIsNull(FieldOrganization)) -} - -// OrganizationNotNil applies the NotNil predicate on the "organization" field. -func OrganizationNotNil() predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNotNull(FieldOrganization)) -} - -// OrganizationEqualFold applies the EqualFold predicate on the "organization" field. -func OrganizationEqualFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEqualFold(FieldOrganization, v)) -} - -// OrganizationContainsFold applies the ContainsFold predicate on the "organization" field. -func OrganizationContainsFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContainsFold(FieldOrganization, v)) -} - -// DeviceIdentifierEQ applies the EQ predicate on the "device_identifier" field. -func DeviceIdentifierEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEQ(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierNEQ applies the NEQ predicate on the "device_identifier" field. -func DeviceIdentifierNEQ(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNEQ(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierIn applies the In predicate on the "device_identifier" field. -func DeviceIdentifierIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldIn(FieldDeviceIdentifier, vs...)) -} - -// DeviceIdentifierNotIn applies the NotIn predicate on the "device_identifier" field. -func DeviceIdentifierNotIn(vs ...string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNotIn(FieldDeviceIdentifier, vs...)) -} - -// DeviceIdentifierGT applies the GT predicate on the "device_identifier" field. -func DeviceIdentifierGT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGT(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierGTE applies the GTE predicate on the "device_identifier" field. -func DeviceIdentifierGTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldGTE(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierLT applies the LT predicate on the "device_identifier" field. -func DeviceIdentifierLT(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLT(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierLTE applies the LTE predicate on the "device_identifier" field. -func DeviceIdentifierLTE(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldLTE(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierContains applies the Contains predicate on the "device_identifier" field. -func DeviceIdentifierContains(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContains(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierHasPrefix applies the HasPrefix predicate on the "device_identifier" field. -func DeviceIdentifierHasPrefix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasPrefix(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierHasSuffix applies the HasSuffix predicate on the "device_identifier" field. -func DeviceIdentifierHasSuffix(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldHasSuffix(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierIsNil applies the IsNil predicate on the "device_identifier" field. -func DeviceIdentifierIsNil() predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldIsNull(FieldDeviceIdentifier)) -} - -// DeviceIdentifierNotNil applies the NotNil predicate on the "device_identifier" field. -func DeviceIdentifierNotNil() predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldNotNull(FieldDeviceIdentifier)) -} - -// DeviceIdentifierEqualFold applies the EqualFold predicate on the "device_identifier" field. -func DeviceIdentifierEqualFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldEqualFold(FieldDeviceIdentifier, v)) -} - -// DeviceIdentifierContainsFold applies the ContainsFold predicate on the "device_identifier" field. -func DeviceIdentifierContainsFold(v string) predicate.MagicFlow { - return predicate.MagicFlow(sql.FieldContainsFold(FieldDeviceIdentifier, v)) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.MagicFlow) predicate.MagicFlow { - return predicate.MagicFlow(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.MagicFlow) predicate.MagicFlow { - return predicate.MagicFlow(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.MagicFlow) predicate.MagicFlow { - return predicate.MagicFlow(func(s *sql.Selector) { - p(s.Not()) - }) -} diff --git a/internal/ent/magicflow_create.go b/internal/ent/magicflow_create.go deleted file mode 100644 index ba3b1ac..0000000 --- a/internal/ent/magicflow_create.go +++ /dev/null @@ -1,340 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/magicflow" -) - -// MagicFlowCreate is the builder for creating a MagicFlow entity. -type MagicFlowCreate struct { - config - mutation *MagicFlowMutation - hooks []Hook -} - -// SetCreatedAt sets the "created_at" field. -func (mfc *MagicFlowCreate) SetCreatedAt(t time.Time) *MagicFlowCreate { - mfc.mutation.SetCreatedAt(t) - return mfc -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (mfc *MagicFlowCreate) SetNillableCreatedAt(t *time.Time) *MagicFlowCreate { - if t != nil { - mfc.SetCreatedAt(*t) - } - return mfc -} - -// SetIdentifier sets the "identifier" field. -func (mfc *MagicFlowCreate) SetIdentifier(s string) *MagicFlowCreate { - mfc.mutation.SetIdentifier(s) - return mfc -} - -// SetEmail sets the "email" field. -func (mfc *MagicFlowCreate) SetEmail(s string) *MagicFlowCreate { - mfc.mutation.SetEmail(s) - return mfc -} - -// SetIPAddress sets the "ip_address" field. -func (mfc *MagicFlowCreate) SetIPAddress(s string) *MagicFlowCreate { - mfc.mutation.SetIPAddress(s) - return mfc -} - -// SetSecret sets the "secret" field. -func (mfc *MagicFlowCreate) SetSecret(s string) *MagicFlowCreate { - mfc.mutation.SetSecret(s) - return mfc -} - -// SetNextURL sets the "next_url" field. -func (mfc *MagicFlowCreate) SetNextURL(s string) *MagicFlowCreate { - mfc.mutation.SetNextURL(s) - return mfc -} - -// SetOrganization sets the "organization" field. -func (mfc *MagicFlowCreate) SetOrganization(s string) *MagicFlowCreate { - mfc.mutation.SetOrganization(s) - return mfc -} - -// SetNillableOrganization sets the "organization" field if the given value is not nil. -func (mfc *MagicFlowCreate) SetNillableOrganization(s *string) *MagicFlowCreate { - if s != nil { - mfc.SetOrganization(*s) - } - return mfc -} - -// SetDeviceIdentifier sets the "device_identifier" field. -func (mfc *MagicFlowCreate) SetDeviceIdentifier(s string) *MagicFlowCreate { - mfc.mutation.SetDeviceIdentifier(s) - return mfc -} - -// SetNillableDeviceIdentifier sets the "device_identifier" field if the given value is not nil. -func (mfc *MagicFlowCreate) SetNillableDeviceIdentifier(s *string) *MagicFlowCreate { - if s != nil { - mfc.SetDeviceIdentifier(*s) - } - return mfc -} - -// Mutation returns the MagicFlowMutation object of the builder. -func (mfc *MagicFlowCreate) Mutation() *MagicFlowMutation { - return mfc.mutation -} - -// Save creates the MagicFlow in the database. -func (mfc *MagicFlowCreate) Save(ctx context.Context) (*MagicFlow, error) { - mfc.defaults() - return withHooks(ctx, mfc.sqlSave, mfc.mutation, mfc.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (mfc *MagicFlowCreate) SaveX(ctx context.Context) *MagicFlow { - v, err := mfc.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (mfc *MagicFlowCreate) Exec(ctx context.Context) error { - _, err := mfc.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (mfc *MagicFlowCreate) ExecX(ctx context.Context) { - if err := mfc.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (mfc *MagicFlowCreate) defaults() { - if _, ok := mfc.mutation.CreatedAt(); !ok { - v := magicflow.DefaultCreatedAt() - mfc.mutation.SetCreatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (mfc *MagicFlowCreate) check() error { - if _, ok := mfc.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "MagicFlow.created_at"`)} - } - if _, ok := mfc.mutation.Identifier(); !ok { - return &ValidationError{Name: "identifier", err: errors.New(`ent: missing required field "MagicFlow.identifier"`)} - } - if v, ok := mfc.mutation.Identifier(); ok { - if err := magicflow.IdentifierValidator(v); err != nil { - return &ValidationError{Name: "identifier", err: fmt.Errorf(`ent: validator failed for field "MagicFlow.identifier": %w`, err)} - } - } - if _, ok := mfc.mutation.Email(); !ok { - return &ValidationError{Name: "email", err: errors.New(`ent: missing required field "MagicFlow.email"`)} - } - if v, ok := mfc.mutation.Email(); ok { - if err := magicflow.EmailValidator(v); err != nil { - return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "MagicFlow.email": %w`, err)} - } - } - if _, ok := mfc.mutation.IPAddress(); !ok { - return &ValidationError{Name: "ip_address", err: errors.New(`ent: missing required field "MagicFlow.ip_address"`)} - } - if v, ok := mfc.mutation.IPAddress(); ok { - if err := magicflow.IPAddressValidator(v); err != nil { - return &ValidationError{Name: "ip_address", err: fmt.Errorf(`ent: validator failed for field "MagicFlow.ip_address": %w`, err)} - } - } - if _, ok := mfc.mutation.Secret(); !ok { - return &ValidationError{Name: "secret", err: errors.New(`ent: missing required field "MagicFlow.secret"`)} - } - if v, ok := mfc.mutation.Secret(); ok { - if err := magicflow.SecretValidator(v); err != nil { - return &ValidationError{Name: "secret", err: fmt.Errorf(`ent: validator failed for field "MagicFlow.secret": %w`, err)} - } - } - if _, ok := mfc.mutation.NextURL(); !ok { - return &ValidationError{Name: "next_url", err: errors.New(`ent: missing required field "MagicFlow.next_url"`)} - } - if v, ok := mfc.mutation.NextURL(); ok { - if err := magicflow.NextURLValidator(v); err != nil { - return &ValidationError{Name: "next_url", err: fmt.Errorf(`ent: validator failed for field "MagicFlow.next_url": %w`, err)} - } - } - return nil -} - -func (mfc *MagicFlowCreate) sqlSave(ctx context.Context) (*MagicFlow, error) { - if err := mfc.check(); err != nil { - return nil, err - } - _node, _spec := mfc.createSpec() - if err := sqlgraph.CreateNode(ctx, mfc.driver, _spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - id := _spec.ID.Value.(int64) - _node.ID = int(id) - mfc.mutation.id = &_node.ID - mfc.mutation.done = true - return _node, nil -} - -func (mfc *MagicFlowCreate) createSpec() (*MagicFlow, *sqlgraph.CreateSpec) { - var ( - _node = &MagicFlow{config: mfc.config} - _spec = sqlgraph.NewCreateSpec(magicflow.Table, sqlgraph.NewFieldSpec(magicflow.FieldID, field.TypeInt)) - ) - if value, ok := mfc.mutation.CreatedAt(); ok { - _spec.SetField(magicflow.FieldCreatedAt, field.TypeTime, value) - _node.CreatedAt = value - } - if value, ok := mfc.mutation.Identifier(); ok { - _spec.SetField(magicflow.FieldIdentifier, field.TypeString, value) - _node.Identifier = value - } - if value, ok := mfc.mutation.Email(); ok { - _spec.SetField(magicflow.FieldEmail, field.TypeString, value) - _node.Email = value - } - if value, ok := mfc.mutation.IPAddress(); ok { - _spec.SetField(magicflow.FieldIPAddress, field.TypeString, value) - _node.IPAddress = value - } - if value, ok := mfc.mutation.Secret(); ok { - _spec.SetField(magicflow.FieldSecret, field.TypeString, value) - _node.Secret = value - } - if value, ok := mfc.mutation.NextURL(); ok { - _spec.SetField(magicflow.FieldNextURL, field.TypeString, value) - _node.NextURL = value - } - if value, ok := mfc.mutation.Organization(); ok { - _spec.SetField(magicflow.FieldOrganization, field.TypeString, value) - _node.Organization = value - } - if value, ok := mfc.mutation.DeviceIdentifier(); ok { - _spec.SetField(magicflow.FieldDeviceIdentifier, field.TypeString, value) - _node.DeviceIdentifier = value - } - return _node, _spec -} - -// MagicFlowCreateBulk is the builder for creating many MagicFlow entities in bulk. -type MagicFlowCreateBulk struct { - config - builders []*MagicFlowCreate -} - -// Save creates the MagicFlow entities in the database. -func (mfcb *MagicFlowCreateBulk) Save(ctx context.Context) ([]*MagicFlow, error) { - specs := make([]*sqlgraph.CreateSpec, len(mfcb.builders)) - nodes := make([]*MagicFlow, len(mfcb.builders)) - mutators := make([]Mutator, len(mfcb.builders)) - for i := range mfcb.builders { - func(i int, root context.Context) { - builder := mfcb.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*MagicFlowMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - var err error - nodes[i], specs[i] = builder.createSpec() - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, mfcb.builders[i+1].mutation) - } else { - spec := &sqlgraph.BatchCreateSpec{Nodes: specs} - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, mfcb.driver, spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - } - } - if err != nil { - return nil, err - } - mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) - } - mutation.done = true - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, mfcb.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (mfcb *MagicFlowCreateBulk) SaveX(ctx context.Context) []*MagicFlow { - v, err := mfcb.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (mfcb *MagicFlowCreateBulk) Exec(ctx context.Context) error { - _, err := mfcb.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (mfcb *MagicFlowCreateBulk) ExecX(ctx context.Context) { - if err := mfcb.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/internal/ent/magicflow_delete.go b/internal/ent/magicflow_delete.go deleted file mode 100644 index 9be94db..0000000 --- a/internal/ent/magicflow_delete.go +++ /dev/null @@ -1,104 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/magicflow" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// MagicFlowDelete is the builder for deleting a MagicFlow entity. -type MagicFlowDelete struct { - config - hooks []Hook - mutation *MagicFlowMutation -} - -// Where appends a list predicates to the MagicFlowDelete builder. -func (mfd *MagicFlowDelete) Where(ps ...predicate.MagicFlow) *MagicFlowDelete { - mfd.mutation.Where(ps...) - return mfd -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (mfd *MagicFlowDelete) Exec(ctx context.Context) (int, error) { - return withHooks(ctx, mfd.sqlExec, mfd.mutation, mfd.hooks) -} - -// ExecX is like Exec, but panics if an error occurs. -func (mfd *MagicFlowDelete) ExecX(ctx context.Context) int { - n, err := mfd.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (mfd *MagicFlowDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(magicflow.Table, sqlgraph.NewFieldSpec(magicflow.FieldID, field.TypeInt)) - if ps := mfd.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - affected, err := sqlgraph.DeleteNodes(ctx, mfd.driver, _spec) - if err != nil && sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - mfd.mutation.done = true - return affected, err -} - -// MagicFlowDeleteOne is the builder for deleting a single MagicFlow entity. -type MagicFlowDeleteOne struct { - mfd *MagicFlowDelete -} - -// Where appends a list predicates to the MagicFlowDelete builder. -func (mfdo *MagicFlowDeleteOne) Where(ps ...predicate.MagicFlow) *MagicFlowDeleteOne { - mfdo.mfd.mutation.Where(ps...) - return mfdo -} - -// Exec executes the deletion query. -func (mfdo *MagicFlowDeleteOne) Exec(ctx context.Context) error { - n, err := mfdo.mfd.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{magicflow.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (mfdo *MagicFlowDeleteOne) ExecX(ctx context.Context) { - if err := mfdo.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/internal/ent/magicflow_query.go b/internal/ent/magicflow_query.go deleted file mode 100644 index 6a8d689..0000000 --- a/internal/ent/magicflow_query.go +++ /dev/null @@ -1,542 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "math" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/magicflow" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// MagicFlowQuery is the builder for querying MagicFlow entities. -type MagicFlowQuery struct { - config - ctx *QueryContext - order []magicflow.OrderOption - inters []Interceptor - predicates []predicate.MagicFlow - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the MagicFlowQuery builder. -func (mfq *MagicFlowQuery) Where(ps ...predicate.MagicFlow) *MagicFlowQuery { - mfq.predicates = append(mfq.predicates, ps...) - return mfq -} - -// Limit the number of records to be returned by this query. -func (mfq *MagicFlowQuery) Limit(limit int) *MagicFlowQuery { - mfq.ctx.Limit = &limit - return mfq -} - -// Offset to start from. -func (mfq *MagicFlowQuery) Offset(offset int) *MagicFlowQuery { - mfq.ctx.Offset = &offset - return mfq -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (mfq *MagicFlowQuery) Unique(unique bool) *MagicFlowQuery { - mfq.ctx.Unique = &unique - return mfq -} - -// Order specifies how the records should be ordered. -func (mfq *MagicFlowQuery) Order(o ...magicflow.OrderOption) *MagicFlowQuery { - mfq.order = append(mfq.order, o...) - return mfq -} - -// First returns the first MagicFlow entity from the query. -// Returns a *NotFoundError when no MagicFlow was found. -func (mfq *MagicFlowQuery) First(ctx context.Context) (*MagicFlow, error) { - nodes, err := mfq.Limit(1).All(setContextOp(ctx, mfq.ctx, "First")) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{magicflow.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (mfq *MagicFlowQuery) FirstX(ctx context.Context) *MagicFlow { - node, err := mfq.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first MagicFlow ID from the query. -// Returns a *NotFoundError when no MagicFlow ID was found. -func (mfq *MagicFlowQuery) FirstID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = mfq.Limit(1).IDs(setContextOp(ctx, mfq.ctx, "FirstID")); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{magicflow.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (mfq *MagicFlowQuery) FirstIDX(ctx context.Context) int { - id, err := mfq.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single MagicFlow entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one MagicFlow entity is found. -// Returns a *NotFoundError when no MagicFlow entities are found. -func (mfq *MagicFlowQuery) Only(ctx context.Context) (*MagicFlow, error) { - nodes, err := mfq.Limit(2).All(setContextOp(ctx, mfq.ctx, "Only")) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{magicflow.Label} - default: - return nil, &NotSingularError{magicflow.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (mfq *MagicFlowQuery) OnlyX(ctx context.Context) *MagicFlow { - node, err := mfq.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only MagicFlow ID in the query. -// Returns a *NotSingularError when more than one MagicFlow ID is found. -// Returns a *NotFoundError when no entities are found. -func (mfq *MagicFlowQuery) OnlyID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = mfq.Limit(2).IDs(setContextOp(ctx, mfq.ctx, "OnlyID")); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{magicflow.Label} - default: - err = &NotSingularError{magicflow.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (mfq *MagicFlowQuery) OnlyIDX(ctx context.Context) int { - id, err := mfq.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of MagicFlows. -func (mfq *MagicFlowQuery) All(ctx context.Context) ([]*MagicFlow, error) { - ctx = setContextOp(ctx, mfq.ctx, "All") - if err := mfq.prepareQuery(ctx); err != nil { - return nil, err - } - qr := querierAll[[]*MagicFlow, *MagicFlowQuery]() - return withInterceptors[[]*MagicFlow](ctx, mfq, qr, mfq.inters) -} - -// AllX is like All, but panics if an error occurs. -func (mfq *MagicFlowQuery) AllX(ctx context.Context) []*MagicFlow { - nodes, err := mfq.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of MagicFlow IDs. -func (mfq *MagicFlowQuery) IDs(ctx context.Context) (ids []int, err error) { - if mfq.ctx.Unique == nil && mfq.path != nil { - mfq.Unique(true) - } - ctx = setContextOp(ctx, mfq.ctx, "IDs") - if err = mfq.Select(magicflow.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (mfq *MagicFlowQuery) IDsX(ctx context.Context) []int { - ids, err := mfq.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (mfq *MagicFlowQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, mfq.ctx, "Count") - if err := mfq.prepareQuery(ctx); err != nil { - return 0, err - } - return withInterceptors[int](ctx, mfq, querierCount[*MagicFlowQuery](), mfq.inters) -} - -// CountX is like Count, but panics if an error occurs. -func (mfq *MagicFlowQuery) CountX(ctx context.Context) int { - count, err := mfq.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (mfq *MagicFlowQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, mfq.ctx, "Exist") - switch _, err := mfq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - -// ExistX is like Exist, but panics if an error occurs. -func (mfq *MagicFlowQuery) ExistX(ctx context.Context) bool { - exist, err := mfq.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the MagicFlowQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (mfq *MagicFlowQuery) Clone() *MagicFlowQuery { - if mfq == nil { - return nil - } - return &MagicFlowQuery{ - config: mfq.config, - ctx: mfq.ctx.Clone(), - order: append([]magicflow.OrderOption{}, mfq.order...), - inters: append([]Interceptor{}, mfq.inters...), - predicates: append([]predicate.MagicFlow{}, mfq.predicates...), - // clone intermediate query. - sql: mfq.sql.Clone(), - path: mfq.path, - } -} - -// 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: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.MagicFlow.Query(). -// GroupBy(magicflow.FieldCreatedAt). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -func (mfq *MagicFlowQuery) GroupBy(field string, fields ...string) *MagicFlowGroupBy { - mfq.ctx.Fields = append([]string{field}, fields...) - grbuild := &MagicFlowGroupBy{build: mfq} - grbuild.flds = &mfq.ctx.Fields - grbuild.label = magicflow.Label - grbuild.scan = grbuild.Scan - return grbuild -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// } -// -// client.MagicFlow.Query(). -// Select(magicflow.FieldCreatedAt). -// Scan(ctx, &v) -func (mfq *MagicFlowQuery) Select(fields ...string) *MagicFlowSelect { - mfq.ctx.Fields = append(mfq.ctx.Fields, fields...) - sbuild := &MagicFlowSelect{MagicFlowQuery: mfq} - sbuild.label = magicflow.Label - sbuild.flds, sbuild.scan = &mfq.ctx.Fields, sbuild.Scan - return sbuild -} - -// Aggregate returns a MagicFlowSelect configured with the given aggregations. -func (mfq *MagicFlowQuery) Aggregate(fns ...AggregateFunc) *MagicFlowSelect { - return mfq.Select().Aggregate(fns...) -} - -func (mfq *MagicFlowQuery) prepareQuery(ctx context.Context) error { - for _, inter := range mfq.inters { - if inter == nil { - return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") - } - if trv, ok := inter.(Traverser); ok { - if err := trv.Traverse(ctx, mfq); err != nil { - return err - } - } - } - for _, f := range mfq.ctx.Fields { - if !magicflow.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if mfq.path != nil { - prev, err := mfq.path(ctx) - if err != nil { - return err - } - mfq.sql = prev - } - return nil -} - -func (mfq *MagicFlowQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*MagicFlow, error) { - var ( - nodes = []*MagicFlow{} - _spec = mfq.querySpec() - ) - _spec.ScanValues = func(columns []string) ([]any, error) { - return (*MagicFlow).scanValues(nil, columns) - } - _spec.Assign = func(columns []string, values []any) error { - node := &MagicFlow{config: mfq.config} - nodes = append(nodes, node) - return node.assignValues(columns, values) - } - for i := range hooks { - hooks[i](ctx, _spec) - } - if err := sqlgraph.QueryNodes(ctx, mfq.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - return nodes, nil -} - -func (mfq *MagicFlowQuery) sqlCount(ctx context.Context) (int, error) { - _spec := mfq.querySpec() - _spec.Node.Columns = mfq.ctx.Fields - if len(mfq.ctx.Fields) > 0 { - _spec.Unique = mfq.ctx.Unique != nil && *mfq.ctx.Unique - } - return sqlgraph.CountNodes(ctx, mfq.driver, _spec) -} - -func (mfq *MagicFlowQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(magicflow.Table, magicflow.Columns, sqlgraph.NewFieldSpec(magicflow.FieldID, field.TypeInt)) - _spec.From = mfq.sql - if unique := mfq.ctx.Unique; unique != nil { - _spec.Unique = *unique - } else if mfq.path != nil { - _spec.Unique = true - } - if fields := mfq.ctx.Fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, magicflow.FieldID) - for i := range fields { - if fields[i] != magicflow.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := mfq.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := mfq.ctx.Limit; limit != nil { - _spec.Limit = *limit - } - if offset := mfq.ctx.Offset; offset != nil { - _spec.Offset = *offset - } - if ps := mfq.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (mfq *MagicFlowQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(mfq.driver.Dialect()) - t1 := builder.Table(magicflow.Table) - columns := mfq.ctx.Fields - if len(columns) == 0 { - columns = magicflow.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if mfq.sql != nil { - selector = mfq.sql - selector.Select(selector.Columns(columns...)...) - } - if mfq.ctx.Unique != nil && *mfq.ctx.Unique { - selector.Distinct() - } - for _, p := range mfq.predicates { - p(selector) - } - for _, p := range mfq.order { - p(selector) - } - if offset := mfq.ctx.Offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := mfq.ctx.Limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// MagicFlowGroupBy is the group-by builder for MagicFlow entities. -type MagicFlowGroupBy struct { - selector - build *MagicFlowQuery -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (mfgb *MagicFlowGroupBy) Aggregate(fns ...AggregateFunc) *MagicFlowGroupBy { - mfgb.fns = append(mfgb.fns, fns...) - return mfgb -} - -// Scan applies the selector query and scans the result into the given value. -func (mfgb *MagicFlowGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, mfgb.build.ctx, "GroupBy") - if err := mfgb.build.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*MagicFlowQuery, *MagicFlowGroupBy](ctx, mfgb.build, mfgb, mfgb.build.inters, v) -} - -func (mfgb *MagicFlowGroupBy) sqlScan(ctx context.Context, root *MagicFlowQuery, v any) error { - selector := root.sqlQuery(ctx).Select() - aggregation := make([]string, 0, len(mfgb.fns)) - for _, fn := range mfgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(*mfgb.flds)+len(mfgb.fns)) - for _, f := range *mfgb.flds { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - selector.GroupBy(selector.Columns(*mfgb.flds...)...) - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := mfgb.build.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -// MagicFlowSelect is the builder for selecting fields of MagicFlow entities. -type MagicFlowSelect struct { - *MagicFlowQuery - selector -} - -// Aggregate adds the given aggregation functions to the selector query. -func (mfs *MagicFlowSelect) Aggregate(fns ...AggregateFunc) *MagicFlowSelect { - mfs.fns = append(mfs.fns, fns...) - return mfs -} - -// Scan applies the selector query and scans the result into the given value. -func (mfs *MagicFlowSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, mfs.ctx, "Select") - if err := mfs.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*MagicFlowQuery, *MagicFlowSelect](ctx, mfs.MagicFlowQuery, mfs, mfs.inters, v) -} - -func (mfs *MagicFlowSelect) sqlScan(ctx context.Context, root *MagicFlowQuery, v any) error { - selector := root.sqlQuery(ctx) - aggregation := make([]string, 0, len(mfs.fns)) - for _, fn := range mfs.fns { - aggregation = append(aggregation, fn(selector)) - } - switch n := len(*mfs.selector.flds); { - case n == 0 && len(aggregation) > 0: - selector.Select(aggregation...) - case n != 0 && len(aggregation) > 0: - selector.AppendSelect(aggregation...) - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := mfs.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/internal/ent/magicflow_update.go b/internal/ent/magicflow_update.go deleted file mode 100644 index 8b60360..0000000 --- a/internal/ent/magicflow_update.go +++ /dev/null @@ -1,203 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/loopholelabs/auth/internal/ent/magicflow" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -// MagicFlowUpdate is the builder for updating MagicFlow entities. -type MagicFlowUpdate struct { - config - hooks []Hook - mutation *MagicFlowMutation -} - -// Where appends a list predicates to the MagicFlowUpdate builder. -func (mfu *MagicFlowUpdate) Where(ps ...predicate.MagicFlow) *MagicFlowUpdate { - mfu.mutation.Where(ps...) - return mfu -} - -// Mutation returns the MagicFlowMutation object of the builder. -func (mfu *MagicFlowUpdate) Mutation() *MagicFlowMutation { - return mfu.mutation -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (mfu *MagicFlowUpdate) Save(ctx context.Context) (int, error) { - return withHooks(ctx, mfu.sqlSave, mfu.mutation, mfu.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (mfu *MagicFlowUpdate) SaveX(ctx context.Context) int { - affected, err := mfu.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (mfu *MagicFlowUpdate) Exec(ctx context.Context) error { - _, err := mfu.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (mfu *MagicFlowUpdate) ExecX(ctx context.Context) { - if err := mfu.Exec(ctx); err != nil { - panic(err) - } -} - -func (mfu *MagicFlowUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := sqlgraph.NewUpdateSpec(magicflow.Table, magicflow.Columns, sqlgraph.NewFieldSpec(magicflow.FieldID, field.TypeInt)) - if ps := mfu.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if mfu.mutation.OrganizationCleared() { - _spec.ClearField(magicflow.FieldOrganization, field.TypeString) - } - if mfu.mutation.DeviceIdentifierCleared() { - _spec.ClearField(magicflow.FieldDeviceIdentifier, field.TypeString) - } - if n, err = sqlgraph.UpdateNodes(ctx, mfu.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{magicflow.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - mfu.mutation.done = true - return n, nil -} - -// MagicFlowUpdateOne is the builder for updating a single MagicFlow entity. -type MagicFlowUpdateOne struct { - config - fields []string - hooks []Hook - mutation *MagicFlowMutation -} - -// Mutation returns the MagicFlowMutation object of the builder. -func (mfuo *MagicFlowUpdateOne) Mutation() *MagicFlowMutation { - return mfuo.mutation -} - -// Where appends a list predicates to the MagicFlowUpdate builder. -func (mfuo *MagicFlowUpdateOne) Where(ps ...predicate.MagicFlow) *MagicFlowUpdateOne { - mfuo.mutation.Where(ps...) - return mfuo -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (mfuo *MagicFlowUpdateOne) Select(field string, fields ...string) *MagicFlowUpdateOne { - mfuo.fields = append([]string{field}, fields...) - return mfuo -} - -// Save executes the query and returns the updated MagicFlow entity. -func (mfuo *MagicFlowUpdateOne) Save(ctx context.Context) (*MagicFlow, error) { - return withHooks(ctx, mfuo.sqlSave, mfuo.mutation, mfuo.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (mfuo *MagicFlowUpdateOne) SaveX(ctx context.Context) *MagicFlow { - node, err := mfuo.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (mfuo *MagicFlowUpdateOne) Exec(ctx context.Context) error { - _, err := mfuo.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (mfuo *MagicFlowUpdateOne) ExecX(ctx context.Context) { - if err := mfuo.Exec(ctx); err != nil { - panic(err) - } -} - -func (mfuo *MagicFlowUpdateOne) sqlSave(ctx context.Context) (_node *MagicFlow, err error) { - _spec := sqlgraph.NewUpdateSpec(magicflow.Table, magicflow.Columns, sqlgraph.NewFieldSpec(magicflow.FieldID, field.TypeInt)) - id, ok := mfuo.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "MagicFlow.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := mfuo.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, magicflow.FieldID) - for _, f := range fields { - if !magicflow.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != magicflow.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := mfuo.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if mfuo.mutation.OrganizationCleared() { - _spec.ClearField(magicflow.FieldOrganization, field.TypeString) - } - if mfuo.mutation.DeviceIdentifierCleared() { - _spec.ClearField(magicflow.FieldDeviceIdentifier, field.TypeString) - } - _node = &MagicFlow{config: mfuo.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, mfuo.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{magicflow.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - mfuo.mutation.done = true - return _node, nil -} diff --git a/internal/ent/migrate/migrate.go b/internal/ent/migrate/migrate.go deleted file mode 100644 index 7f5cebb..0000000 --- a/internal/ent/migrate/migrate.go +++ /dev/null @@ -1,80 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package migrate - -import ( - "context" - "fmt" - "io" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql/schema" -) - -var ( - // WithGlobalUniqueID sets the universal ids options to the migration. - // If this option is enabled, ent migration will allocate a 1<<32 range - // for the ids of each entity (table). - // Note that this option cannot be applied on tables that already exist. - WithGlobalUniqueID = schema.WithGlobalUniqueID - // WithDropColumn sets the drop column option to the migration. - // If this option is enabled, ent migration will drop old columns - // that were used for both fields and edges. This defaults to false. - WithDropColumn = schema.WithDropColumn - // WithDropIndex sets the drop index option to the migration. - // If this option is enabled, ent migration will drop old indexes - // that were defined in the schema. This defaults to false. - // Note that unique constraints are defined using `UNIQUE INDEX`, - // and therefore, it's recommended to enable this option to get more - // flexibility in the schema changes. - WithDropIndex = schema.WithDropIndex - // 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. -type Schema struct { - drv dialect.Driver -} - -// NewSchema creates a new schema client. -func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} } - -// Create creates all schema resources. -func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error { - return Create(ctx, s, Tables, opts...) -} - -// Create creates all table resources using the given schema driver. -func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error { - migrate, err := schema.NewMigrate(s.drv, opts...) - if err != nil { - return fmt.Errorf("ent/migrate: %w", err) - } - return migrate.Create(ctx, tables...) -} - -// WriteTo writes the schema changes to w instead of running them against the database. -// -// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil { -// log.Fatal(err) -// } -func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error { - return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...) -} diff --git a/internal/ent/migrate/schema.go b/internal/ent/migrate/schema.go deleted file mode 100644 index a0540a6..0000000 --- a/internal/ent/migrate/schema.go +++ /dev/null @@ -1,106 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package migrate - -import ( - "entgo.io/ent/dialect/sql/schema" - "entgo.io/ent/schema/field" -) - -var ( - // DeviceFlowsColumns holds the columns for the "device_flows" table. - DeviceFlowsColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "created_at", Type: field.TypeTime}, - {Name: "identifier", Type: field.TypeString, Unique: true}, - {Name: "device_code", Type: field.TypeString, Unique: true}, - {Name: "user_code", Type: field.TypeString, Unique: true}, - {Name: "session", Type: field.TypeString, Unique: true, Nullable: true}, - {Name: "last_poll", Type: field.TypeTime}, - {Name: "expires_at", Type: field.TypeTime, Nullable: true}, - } - // DeviceFlowsTable holds the schema information for the "device_flows" table. - DeviceFlowsTable = &schema.Table{ - Name: "device_flows", - Columns: DeviceFlowsColumns, - PrimaryKey: []*schema.Column{DeviceFlowsColumns[0]}, - } - // GithubFlowsColumns holds the columns for the "github_flows" table. - GithubFlowsColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "created_at", Type: field.TypeTime}, - {Name: "identifier", Type: field.TypeString, Unique: true}, - {Name: "verifier", Type: field.TypeString, Unique: true}, - {Name: "challenge", Type: field.TypeString, Unique: true}, - {Name: "next_url", Type: field.TypeString}, - {Name: "organization", Type: field.TypeString, Nullable: true}, - {Name: "device_identifier", Type: field.TypeString, Nullable: true}, - } - // GithubFlowsTable holds the schema information for the "github_flows" table. - GithubFlowsTable = &schema.Table{ - Name: "github_flows", - Columns: GithubFlowsColumns, - PrimaryKey: []*schema.Column{GithubFlowsColumns[0]}, - } - // GoogleFlowsColumns holds the columns for the "google_flows" table. - GoogleFlowsColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "created_at", Type: field.TypeTime}, - {Name: "identifier", Type: field.TypeString, Unique: true}, - {Name: "verifier", Type: field.TypeString, Unique: true}, - {Name: "challenge", Type: field.TypeString, Unique: true}, - {Name: "next_url", Type: field.TypeString}, - {Name: "organization", Type: field.TypeString, Nullable: true}, - {Name: "device_identifier", Type: field.TypeString, Nullable: true}, - } - // GoogleFlowsTable holds the schema information for the "google_flows" table. - GoogleFlowsTable = &schema.Table{ - Name: "google_flows", - Columns: GoogleFlowsColumns, - PrimaryKey: []*schema.Column{GoogleFlowsColumns[0]}, - } - // MagicFlowsColumns holds the columns for the "magic_flows" table. - MagicFlowsColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "created_at", Type: field.TypeTime}, - {Name: "identifier", Type: field.TypeString, Unique: true}, - {Name: "email", Type: field.TypeString, Unique: true}, - {Name: "ip_address", Type: field.TypeString}, - {Name: "secret", Type: field.TypeString}, - {Name: "next_url", Type: field.TypeString}, - {Name: "organization", Type: field.TypeString, Nullable: true}, - {Name: "device_identifier", Type: field.TypeString, Nullable: true}, - } - // MagicFlowsTable holds the schema information for the "magic_flows" table. - MagicFlowsTable = &schema.Table{ - Name: "magic_flows", - Columns: MagicFlowsColumns, - PrimaryKey: []*schema.Column{MagicFlowsColumns[0]}, - } - // Tables holds all the tables in the schema. - Tables = []*schema.Table{ - DeviceFlowsTable, - GithubFlowsTable, - GoogleFlowsTable, - MagicFlowsTable, - } -) - -func init() { -} diff --git a/internal/ent/mutation.go b/internal/ent/mutation.go deleted file mode 100644 index caed73f..0000000 --- a/internal/ent/mutation.go +++ /dev/null @@ -1,2868 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "sync" - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "github.com/loopholelabs/auth/internal/ent/deviceflow" - "github.com/loopholelabs/auth/internal/ent/githubflow" - "github.com/loopholelabs/auth/internal/ent/googleflow" - "github.com/loopholelabs/auth/internal/ent/magicflow" - "github.com/loopholelabs/auth/internal/ent/predicate" -) - -const ( - // Operation types. - OpCreate = ent.OpCreate - OpDelete = ent.OpDelete - OpDeleteOne = ent.OpDeleteOne - OpUpdate = ent.OpUpdate - OpUpdateOne = ent.OpUpdateOne - - // Node types. - TypeDeviceFlow = "DeviceFlow" - TypeGithubFlow = "GithubFlow" - TypeGoogleFlow = "GoogleFlow" - TypeMagicFlow = "MagicFlow" -) - -// DeviceFlowMutation represents an operation that mutates the DeviceFlow nodes in the graph. -type DeviceFlowMutation struct { - config - op Op - typ string - id *int - created_at *time.Time - identifier *string - device_code *string - user_code *string - session *string - last_poll *time.Time - expires_at *time.Time - clearedFields map[string]struct{} - done bool - oldValue func(context.Context) (*DeviceFlow, error) - predicates []predicate.DeviceFlow -} - -var _ ent.Mutation = (*DeviceFlowMutation)(nil) - -// deviceflowOption allows management of the mutation configuration using functional options. -type deviceflowOption func(*DeviceFlowMutation) - -// newDeviceFlowMutation creates new mutation for the DeviceFlow entity. -func newDeviceFlowMutation(c config, op Op, opts ...deviceflowOption) *DeviceFlowMutation { - m := &DeviceFlowMutation{ - config: c, - op: op, - typ: TypeDeviceFlow, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withDeviceFlowID sets the ID field of the mutation. -func withDeviceFlowID(id int) deviceflowOption { - return func(m *DeviceFlowMutation) { - var ( - err error - once sync.Once - value *DeviceFlow - ) - m.oldValue = func(ctx context.Context) (*DeviceFlow, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().DeviceFlow.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withDeviceFlow sets the old DeviceFlow of the mutation. -func withDeviceFlow(node *DeviceFlow) deviceflowOption { - return func(m *DeviceFlowMutation) { - m.oldValue = func(context.Context) (*DeviceFlow, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m DeviceFlowMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m DeviceFlowMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, errors.New("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *DeviceFlowMutation) ID() (id int, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// IDs queries the database and returns the entity ids that match the mutation's predicate. -// That means, if the mutation is applied within a transaction with an isolation level such -// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated -// or updated by the mutation. -func (m *DeviceFlowMutation) IDs(ctx context.Context) ([]int, error) { - switch { - case m.op.Is(OpUpdateOne | OpDeleteOne): - id, exists := m.ID() - if exists { - return []int{id}, nil - } - fallthrough - case m.op.Is(OpUpdate | OpDelete): - return m.Client().DeviceFlow.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } -} - -// SetCreatedAt sets the "created_at" field. -func (m *DeviceFlowMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *DeviceFlowMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the DeviceFlow entity. -// If the DeviceFlow 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 *DeviceFlowMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) - } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *DeviceFlowMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetIdentifier sets the "identifier" field. -func (m *DeviceFlowMutation) SetIdentifier(s string) { - m.identifier = &s -} - -// Identifier returns the value of the "identifier" field in the mutation. -func (m *DeviceFlowMutation) Identifier() (r string, exists bool) { - v := m.identifier - if v == nil { - return - } - return *v, true -} - -// OldIdentifier returns the old "identifier" field's value of the DeviceFlow entity. -// If the DeviceFlow 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 *DeviceFlowMutation) OldIdentifier(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldIdentifier is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldIdentifier requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldIdentifier: %w", err) - } - return oldValue.Identifier, nil -} - -// ResetIdentifier resets all changes to the "identifier" field. -func (m *DeviceFlowMutation) ResetIdentifier() { - m.identifier = nil -} - -// SetDeviceCode sets the "device_code" field. -func (m *DeviceFlowMutation) SetDeviceCode(s string) { - m.device_code = &s -} - -// DeviceCode returns the value of the "device_code" field in the mutation. -func (m *DeviceFlowMutation) DeviceCode() (r string, exists bool) { - v := m.device_code - if v == nil { - return - } - return *v, true -} - -// OldDeviceCode returns the old "device_code" field's value of the DeviceFlow entity. -// If the DeviceFlow 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 *DeviceFlowMutation) OldDeviceCode(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDeviceCode is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDeviceCode requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDeviceCode: %w", err) - } - return oldValue.DeviceCode, nil -} - -// ResetDeviceCode resets all changes to the "device_code" field. -func (m *DeviceFlowMutation) ResetDeviceCode() { - m.device_code = nil -} - -// SetUserCode sets the "user_code" field. -func (m *DeviceFlowMutation) SetUserCode(s string) { - m.user_code = &s -} - -// UserCode returns the value of the "user_code" field in the mutation. -func (m *DeviceFlowMutation) UserCode() (r string, exists bool) { - v := m.user_code - if v == nil { - return - } - return *v, true -} - -// OldUserCode returns the old "user_code" field's value of the DeviceFlow entity. -// If the DeviceFlow 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 *DeviceFlowMutation) OldUserCode(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUserCode is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUserCode requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUserCode: %w", err) - } - return oldValue.UserCode, nil -} - -// ResetUserCode resets all changes to the "user_code" field. -func (m *DeviceFlowMutation) ResetUserCode() { - m.user_code = nil -} - -// SetSession sets the "session" field. -func (m *DeviceFlowMutation) SetSession(s string) { - m.session = &s -} - -// Session returns the value of the "session" field in the mutation. -func (m *DeviceFlowMutation) Session() (r string, exists bool) { - v := m.session - if v == nil { - return - } - return *v, true -} - -// OldSession returns the old "session" field's value of the DeviceFlow entity. -// If the DeviceFlow 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 *DeviceFlowMutation) OldSession(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSession is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSession requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldSession: %w", err) - } - return oldValue.Session, nil -} - -// ClearSession clears the value of the "session" field. -func (m *DeviceFlowMutation) ClearSession() { - m.session = nil - m.clearedFields[deviceflow.FieldSession] = struct{}{} -} - -// SessionCleared returns if the "session" field was cleared in this mutation. -func (m *DeviceFlowMutation) SessionCleared() bool { - _, ok := m.clearedFields[deviceflow.FieldSession] - return ok -} - -// ResetSession resets all changes to the "session" field. -func (m *DeviceFlowMutation) ResetSession() { - m.session = nil - delete(m.clearedFields, deviceflow.FieldSession) -} - -// SetLastPoll sets the "last_poll" field. -func (m *DeviceFlowMutation) SetLastPoll(t time.Time) { - m.last_poll = &t -} - -// LastPoll returns the value of the "last_poll" field in the mutation. -func (m *DeviceFlowMutation) LastPoll() (r time.Time, exists bool) { - v := m.last_poll - if v == nil { - return - } - return *v, true -} - -// OldLastPoll returns the old "last_poll" field's value of the DeviceFlow entity. -// If the DeviceFlow 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 *DeviceFlowMutation) OldLastPoll(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldLastPoll is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldLastPoll requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldLastPoll: %w", err) - } - return oldValue.LastPoll, nil -} - -// ResetLastPoll resets all changes to the "last_poll" field. -func (m *DeviceFlowMutation) ResetLastPoll() { - m.last_poll = nil -} - -// SetExpiresAt sets the "expires_at" field. -func (m *DeviceFlowMutation) SetExpiresAt(t time.Time) { - m.expires_at = &t -} - -// ExpiresAt returns the value of the "expires_at" field in the mutation. -func (m *DeviceFlowMutation) ExpiresAt() (r time.Time, exists bool) { - v := m.expires_at - if v == nil { - return - } - return *v, true -} - -// OldExpiresAt returns the old "expires_at" field's value of the DeviceFlow entity. -// If the DeviceFlow 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 *DeviceFlowMutation) OldExpiresAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldExpiresAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err) - } - return oldValue.ExpiresAt, nil -} - -// ClearExpiresAt clears the value of the "expires_at" field. -func (m *DeviceFlowMutation) ClearExpiresAt() { - m.expires_at = nil - m.clearedFields[deviceflow.FieldExpiresAt] = struct{}{} -} - -// ExpiresAtCleared returns if the "expires_at" field was cleared in this mutation. -func (m *DeviceFlowMutation) ExpiresAtCleared() bool { - _, ok := m.clearedFields[deviceflow.FieldExpiresAt] - return ok -} - -// ResetExpiresAt resets all changes to the "expires_at" field. -func (m *DeviceFlowMutation) ResetExpiresAt() { - m.expires_at = nil - delete(m.clearedFields, deviceflow.FieldExpiresAt) -} - -// Where appends a list predicates to the DeviceFlowMutation builder. -func (m *DeviceFlowMutation) Where(ps ...predicate.DeviceFlow) { - m.predicates = append(m.predicates, ps...) -} - -// WhereP appends storage-level predicates to the DeviceFlowMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *DeviceFlowMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.DeviceFlow, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) -} - -// Op returns the operation name. -func (m *DeviceFlowMutation) Op() Op { - return m.op -} - -// SetOp allows setting the mutation operation. -func (m *DeviceFlowMutation) SetOp(op Op) { - m.op = op -} - -// Type returns the node type of this mutation (DeviceFlow). -func (m *DeviceFlowMutation) 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 incremented/decremented, call -// AddedFields(). -func (m *DeviceFlowMutation) Fields() []string { - fields := make([]string, 0, 7) - if m.created_at != nil { - fields = append(fields, deviceflow.FieldCreatedAt) - } - if m.identifier != nil { - fields = append(fields, deviceflow.FieldIdentifier) - } - if m.device_code != nil { - fields = append(fields, deviceflow.FieldDeviceCode) - } - if m.user_code != nil { - fields = append(fields, deviceflow.FieldUserCode) - } - if m.session != nil { - fields = append(fields, deviceflow.FieldSession) - } - if m.last_poll != nil { - fields = append(fields, deviceflow.FieldLastPoll) - } - if m.expires_at != nil { - fields = append(fields, deviceflow.FieldExpiresAt) - } - return fields -} - -// 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 *DeviceFlowMutation) Field(name string) (ent.Value, bool) { - switch name { - case deviceflow.FieldCreatedAt: - return m.CreatedAt() - case deviceflow.FieldIdentifier: - return m.Identifier() - case deviceflow.FieldDeviceCode: - return m.DeviceCode() - case deviceflow.FieldUserCode: - return m.UserCode() - case deviceflow.FieldSession: - return m.Session() - case deviceflow.FieldLastPoll: - return m.LastPoll() - case deviceflow.FieldExpiresAt: - return m.ExpiresAt() - } - 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 failed. -func (m *DeviceFlowMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case deviceflow.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case deviceflow.FieldIdentifier: - return m.OldIdentifier(ctx) - case deviceflow.FieldDeviceCode: - return m.OldDeviceCode(ctx) - case deviceflow.FieldUserCode: - return m.OldUserCode(ctx) - case deviceflow.FieldSession: - return m.OldSession(ctx) - case deviceflow.FieldLastPoll: - return m.OldLastPoll(ctx) - case deviceflow.FieldExpiresAt: - return m.OldExpiresAt(ctx) - } - return nil, fmt.Errorf("unknown DeviceFlow field %s", name) -} - -// 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 *DeviceFlowMutation) SetField(name string, value ent.Value) error { - switch name { - case deviceflow.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case deviceflow.FieldIdentifier: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetIdentifier(v) - return nil - case deviceflow.FieldDeviceCode: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDeviceCode(v) - return nil - case deviceflow.FieldUserCode: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUserCode(v) - return nil - case deviceflow.FieldSession: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetSession(v) - return nil - case deviceflow.FieldLastPoll: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetLastPoll(v) - return nil - case deviceflow.FieldExpiresAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetExpiresAt(v) - return nil - } - return fmt.Errorf("unknown DeviceFlow field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *DeviceFlowMutation) AddedFields() []string { - return nil -} - -// 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 *DeviceFlowMutation) AddedField(name string) (ent.Value, bool) { - return nil, false -} - -// 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 *DeviceFlowMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown DeviceFlow numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *DeviceFlowMutation) ClearedFields() []string { - var fields []string - if m.FieldCleared(deviceflow.FieldSession) { - fields = append(fields, deviceflow.FieldSession) - } - if m.FieldCleared(deviceflow.FieldExpiresAt) { - fields = append(fields, deviceflow.FieldExpiresAt) - } - return fields -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *DeviceFlowMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// 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 *DeviceFlowMutation) ClearField(name string) error { - switch name { - case deviceflow.FieldSession: - m.ClearSession() - return nil - case deviceflow.FieldExpiresAt: - m.ClearExpiresAt() - return nil - } - return fmt.Errorf("unknown DeviceFlow nullable field %s", name) -} - -// 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 *DeviceFlowMutation) ResetField(name string) error { - switch name { - case deviceflow.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case deviceflow.FieldIdentifier: - m.ResetIdentifier() - return nil - case deviceflow.FieldDeviceCode: - m.ResetDeviceCode() - return nil - case deviceflow.FieldUserCode: - m.ResetUserCode() - return nil - case deviceflow.FieldSession: - m.ResetSession() - return nil - case deviceflow.FieldLastPoll: - m.ResetLastPoll() - return nil - case deviceflow.FieldExpiresAt: - m.ResetExpiresAt() - return nil - } - return fmt.Errorf("unknown DeviceFlow field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *DeviceFlowMutation) AddedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *DeviceFlowMutation) AddedIDs(name string) []ent.Value { - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *DeviceFlowMutation) RemovedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *DeviceFlowMutation) RemovedIDs(name string) []ent.Value { - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *DeviceFlowMutation) ClearedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *DeviceFlowMutation) EdgeCleared(name string) bool { - return false -} - -// 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 *DeviceFlowMutation) ClearEdge(name string) error { - return fmt.Errorf("unknown DeviceFlow unique edge %s", name) -} - -// 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 *DeviceFlowMutation) ResetEdge(name string) error { - return fmt.Errorf("unknown DeviceFlow edge %s", name) -} - -// GithubFlowMutation represents an operation that mutates the GithubFlow nodes in the graph. -type GithubFlowMutation struct { - config - op Op - typ string - id *int - created_at *time.Time - identifier *string - verifier *string - challenge *string - next_url *string - organization *string - device_identifier *string - clearedFields map[string]struct{} - done bool - oldValue func(context.Context) (*GithubFlow, error) - predicates []predicate.GithubFlow -} - -var _ ent.Mutation = (*GithubFlowMutation)(nil) - -// githubflowOption allows management of the mutation configuration using functional options. -type githubflowOption func(*GithubFlowMutation) - -// newGithubFlowMutation creates new mutation for the GithubFlow entity. -func newGithubFlowMutation(c config, op Op, opts ...githubflowOption) *GithubFlowMutation { - m := &GithubFlowMutation{ - config: c, - op: op, - typ: TypeGithubFlow, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withGithubFlowID sets the ID field of the mutation. -func withGithubFlowID(id int) githubflowOption { - return func(m *GithubFlowMutation) { - var ( - err error - once sync.Once - value *GithubFlow - ) - m.oldValue = func(ctx context.Context) (*GithubFlow, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().GithubFlow.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withGithubFlow sets the old GithubFlow of the mutation. -func withGithubFlow(node *GithubFlow) githubflowOption { - return func(m *GithubFlowMutation) { - m.oldValue = func(context.Context) (*GithubFlow, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m GithubFlowMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m GithubFlowMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, errors.New("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *GithubFlowMutation) ID() (id int, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// IDs queries the database and returns the entity ids that match the mutation's predicate. -// That means, if the mutation is applied within a transaction with an isolation level such -// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated -// or updated by the mutation. -func (m *GithubFlowMutation) IDs(ctx context.Context) ([]int, error) { - switch { - case m.op.Is(OpUpdateOne | OpDeleteOne): - id, exists := m.ID() - if exists { - return []int{id}, nil - } - fallthrough - case m.op.Is(OpUpdate | OpDelete): - return m.Client().GithubFlow.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } -} - -// SetCreatedAt sets the "created_at" field. -func (m *GithubFlowMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *GithubFlowMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the GithubFlow entity. -// If the GithubFlow 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 *GithubFlowMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) - } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *GithubFlowMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetIdentifier sets the "identifier" field. -func (m *GithubFlowMutation) SetIdentifier(s string) { - m.identifier = &s -} - -// Identifier returns the value of the "identifier" field in the mutation. -func (m *GithubFlowMutation) Identifier() (r string, exists bool) { - v := m.identifier - if v == nil { - return - } - return *v, true -} - -// OldIdentifier returns the old "identifier" field's value of the GithubFlow entity. -// If the GithubFlow 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 *GithubFlowMutation) OldIdentifier(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldIdentifier is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldIdentifier requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldIdentifier: %w", err) - } - return oldValue.Identifier, nil -} - -// ResetIdentifier resets all changes to the "identifier" field. -func (m *GithubFlowMutation) ResetIdentifier() { - m.identifier = nil -} - -// SetVerifier sets the "verifier" field. -func (m *GithubFlowMutation) SetVerifier(s string) { - m.verifier = &s -} - -// Verifier returns the value of the "verifier" field in the mutation. -func (m *GithubFlowMutation) Verifier() (r string, exists bool) { - v := m.verifier - if v == nil { - return - } - return *v, true -} - -// OldVerifier returns the old "verifier" field's value of the GithubFlow entity. -// If the GithubFlow 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 *GithubFlowMutation) OldVerifier(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldVerifier is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldVerifier requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldVerifier: %w", err) - } - return oldValue.Verifier, nil -} - -// ResetVerifier resets all changes to the "verifier" field. -func (m *GithubFlowMutation) ResetVerifier() { - m.verifier = nil -} - -// SetChallenge sets the "challenge" field. -func (m *GithubFlowMutation) SetChallenge(s string) { - m.challenge = &s -} - -// Challenge returns the value of the "challenge" field in the mutation. -func (m *GithubFlowMutation) Challenge() (r string, exists bool) { - v := m.challenge - if v == nil { - return - } - return *v, true -} - -// OldChallenge returns the old "challenge" field's value of the GithubFlow entity. -// If the GithubFlow 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 *GithubFlowMutation) OldChallenge(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldChallenge is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldChallenge requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldChallenge: %w", err) - } - return oldValue.Challenge, nil -} - -// ResetChallenge resets all changes to the "challenge" field. -func (m *GithubFlowMutation) ResetChallenge() { - m.challenge = nil -} - -// SetNextURL sets the "next_url" field. -func (m *GithubFlowMutation) SetNextURL(s string) { - m.next_url = &s -} - -// NextURL returns the value of the "next_url" field in the mutation. -func (m *GithubFlowMutation) NextURL() (r string, exists bool) { - v := m.next_url - if v == nil { - return - } - return *v, true -} - -// OldNextURL returns the old "next_url" field's value of the GithubFlow entity. -// If the GithubFlow 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 *GithubFlowMutation) OldNextURL(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldNextURL is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldNextURL requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldNextURL: %w", err) - } - return oldValue.NextURL, nil -} - -// ResetNextURL resets all changes to the "next_url" field. -func (m *GithubFlowMutation) ResetNextURL() { - m.next_url = nil -} - -// SetOrganization sets the "organization" field. -func (m *GithubFlowMutation) SetOrganization(s string) { - m.organization = &s -} - -// Organization returns the value of the "organization" field in the mutation. -func (m *GithubFlowMutation) Organization() (r string, exists bool) { - v := m.organization - if v == nil { - return - } - return *v, true -} - -// OldOrganization returns the old "organization" field's value of the GithubFlow entity. -// If the GithubFlow 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 *GithubFlowMutation) OldOrganization(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldOrganization is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldOrganization requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldOrganization: %w", err) - } - return oldValue.Organization, nil -} - -// ClearOrganization clears the value of the "organization" field. -func (m *GithubFlowMutation) ClearOrganization() { - m.organization = nil - m.clearedFields[githubflow.FieldOrganization] = struct{}{} -} - -// OrganizationCleared returns if the "organization" field was cleared in this mutation. -func (m *GithubFlowMutation) OrganizationCleared() bool { - _, ok := m.clearedFields[githubflow.FieldOrganization] - return ok -} - -// ResetOrganization resets all changes to the "organization" field. -func (m *GithubFlowMutation) ResetOrganization() { - m.organization = nil - delete(m.clearedFields, githubflow.FieldOrganization) -} - -// SetDeviceIdentifier sets the "device_identifier" field. -func (m *GithubFlowMutation) SetDeviceIdentifier(s string) { - m.device_identifier = &s -} - -// DeviceIdentifier returns the value of the "device_identifier" field in the mutation. -func (m *GithubFlowMutation) DeviceIdentifier() (r string, exists bool) { - v := m.device_identifier - if v == nil { - return - } - return *v, true -} - -// OldDeviceIdentifier returns the old "device_identifier" field's value of the GithubFlow entity. -// If the GithubFlow 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 *GithubFlowMutation) OldDeviceIdentifier(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDeviceIdentifier is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDeviceIdentifier requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDeviceIdentifier: %w", err) - } - return oldValue.DeviceIdentifier, nil -} - -// ClearDeviceIdentifier clears the value of the "device_identifier" field. -func (m *GithubFlowMutation) ClearDeviceIdentifier() { - m.device_identifier = nil - m.clearedFields[githubflow.FieldDeviceIdentifier] = struct{}{} -} - -// DeviceIdentifierCleared returns if the "device_identifier" field was cleared in this mutation. -func (m *GithubFlowMutation) DeviceIdentifierCleared() bool { - _, ok := m.clearedFields[githubflow.FieldDeviceIdentifier] - return ok -} - -// ResetDeviceIdentifier resets all changes to the "device_identifier" field. -func (m *GithubFlowMutation) ResetDeviceIdentifier() { - m.device_identifier = nil - delete(m.clearedFields, githubflow.FieldDeviceIdentifier) -} - -// Where appends a list predicates to the GithubFlowMutation builder. -func (m *GithubFlowMutation) Where(ps ...predicate.GithubFlow) { - m.predicates = append(m.predicates, ps...) -} - -// WhereP appends storage-level predicates to the GithubFlowMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *GithubFlowMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.GithubFlow, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) -} - -// Op returns the operation name. -func (m *GithubFlowMutation) Op() Op { - return m.op -} - -// SetOp allows setting the mutation operation. -func (m *GithubFlowMutation) SetOp(op Op) { - m.op = op -} - -// Type returns the node type of this mutation (GithubFlow). -func (m *GithubFlowMutation) 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 incremented/decremented, call -// AddedFields(). -func (m *GithubFlowMutation) Fields() []string { - fields := make([]string, 0, 7) - if m.created_at != nil { - fields = append(fields, githubflow.FieldCreatedAt) - } - if m.identifier != nil { - fields = append(fields, githubflow.FieldIdentifier) - } - if m.verifier != nil { - fields = append(fields, githubflow.FieldVerifier) - } - if m.challenge != nil { - fields = append(fields, githubflow.FieldChallenge) - } - if m.next_url != nil { - fields = append(fields, githubflow.FieldNextURL) - } - if m.organization != nil { - fields = append(fields, githubflow.FieldOrganization) - } - if m.device_identifier != nil { - fields = append(fields, githubflow.FieldDeviceIdentifier) - } - return fields -} - -// 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 *GithubFlowMutation) Field(name string) (ent.Value, bool) { - switch name { - case githubflow.FieldCreatedAt: - return m.CreatedAt() - case githubflow.FieldIdentifier: - return m.Identifier() - case githubflow.FieldVerifier: - return m.Verifier() - case githubflow.FieldChallenge: - return m.Challenge() - case githubflow.FieldNextURL: - return m.NextURL() - case githubflow.FieldOrganization: - return m.Organization() - case githubflow.FieldDeviceIdentifier: - return m.DeviceIdentifier() - } - 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 failed. -func (m *GithubFlowMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case githubflow.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case githubflow.FieldIdentifier: - return m.OldIdentifier(ctx) - case githubflow.FieldVerifier: - return m.OldVerifier(ctx) - case githubflow.FieldChallenge: - return m.OldChallenge(ctx) - case githubflow.FieldNextURL: - return m.OldNextURL(ctx) - case githubflow.FieldOrganization: - return m.OldOrganization(ctx) - case githubflow.FieldDeviceIdentifier: - return m.OldDeviceIdentifier(ctx) - } - return nil, fmt.Errorf("unknown GithubFlow field %s", name) -} - -// 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 *GithubFlowMutation) SetField(name string, value ent.Value) error { - switch name { - case githubflow.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case githubflow.FieldIdentifier: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetIdentifier(v) - return nil - case githubflow.FieldVerifier: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetVerifier(v) - return nil - case githubflow.FieldChallenge: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetChallenge(v) - return nil - case githubflow.FieldNextURL: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetNextURL(v) - return nil - case githubflow.FieldOrganization: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetOrganization(v) - return nil - case githubflow.FieldDeviceIdentifier: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDeviceIdentifier(v) - return nil - } - return fmt.Errorf("unknown GithubFlow field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *GithubFlowMutation) AddedFields() []string { - return nil -} - -// 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 *GithubFlowMutation) AddedField(name string) (ent.Value, bool) { - return nil, false -} - -// 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 *GithubFlowMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown GithubFlow numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *GithubFlowMutation) ClearedFields() []string { - var fields []string - if m.FieldCleared(githubflow.FieldOrganization) { - fields = append(fields, githubflow.FieldOrganization) - } - if m.FieldCleared(githubflow.FieldDeviceIdentifier) { - fields = append(fields, githubflow.FieldDeviceIdentifier) - } - return fields -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *GithubFlowMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// 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 *GithubFlowMutation) ClearField(name string) error { - switch name { - case githubflow.FieldOrganization: - m.ClearOrganization() - return nil - case githubflow.FieldDeviceIdentifier: - m.ClearDeviceIdentifier() - return nil - } - return fmt.Errorf("unknown GithubFlow nullable field %s", name) -} - -// 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 *GithubFlowMutation) ResetField(name string) error { - switch name { - case githubflow.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case githubflow.FieldIdentifier: - m.ResetIdentifier() - return nil - case githubflow.FieldVerifier: - m.ResetVerifier() - return nil - case githubflow.FieldChallenge: - m.ResetChallenge() - return nil - case githubflow.FieldNextURL: - m.ResetNextURL() - return nil - case githubflow.FieldOrganization: - m.ResetOrganization() - return nil - case githubflow.FieldDeviceIdentifier: - m.ResetDeviceIdentifier() - return nil - } - return fmt.Errorf("unknown GithubFlow field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *GithubFlowMutation) AddedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *GithubFlowMutation) AddedIDs(name string) []ent.Value { - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *GithubFlowMutation) RemovedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *GithubFlowMutation) RemovedIDs(name string) []ent.Value { - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *GithubFlowMutation) ClearedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *GithubFlowMutation) EdgeCleared(name string) bool { - return false -} - -// 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 *GithubFlowMutation) ClearEdge(name string) error { - return fmt.Errorf("unknown GithubFlow unique edge %s", name) -} - -// 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 *GithubFlowMutation) ResetEdge(name string) error { - return fmt.Errorf("unknown GithubFlow edge %s", name) -} - -// GoogleFlowMutation represents an operation that mutates the GoogleFlow nodes in the graph. -type GoogleFlowMutation struct { - config - op Op - typ string - id *int - created_at *time.Time - identifier *string - verifier *string - challenge *string - next_url *string - organization *string - device_identifier *string - clearedFields map[string]struct{} - done bool - oldValue func(context.Context) (*GoogleFlow, error) - predicates []predicate.GoogleFlow -} - -var _ ent.Mutation = (*GoogleFlowMutation)(nil) - -// googleflowOption allows management of the mutation configuration using functional options. -type googleflowOption func(*GoogleFlowMutation) - -// newGoogleFlowMutation creates new mutation for the GoogleFlow entity. -func newGoogleFlowMutation(c config, op Op, opts ...googleflowOption) *GoogleFlowMutation { - m := &GoogleFlowMutation{ - config: c, - op: op, - typ: TypeGoogleFlow, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withGoogleFlowID sets the ID field of the mutation. -func withGoogleFlowID(id int) googleflowOption { - return func(m *GoogleFlowMutation) { - var ( - err error - once sync.Once - value *GoogleFlow - ) - m.oldValue = func(ctx context.Context) (*GoogleFlow, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().GoogleFlow.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withGoogleFlow sets the old GoogleFlow of the mutation. -func withGoogleFlow(node *GoogleFlow) googleflowOption { - return func(m *GoogleFlowMutation) { - m.oldValue = func(context.Context) (*GoogleFlow, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m GoogleFlowMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m GoogleFlowMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, errors.New("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *GoogleFlowMutation) ID() (id int, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// IDs queries the database and returns the entity ids that match the mutation's predicate. -// That means, if the mutation is applied within a transaction with an isolation level such -// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated -// or updated by the mutation. -func (m *GoogleFlowMutation) IDs(ctx context.Context) ([]int, error) { - switch { - case m.op.Is(OpUpdateOne | OpDeleteOne): - id, exists := m.ID() - if exists { - return []int{id}, nil - } - fallthrough - case m.op.Is(OpUpdate | OpDelete): - return m.Client().GoogleFlow.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } -} - -// SetCreatedAt sets the "created_at" field. -func (m *GoogleFlowMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *GoogleFlowMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the GoogleFlow entity. -// If the GoogleFlow 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 *GoogleFlowMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) - } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *GoogleFlowMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetIdentifier sets the "identifier" field. -func (m *GoogleFlowMutation) SetIdentifier(s string) { - m.identifier = &s -} - -// Identifier returns the value of the "identifier" field in the mutation. -func (m *GoogleFlowMutation) Identifier() (r string, exists bool) { - v := m.identifier - if v == nil { - return - } - return *v, true -} - -// OldIdentifier returns the old "identifier" field's value of the GoogleFlow entity. -// If the GoogleFlow 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 *GoogleFlowMutation) OldIdentifier(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldIdentifier is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldIdentifier requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldIdentifier: %w", err) - } - return oldValue.Identifier, nil -} - -// ResetIdentifier resets all changes to the "identifier" field. -func (m *GoogleFlowMutation) ResetIdentifier() { - m.identifier = nil -} - -// SetVerifier sets the "verifier" field. -func (m *GoogleFlowMutation) SetVerifier(s string) { - m.verifier = &s -} - -// Verifier returns the value of the "verifier" field in the mutation. -func (m *GoogleFlowMutation) Verifier() (r string, exists bool) { - v := m.verifier - if v == nil { - return - } - return *v, true -} - -// OldVerifier returns the old "verifier" field's value of the GoogleFlow entity. -// If the GoogleFlow 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 *GoogleFlowMutation) OldVerifier(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldVerifier is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldVerifier requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldVerifier: %w", err) - } - return oldValue.Verifier, nil -} - -// ResetVerifier resets all changes to the "verifier" field. -func (m *GoogleFlowMutation) ResetVerifier() { - m.verifier = nil -} - -// SetChallenge sets the "challenge" field. -func (m *GoogleFlowMutation) SetChallenge(s string) { - m.challenge = &s -} - -// Challenge returns the value of the "challenge" field in the mutation. -func (m *GoogleFlowMutation) Challenge() (r string, exists bool) { - v := m.challenge - if v == nil { - return - } - return *v, true -} - -// OldChallenge returns the old "challenge" field's value of the GoogleFlow entity. -// If the GoogleFlow 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 *GoogleFlowMutation) OldChallenge(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldChallenge is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldChallenge requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldChallenge: %w", err) - } - return oldValue.Challenge, nil -} - -// ResetChallenge resets all changes to the "challenge" field. -func (m *GoogleFlowMutation) ResetChallenge() { - m.challenge = nil -} - -// SetNextURL sets the "next_url" field. -func (m *GoogleFlowMutation) SetNextURL(s string) { - m.next_url = &s -} - -// NextURL returns the value of the "next_url" field in the mutation. -func (m *GoogleFlowMutation) NextURL() (r string, exists bool) { - v := m.next_url - if v == nil { - return - } - return *v, true -} - -// OldNextURL returns the old "next_url" field's value of the GoogleFlow entity. -// If the GoogleFlow 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 *GoogleFlowMutation) OldNextURL(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldNextURL is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldNextURL requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldNextURL: %w", err) - } - return oldValue.NextURL, nil -} - -// ResetNextURL resets all changes to the "next_url" field. -func (m *GoogleFlowMutation) ResetNextURL() { - m.next_url = nil -} - -// SetOrganization sets the "organization" field. -func (m *GoogleFlowMutation) SetOrganization(s string) { - m.organization = &s -} - -// Organization returns the value of the "organization" field in the mutation. -func (m *GoogleFlowMutation) Organization() (r string, exists bool) { - v := m.organization - if v == nil { - return - } - return *v, true -} - -// OldOrganization returns the old "organization" field's value of the GoogleFlow entity. -// If the GoogleFlow 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 *GoogleFlowMutation) OldOrganization(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldOrganization is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldOrganization requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldOrganization: %w", err) - } - return oldValue.Organization, nil -} - -// ClearOrganization clears the value of the "organization" field. -func (m *GoogleFlowMutation) ClearOrganization() { - m.organization = nil - m.clearedFields[googleflow.FieldOrganization] = struct{}{} -} - -// OrganizationCleared returns if the "organization" field was cleared in this mutation. -func (m *GoogleFlowMutation) OrganizationCleared() bool { - _, ok := m.clearedFields[googleflow.FieldOrganization] - return ok -} - -// ResetOrganization resets all changes to the "organization" field. -func (m *GoogleFlowMutation) ResetOrganization() { - m.organization = nil - delete(m.clearedFields, googleflow.FieldOrganization) -} - -// SetDeviceIdentifier sets the "device_identifier" field. -func (m *GoogleFlowMutation) SetDeviceIdentifier(s string) { - m.device_identifier = &s -} - -// DeviceIdentifier returns the value of the "device_identifier" field in the mutation. -func (m *GoogleFlowMutation) DeviceIdentifier() (r string, exists bool) { - v := m.device_identifier - if v == nil { - return - } - return *v, true -} - -// OldDeviceIdentifier returns the old "device_identifier" field's value of the GoogleFlow entity. -// If the GoogleFlow 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 *GoogleFlowMutation) OldDeviceIdentifier(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDeviceIdentifier is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDeviceIdentifier requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDeviceIdentifier: %w", err) - } - return oldValue.DeviceIdentifier, nil -} - -// ClearDeviceIdentifier clears the value of the "device_identifier" field. -func (m *GoogleFlowMutation) ClearDeviceIdentifier() { - m.device_identifier = nil - m.clearedFields[googleflow.FieldDeviceIdentifier] = struct{}{} -} - -// DeviceIdentifierCleared returns if the "device_identifier" field was cleared in this mutation. -func (m *GoogleFlowMutation) DeviceIdentifierCleared() bool { - _, ok := m.clearedFields[googleflow.FieldDeviceIdentifier] - return ok -} - -// ResetDeviceIdentifier resets all changes to the "device_identifier" field. -func (m *GoogleFlowMutation) ResetDeviceIdentifier() { - m.device_identifier = nil - delete(m.clearedFields, googleflow.FieldDeviceIdentifier) -} - -// Where appends a list predicates to the GoogleFlowMutation builder. -func (m *GoogleFlowMutation) Where(ps ...predicate.GoogleFlow) { - m.predicates = append(m.predicates, ps...) -} - -// WhereP appends storage-level predicates to the GoogleFlowMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *GoogleFlowMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.GoogleFlow, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) -} - -// Op returns the operation name. -func (m *GoogleFlowMutation) Op() Op { - return m.op -} - -// SetOp allows setting the mutation operation. -func (m *GoogleFlowMutation) SetOp(op Op) { - m.op = op -} - -// Type returns the node type of this mutation (GoogleFlow). -func (m *GoogleFlowMutation) 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 incremented/decremented, call -// AddedFields(). -func (m *GoogleFlowMutation) Fields() []string { - fields := make([]string, 0, 7) - if m.created_at != nil { - fields = append(fields, googleflow.FieldCreatedAt) - } - if m.identifier != nil { - fields = append(fields, googleflow.FieldIdentifier) - } - if m.verifier != nil { - fields = append(fields, googleflow.FieldVerifier) - } - if m.challenge != nil { - fields = append(fields, googleflow.FieldChallenge) - } - if m.next_url != nil { - fields = append(fields, googleflow.FieldNextURL) - } - if m.organization != nil { - fields = append(fields, googleflow.FieldOrganization) - } - if m.device_identifier != nil { - fields = append(fields, googleflow.FieldDeviceIdentifier) - } - return fields -} - -// 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 *GoogleFlowMutation) Field(name string) (ent.Value, bool) { - switch name { - case googleflow.FieldCreatedAt: - return m.CreatedAt() - case googleflow.FieldIdentifier: - return m.Identifier() - case googleflow.FieldVerifier: - return m.Verifier() - case googleflow.FieldChallenge: - return m.Challenge() - case googleflow.FieldNextURL: - return m.NextURL() - case googleflow.FieldOrganization: - return m.Organization() - case googleflow.FieldDeviceIdentifier: - return m.DeviceIdentifier() - } - 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 failed. -func (m *GoogleFlowMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case googleflow.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case googleflow.FieldIdentifier: - return m.OldIdentifier(ctx) - case googleflow.FieldVerifier: - return m.OldVerifier(ctx) - case googleflow.FieldChallenge: - return m.OldChallenge(ctx) - case googleflow.FieldNextURL: - return m.OldNextURL(ctx) - case googleflow.FieldOrganization: - return m.OldOrganization(ctx) - case googleflow.FieldDeviceIdentifier: - return m.OldDeviceIdentifier(ctx) - } - return nil, fmt.Errorf("unknown GoogleFlow field %s", name) -} - -// 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 *GoogleFlowMutation) SetField(name string, value ent.Value) error { - switch name { - case googleflow.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case googleflow.FieldIdentifier: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetIdentifier(v) - return nil - case googleflow.FieldVerifier: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetVerifier(v) - return nil - case googleflow.FieldChallenge: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetChallenge(v) - return nil - case googleflow.FieldNextURL: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetNextURL(v) - return nil - case googleflow.FieldOrganization: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetOrganization(v) - return nil - case googleflow.FieldDeviceIdentifier: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDeviceIdentifier(v) - return nil - } - return fmt.Errorf("unknown GoogleFlow field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *GoogleFlowMutation) AddedFields() []string { - return nil -} - -// 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 *GoogleFlowMutation) AddedField(name string) (ent.Value, bool) { - return nil, false -} - -// 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 *GoogleFlowMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown GoogleFlow numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *GoogleFlowMutation) ClearedFields() []string { - var fields []string - if m.FieldCleared(googleflow.FieldOrganization) { - fields = append(fields, googleflow.FieldOrganization) - } - if m.FieldCleared(googleflow.FieldDeviceIdentifier) { - fields = append(fields, googleflow.FieldDeviceIdentifier) - } - return fields -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *GoogleFlowMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// 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 *GoogleFlowMutation) ClearField(name string) error { - switch name { - case googleflow.FieldOrganization: - m.ClearOrganization() - return nil - case googleflow.FieldDeviceIdentifier: - m.ClearDeviceIdentifier() - return nil - } - return fmt.Errorf("unknown GoogleFlow nullable field %s", name) -} - -// 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 *GoogleFlowMutation) ResetField(name string) error { - switch name { - case googleflow.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case googleflow.FieldIdentifier: - m.ResetIdentifier() - return nil - case googleflow.FieldVerifier: - m.ResetVerifier() - return nil - case googleflow.FieldChallenge: - m.ResetChallenge() - return nil - case googleflow.FieldNextURL: - m.ResetNextURL() - return nil - case googleflow.FieldOrganization: - m.ResetOrganization() - return nil - case googleflow.FieldDeviceIdentifier: - m.ResetDeviceIdentifier() - return nil - } - return fmt.Errorf("unknown GoogleFlow field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *GoogleFlowMutation) AddedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *GoogleFlowMutation) AddedIDs(name string) []ent.Value { - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *GoogleFlowMutation) RemovedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *GoogleFlowMutation) RemovedIDs(name string) []ent.Value { - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *GoogleFlowMutation) ClearedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *GoogleFlowMutation) EdgeCleared(name string) bool { - return false -} - -// 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 *GoogleFlowMutation) ClearEdge(name string) error { - return fmt.Errorf("unknown GoogleFlow unique edge %s", name) -} - -// 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 *GoogleFlowMutation) ResetEdge(name string) error { - return fmt.Errorf("unknown GoogleFlow edge %s", name) -} - -// MagicFlowMutation represents an operation that mutates the MagicFlow nodes in the graph. -type MagicFlowMutation struct { - config - op Op - typ string - id *int - created_at *time.Time - identifier *string - email *string - ip_address *string - secret *string - next_url *string - organization *string - device_identifier *string - clearedFields map[string]struct{} - done bool - oldValue func(context.Context) (*MagicFlow, error) - predicates []predicate.MagicFlow -} - -var _ ent.Mutation = (*MagicFlowMutation)(nil) - -// magicflowOption allows management of the mutation configuration using functional options. -type magicflowOption func(*MagicFlowMutation) - -// newMagicFlowMutation creates new mutation for the MagicFlow entity. -func newMagicFlowMutation(c config, op Op, opts ...magicflowOption) *MagicFlowMutation { - m := &MagicFlowMutation{ - config: c, - op: op, - typ: TypeMagicFlow, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withMagicFlowID sets the ID field of the mutation. -func withMagicFlowID(id int) magicflowOption { - return func(m *MagicFlowMutation) { - var ( - err error - once sync.Once - value *MagicFlow - ) - m.oldValue = func(ctx context.Context) (*MagicFlow, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().MagicFlow.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withMagicFlow sets the old MagicFlow of the mutation. -func withMagicFlow(node *MagicFlow) magicflowOption { - return func(m *MagicFlowMutation) { - m.oldValue = func(context.Context) (*MagicFlow, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m MagicFlowMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m MagicFlowMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, errors.New("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *MagicFlowMutation) ID() (id int, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// IDs queries the database and returns the entity ids that match the mutation's predicate. -// That means, if the mutation is applied within a transaction with an isolation level such -// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated -// or updated by the mutation. -func (m *MagicFlowMutation) IDs(ctx context.Context) ([]int, error) { - switch { - case m.op.Is(OpUpdateOne | OpDeleteOne): - id, exists := m.ID() - if exists { - return []int{id}, nil - } - fallthrough - case m.op.Is(OpUpdate | OpDelete): - return m.Client().MagicFlow.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } -} - -// SetCreatedAt sets the "created_at" field. -func (m *MagicFlowMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *MagicFlowMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the MagicFlow entity. -// If the MagicFlow 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 *MagicFlowMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) - } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *MagicFlowMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetIdentifier sets the "identifier" field. -func (m *MagicFlowMutation) SetIdentifier(s string) { - m.identifier = &s -} - -// Identifier returns the value of the "identifier" field in the mutation. -func (m *MagicFlowMutation) Identifier() (r string, exists bool) { - v := m.identifier - if v == nil { - return - } - return *v, true -} - -// OldIdentifier returns the old "identifier" field's value of the MagicFlow entity. -// If the MagicFlow 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 *MagicFlowMutation) OldIdentifier(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldIdentifier is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldIdentifier requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldIdentifier: %w", err) - } - return oldValue.Identifier, nil -} - -// ResetIdentifier resets all changes to the "identifier" field. -func (m *MagicFlowMutation) ResetIdentifier() { - m.identifier = nil -} - -// SetEmail sets the "email" field. -func (m *MagicFlowMutation) SetEmail(s string) { - m.email = &s -} - -// Email returns the value of the "email" field in the mutation. -func (m *MagicFlowMutation) Email() (r string, exists bool) { - v := m.email - if v == nil { - return - } - return *v, true -} - -// OldEmail returns the old "email" field's value of the MagicFlow entity. -// If the MagicFlow 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 *MagicFlowMutation) OldEmail(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldEmail is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldEmail requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldEmail: %w", err) - } - return oldValue.Email, nil -} - -// ResetEmail resets all changes to the "email" field. -func (m *MagicFlowMutation) ResetEmail() { - m.email = nil -} - -// SetIPAddress sets the "ip_address" field. -func (m *MagicFlowMutation) SetIPAddress(s string) { - m.ip_address = &s -} - -// IPAddress returns the value of the "ip_address" field in the mutation. -func (m *MagicFlowMutation) IPAddress() (r string, exists bool) { - v := m.ip_address - if v == nil { - return - } - return *v, true -} - -// OldIPAddress returns the old "ip_address" field's value of the MagicFlow entity. -// If the MagicFlow 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 *MagicFlowMutation) OldIPAddress(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldIPAddress is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldIPAddress requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldIPAddress: %w", err) - } - return oldValue.IPAddress, nil -} - -// ResetIPAddress resets all changes to the "ip_address" field. -func (m *MagicFlowMutation) ResetIPAddress() { - m.ip_address = nil -} - -// SetSecret sets the "secret" field. -func (m *MagicFlowMutation) SetSecret(s string) { - m.secret = &s -} - -// Secret returns the value of the "secret" field in the mutation. -func (m *MagicFlowMutation) Secret() (r string, exists bool) { - v := m.secret - if v == nil { - return - } - return *v, true -} - -// OldSecret returns the old "secret" field's value of the MagicFlow entity. -// If the MagicFlow 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 *MagicFlowMutation) OldSecret(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSecret is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSecret requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldSecret: %w", err) - } - return oldValue.Secret, nil -} - -// ResetSecret resets all changes to the "secret" field. -func (m *MagicFlowMutation) ResetSecret() { - m.secret = nil -} - -// SetNextURL sets the "next_url" field. -func (m *MagicFlowMutation) SetNextURL(s string) { - m.next_url = &s -} - -// NextURL returns the value of the "next_url" field in the mutation. -func (m *MagicFlowMutation) NextURL() (r string, exists bool) { - v := m.next_url - if v == nil { - return - } - return *v, true -} - -// OldNextURL returns the old "next_url" field's value of the MagicFlow entity. -// If the MagicFlow 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 *MagicFlowMutation) OldNextURL(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldNextURL is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldNextURL requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldNextURL: %w", err) - } - return oldValue.NextURL, nil -} - -// ResetNextURL resets all changes to the "next_url" field. -func (m *MagicFlowMutation) ResetNextURL() { - m.next_url = nil -} - -// SetOrganization sets the "organization" field. -func (m *MagicFlowMutation) SetOrganization(s string) { - m.organization = &s -} - -// Organization returns the value of the "organization" field in the mutation. -func (m *MagicFlowMutation) Organization() (r string, exists bool) { - v := m.organization - if v == nil { - return - } - return *v, true -} - -// OldOrganization returns the old "organization" field's value of the MagicFlow entity. -// If the MagicFlow 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 *MagicFlowMutation) OldOrganization(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldOrganization is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldOrganization requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldOrganization: %w", err) - } - return oldValue.Organization, nil -} - -// ClearOrganization clears the value of the "organization" field. -func (m *MagicFlowMutation) ClearOrganization() { - m.organization = nil - m.clearedFields[magicflow.FieldOrganization] = struct{}{} -} - -// OrganizationCleared returns if the "organization" field was cleared in this mutation. -func (m *MagicFlowMutation) OrganizationCleared() bool { - _, ok := m.clearedFields[magicflow.FieldOrganization] - return ok -} - -// ResetOrganization resets all changes to the "organization" field. -func (m *MagicFlowMutation) ResetOrganization() { - m.organization = nil - delete(m.clearedFields, magicflow.FieldOrganization) -} - -// SetDeviceIdentifier sets the "device_identifier" field. -func (m *MagicFlowMutation) SetDeviceIdentifier(s string) { - m.device_identifier = &s -} - -// DeviceIdentifier returns the value of the "device_identifier" field in the mutation. -func (m *MagicFlowMutation) DeviceIdentifier() (r string, exists bool) { - v := m.device_identifier - if v == nil { - return - } - return *v, true -} - -// OldDeviceIdentifier returns the old "device_identifier" field's value of the MagicFlow entity. -// If the MagicFlow 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 *MagicFlowMutation) OldDeviceIdentifier(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDeviceIdentifier is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDeviceIdentifier requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDeviceIdentifier: %w", err) - } - return oldValue.DeviceIdentifier, nil -} - -// ClearDeviceIdentifier clears the value of the "device_identifier" field. -func (m *MagicFlowMutation) ClearDeviceIdentifier() { - m.device_identifier = nil - m.clearedFields[magicflow.FieldDeviceIdentifier] = struct{}{} -} - -// DeviceIdentifierCleared returns if the "device_identifier" field was cleared in this mutation. -func (m *MagicFlowMutation) DeviceIdentifierCleared() bool { - _, ok := m.clearedFields[magicflow.FieldDeviceIdentifier] - return ok -} - -// ResetDeviceIdentifier resets all changes to the "device_identifier" field. -func (m *MagicFlowMutation) ResetDeviceIdentifier() { - m.device_identifier = nil - delete(m.clearedFields, magicflow.FieldDeviceIdentifier) -} - -// Where appends a list predicates to the MagicFlowMutation builder. -func (m *MagicFlowMutation) Where(ps ...predicate.MagicFlow) { - m.predicates = append(m.predicates, ps...) -} - -// WhereP appends storage-level predicates to the MagicFlowMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *MagicFlowMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.MagicFlow, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) -} - -// Op returns the operation name. -func (m *MagicFlowMutation) Op() Op { - return m.op -} - -// SetOp allows setting the mutation operation. -func (m *MagicFlowMutation) SetOp(op Op) { - m.op = op -} - -// Type returns the node type of this mutation (MagicFlow). -func (m *MagicFlowMutation) 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 incremented/decremented, call -// AddedFields(). -func (m *MagicFlowMutation) Fields() []string { - fields := make([]string, 0, 8) - if m.created_at != nil { - fields = append(fields, magicflow.FieldCreatedAt) - } - if m.identifier != nil { - fields = append(fields, magicflow.FieldIdentifier) - } - if m.email != nil { - fields = append(fields, magicflow.FieldEmail) - } - if m.ip_address != nil { - fields = append(fields, magicflow.FieldIPAddress) - } - if m.secret != nil { - fields = append(fields, magicflow.FieldSecret) - } - if m.next_url != nil { - fields = append(fields, magicflow.FieldNextURL) - } - if m.organization != nil { - fields = append(fields, magicflow.FieldOrganization) - } - if m.device_identifier != nil { - fields = append(fields, magicflow.FieldDeviceIdentifier) - } - return fields -} - -// 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 *MagicFlowMutation) Field(name string) (ent.Value, bool) { - switch name { - case magicflow.FieldCreatedAt: - return m.CreatedAt() - case magicflow.FieldIdentifier: - return m.Identifier() - case magicflow.FieldEmail: - return m.Email() - case magicflow.FieldIPAddress: - return m.IPAddress() - case magicflow.FieldSecret: - return m.Secret() - case magicflow.FieldNextURL: - return m.NextURL() - case magicflow.FieldOrganization: - return m.Organization() - case magicflow.FieldDeviceIdentifier: - return m.DeviceIdentifier() - } - 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 failed. -func (m *MagicFlowMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case magicflow.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case magicflow.FieldIdentifier: - return m.OldIdentifier(ctx) - case magicflow.FieldEmail: - return m.OldEmail(ctx) - case magicflow.FieldIPAddress: - return m.OldIPAddress(ctx) - case magicflow.FieldSecret: - return m.OldSecret(ctx) - case magicflow.FieldNextURL: - return m.OldNextURL(ctx) - case magicflow.FieldOrganization: - return m.OldOrganization(ctx) - case magicflow.FieldDeviceIdentifier: - return m.OldDeviceIdentifier(ctx) - } - return nil, fmt.Errorf("unknown MagicFlow field %s", name) -} - -// 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 *MagicFlowMutation) SetField(name string, value ent.Value) error { - switch name { - case magicflow.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case magicflow.FieldIdentifier: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetIdentifier(v) - return nil - case magicflow.FieldEmail: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetEmail(v) - return nil - case magicflow.FieldIPAddress: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetIPAddress(v) - return nil - case magicflow.FieldSecret: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetSecret(v) - return nil - case magicflow.FieldNextURL: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetNextURL(v) - return nil - case magicflow.FieldOrganization: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetOrganization(v) - return nil - case magicflow.FieldDeviceIdentifier: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDeviceIdentifier(v) - return nil - } - return fmt.Errorf("unknown MagicFlow field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *MagicFlowMutation) AddedFields() []string { - return nil -} - -// 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 *MagicFlowMutation) AddedField(name string) (ent.Value, bool) { - return nil, false -} - -// 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 *MagicFlowMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown MagicFlow numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *MagicFlowMutation) ClearedFields() []string { - var fields []string - if m.FieldCleared(magicflow.FieldOrganization) { - fields = append(fields, magicflow.FieldOrganization) - } - if m.FieldCleared(magicflow.FieldDeviceIdentifier) { - fields = append(fields, magicflow.FieldDeviceIdentifier) - } - return fields -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *MagicFlowMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// 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 *MagicFlowMutation) ClearField(name string) error { - switch name { - case magicflow.FieldOrganization: - m.ClearOrganization() - return nil - case magicflow.FieldDeviceIdentifier: - m.ClearDeviceIdentifier() - return nil - } - return fmt.Errorf("unknown MagicFlow nullable field %s", name) -} - -// 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 *MagicFlowMutation) ResetField(name string) error { - switch name { - case magicflow.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case magicflow.FieldIdentifier: - m.ResetIdentifier() - return nil - case magicflow.FieldEmail: - m.ResetEmail() - return nil - case magicflow.FieldIPAddress: - m.ResetIPAddress() - return nil - case magicflow.FieldSecret: - m.ResetSecret() - return nil - case magicflow.FieldNextURL: - m.ResetNextURL() - return nil - case magicflow.FieldOrganization: - m.ResetOrganization() - return nil - case magicflow.FieldDeviceIdentifier: - m.ResetDeviceIdentifier() - return nil - } - return fmt.Errorf("unknown MagicFlow field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *MagicFlowMutation) AddedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *MagicFlowMutation) AddedIDs(name string) []ent.Value { - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *MagicFlowMutation) RemovedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *MagicFlowMutation) RemovedIDs(name string) []ent.Value { - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *MagicFlowMutation) ClearedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *MagicFlowMutation) EdgeCleared(name string) bool { - return false -} - -// 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 *MagicFlowMutation) ClearEdge(name string) error { - return fmt.Errorf("unknown MagicFlow unique edge %s", name) -} - -// 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 *MagicFlowMutation) ResetEdge(name string) error { - return fmt.Errorf("unknown MagicFlow edge %s", name) -} diff --git a/internal/ent/predicate/predicate.go b/internal/ent/predicate/predicate.go deleted file mode 100644 index 40a26d3..0000000 --- a/internal/ent/predicate/predicate.go +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package predicate - -import ( - "entgo.io/ent/dialect/sql" -) - -// DeviceFlow is the predicate function for deviceflow builders. -type DeviceFlow func(*sql.Selector) - -// GithubFlow is the predicate function for githubflow builders. -type GithubFlow func(*sql.Selector) - -// GoogleFlow is the predicate function for googleflow builders. -type GoogleFlow func(*sql.Selector) - -// MagicFlow is the predicate function for magicflow builders. -type MagicFlow func(*sql.Selector) diff --git a/internal/ent/runtime.go b/internal/ent/runtime.go deleted file mode 100644 index 760fd97..0000000 --- a/internal/ent/runtime.go +++ /dev/null @@ -1,127 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "time" - - "github.com/loopholelabs/auth/internal/ent/deviceflow" - "github.com/loopholelabs/auth/internal/ent/githubflow" - "github.com/loopholelabs/auth/internal/ent/googleflow" - "github.com/loopholelabs/auth/internal/ent/magicflow" - "github.com/loopholelabs/auth/internal/ent/schema" -) - -// 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() { - deviceflowFields := schema.DeviceFlow{}.Fields() - _ = deviceflowFields - // deviceflowDescCreatedAt is the schema descriptor for created_at field. - deviceflowDescCreatedAt := deviceflowFields[0].Descriptor() - // deviceflow.DefaultCreatedAt holds the default value on creation for the created_at field. - deviceflow.DefaultCreatedAt = deviceflowDescCreatedAt.Default.(func() time.Time) - // deviceflowDescIdentifier is the schema descriptor for identifier field. - deviceflowDescIdentifier := deviceflowFields[1].Descriptor() - // deviceflow.IdentifierValidator is a validator for the "identifier" field. It is called by the builders before save. - deviceflow.IdentifierValidator = deviceflowDescIdentifier.Validators[0].(func(string) error) - // deviceflowDescDeviceCode is the schema descriptor for device_code field. - deviceflowDescDeviceCode := deviceflowFields[2].Descriptor() - // deviceflow.DeviceCodeValidator is a validator for the "device_code" field. It is called by the builders before save. - deviceflow.DeviceCodeValidator = deviceflowDescDeviceCode.Validators[0].(func(string) error) - // deviceflowDescUserCode is the schema descriptor for user_code field. - deviceflowDescUserCode := deviceflowFields[3].Descriptor() - // deviceflow.UserCodeValidator is a validator for the "user_code" field. It is called by the builders before save. - deviceflow.UserCodeValidator = deviceflowDescUserCode.Validators[0].(func(string) error) - // deviceflowDescLastPoll is the schema descriptor for last_poll field. - deviceflowDescLastPoll := deviceflowFields[5].Descriptor() - // deviceflow.DefaultLastPoll holds the default value on creation for the last_poll field. - deviceflow.DefaultLastPoll = deviceflowDescLastPoll.Default.(func() time.Time) - githubflowFields := schema.GithubFlow{}.Fields() - _ = githubflowFields - // githubflowDescCreatedAt is the schema descriptor for created_at field. - githubflowDescCreatedAt := githubflowFields[0].Descriptor() - // githubflow.DefaultCreatedAt holds the default value on creation for the created_at field. - githubflow.DefaultCreatedAt = githubflowDescCreatedAt.Default.(func() time.Time) - // githubflowDescIdentifier is the schema descriptor for identifier field. - githubflowDescIdentifier := githubflowFields[1].Descriptor() - // githubflow.IdentifierValidator is a validator for the "identifier" field. It is called by the builders before save. - githubflow.IdentifierValidator = githubflowDescIdentifier.Validators[0].(func(string) error) - // githubflowDescVerifier is the schema descriptor for verifier field. - githubflowDescVerifier := githubflowFields[2].Descriptor() - // githubflow.VerifierValidator is a validator for the "verifier" field. It is called by the builders before save. - githubflow.VerifierValidator = githubflowDescVerifier.Validators[0].(func(string) error) - // githubflowDescChallenge is the schema descriptor for challenge field. - githubflowDescChallenge := githubflowFields[3].Descriptor() - // githubflow.ChallengeValidator is a validator for the "challenge" field. It is called by the builders before save. - githubflow.ChallengeValidator = githubflowDescChallenge.Validators[0].(func(string) error) - // githubflowDescNextURL is the schema descriptor for next_url field. - githubflowDescNextURL := githubflowFields[4].Descriptor() - // githubflow.NextURLValidator is a validator for the "next_url" field. It is called by the builders before save. - githubflow.NextURLValidator = githubflowDescNextURL.Validators[0].(func(string) error) - googleflowFields := schema.GoogleFlow{}.Fields() - _ = googleflowFields - // googleflowDescCreatedAt is the schema descriptor for created_at field. - googleflowDescCreatedAt := googleflowFields[0].Descriptor() - // googleflow.DefaultCreatedAt holds the default value on creation for the created_at field. - googleflow.DefaultCreatedAt = googleflowDescCreatedAt.Default.(func() time.Time) - // googleflowDescIdentifier is the schema descriptor for identifier field. - googleflowDescIdentifier := googleflowFields[1].Descriptor() - // googleflow.IdentifierValidator is a validator for the "identifier" field. It is called by the builders before save. - googleflow.IdentifierValidator = googleflowDescIdentifier.Validators[0].(func(string) error) - // googleflowDescVerifier is the schema descriptor for verifier field. - googleflowDescVerifier := googleflowFields[2].Descriptor() - // googleflow.VerifierValidator is a validator for the "verifier" field. It is called by the builders before save. - googleflow.VerifierValidator = googleflowDescVerifier.Validators[0].(func(string) error) - // googleflowDescChallenge is the schema descriptor for challenge field. - googleflowDescChallenge := googleflowFields[3].Descriptor() - // googleflow.ChallengeValidator is a validator for the "challenge" field. It is called by the builders before save. - googleflow.ChallengeValidator = googleflowDescChallenge.Validators[0].(func(string) error) - // googleflowDescNextURL is the schema descriptor for next_url field. - googleflowDescNextURL := googleflowFields[4].Descriptor() - // googleflow.NextURLValidator is a validator for the "next_url" field. It is called by the builders before save. - googleflow.NextURLValidator = googleflowDescNextURL.Validators[0].(func(string) error) - magicflowFields := schema.MagicFlow{}.Fields() - _ = magicflowFields - // magicflowDescCreatedAt is the schema descriptor for created_at field. - magicflowDescCreatedAt := magicflowFields[0].Descriptor() - // magicflow.DefaultCreatedAt holds the default value on creation for the created_at field. - magicflow.DefaultCreatedAt = magicflowDescCreatedAt.Default.(func() time.Time) - // magicflowDescIdentifier is the schema descriptor for identifier field. - magicflowDescIdentifier := magicflowFields[1].Descriptor() - // magicflow.IdentifierValidator is a validator for the "identifier" field. It is called by the builders before save. - magicflow.IdentifierValidator = magicflowDescIdentifier.Validators[0].(func(string) error) - // magicflowDescEmail is the schema descriptor for email field. - magicflowDescEmail := magicflowFields[2].Descriptor() - // magicflow.EmailValidator is a validator for the "email" field. It is called by the builders before save. - magicflow.EmailValidator = magicflowDescEmail.Validators[0].(func(string) error) - // magicflowDescIPAddress is the schema descriptor for ip_address field. - magicflowDescIPAddress := magicflowFields[3].Descriptor() - // magicflow.IPAddressValidator is a validator for the "ip_address" field. It is called by the builders before save. - magicflow.IPAddressValidator = magicflowDescIPAddress.Validators[0].(func(string) error) - // magicflowDescSecret is the schema descriptor for secret field. - magicflowDescSecret := magicflowFields[4].Descriptor() - // magicflow.SecretValidator is a validator for the "secret" field. It is called by the builders before save. - magicflow.SecretValidator = magicflowDescSecret.Validators[0].(func(string) error) - // magicflowDescNextURL is the schema descriptor for next_url field. - magicflowDescNextURL := magicflowFields[5].Descriptor() - // magicflow.NextURLValidator is a validator for the "next_url" field. It is called by the builders before save. - magicflow.NextURLValidator = magicflowDescNextURL.Validators[0].(func(string) error) -} diff --git a/internal/ent/runtime/runtime.go b/internal/ent/runtime/runtime.go deleted file mode 100644 index b1e569f..0000000 --- a/internal/ent/runtime/runtime.go +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package runtime - -// The schema-stitching logic is generated in github.com/loopholelabs/auth/internal/ent/runtime.go - -const ( - Version = "v0.12.3" // Version of ent codegen. - Sum = "h1:N5lO2EOrHpCH5HYfiMOCHYbo+oh5M8GjT0/cx5x6xkk=" // Sum of ent codegen. -) diff --git a/internal/ent/schema/deviceFlow.go b/internal/ent/schema/deviceFlow.go deleted file mode 100644 index 096bc3f..0000000 --- a/internal/ent/schema/deviceFlow.go +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package schema - -import ( - "entgo.io/ent" - "entgo.io/ent/schema/field" - "time" -) - -// DeviceFlow holds the schema definition for the Device Flow entity. -type DeviceFlow struct { - ent.Schema -} - -// Fields of the DeviceFlow. -func (DeviceFlow) Fields() []ent.Field { - return []ent.Field{ - field.Time("created_at").Immutable().Default(time.Now), - field.String("identifier").Unique().Immutable().NotEmpty(), - field.String("device_code").Unique().Immutable().NotEmpty(), - field.String("user_code").Unique().Immutable().NotEmpty(), - field.String("session").Unique().Optional(), - field.Time("last_poll").Default(time.Now), - field.Time("expires_at").Optional(), - } -} - -// Edges of the DeviceFlow. -func (DeviceFlow) Edges() []ent.Edge { - return nil -} diff --git a/internal/ent/schema/githubFlow.go b/internal/ent/schema/githubFlow.go deleted file mode 100644 index 0a7ac9c..0000000 --- a/internal/ent/schema/githubFlow.go +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package schema - -import ( - "entgo.io/ent" - "entgo.io/ent/schema/field" - "time" -) - -// GithubFlow holds the schema definition for the Flow entity. -type GithubFlow struct { - ent.Schema -} - -// Fields of the GithubFlow. -func (GithubFlow) Fields() []ent.Field { - return []ent.Field{ - field.Time("created_at").Immutable().Default(time.Now), - field.String("identifier").Unique().Immutable().NotEmpty(), - field.String("verifier").Unique().Immutable().NotEmpty(), - field.String("challenge").Unique().Immutable().NotEmpty(), - field.String("next_url").Immutable().NotEmpty(), - field.String("organization").Immutable().Optional(), - field.String("device_identifier").Immutable().Optional(), - } -} - -// Edges of the GithubFlow. -func (GithubFlow) Edges() []ent.Edge { - return nil -} diff --git a/internal/ent/schema/googleFlow.go b/internal/ent/schema/googleFlow.go deleted file mode 100644 index b8b1434..0000000 --- a/internal/ent/schema/googleFlow.go +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package schema - -import ( - "entgo.io/ent" - "entgo.io/ent/schema/field" - "time" -) - -// GoogleFlow holds the schema definition for the Flow entity. -type GoogleFlow struct { - ent.Schema -} - -// Fields of the GoogleFlow. -func (GoogleFlow) Fields() []ent.Field { - return []ent.Field{ - field.Time("created_at").Immutable().Default(time.Now), - field.String("identifier").Unique().Immutable().NotEmpty(), - field.String("verifier").Unique().Immutable().NotEmpty(), - field.String("challenge").Unique().Immutable().NotEmpty(), - field.String("next_url").Immutable().NotEmpty(), - field.String("organization").Immutable().Optional(), - field.String("device_identifier").Immutable().Optional(), - } -} - -// Edges of the GoogleFlow. -func (GoogleFlow) Edges() []ent.Edge { - return nil -} diff --git a/internal/ent/schema/magicFlow.go b/internal/ent/schema/magicFlow.go deleted file mode 100644 index 6a5f3ed..0000000 --- a/internal/ent/schema/magicFlow.go +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package schema - -import ( - "entgo.io/ent" - "entgo.io/ent/schema/field" - "time" -) - -// MagicFlow holds the schema definition for the Flow entity. -type MagicFlow struct { - ent.Schema -} - -// Fields of the MagicFlow. -func (MagicFlow) Fields() []ent.Field { - return []ent.Field{ - field.Time("created_at").Immutable().Default(time.Now), - field.String("identifier").Unique().Immutable().NotEmpty(), - field.String("email").Unique().Immutable().NotEmpty(), - field.String("ip_address").Immutable().NotEmpty(), - field.String("secret").Immutable().NotEmpty(), - field.String("next_url").Immutable().NotEmpty(), - field.String("organization").Immutable().Optional(), - field.String("device_identifier").Immutable().Optional(), - } -} - -// Edges of the MagicFlow. -func (MagicFlow) Edges() []ent.Edge { - return nil -} diff --git a/internal/ent/tx.go b/internal/ent/tx.go deleted file mode 100644 index 8697665..0000000 --- a/internal/ent/tx.go +++ /dev/null @@ -1,235 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "sync" - - "entgo.io/ent/dialect" -) - -// Tx is a transactional client that is created by calling Client.Tx(). -type Tx struct { - config - // DeviceFlow is the client for interacting with the DeviceFlow builders. - DeviceFlow *DeviceFlowClient - // GithubFlow is the client for interacting with the GithubFlow builders. - GithubFlow *GithubFlowClient - // GoogleFlow is the client for interacting with the GoogleFlow builders. - GoogleFlow *GoogleFlowClient - // MagicFlow is the client for interacting with the MagicFlow builders. - MagicFlow *MagicFlowClient - - // lazily loaded. - client *Client - clientOnce sync.Once - // ctx lives for the life of the transaction. It is - // the same context used by the underlying connection. - ctx context.Context -} - -type ( - // Committer is the interface that wraps the Commit method. - Committer interface { - Commit(context.Context, *Tx) error - } - - // The CommitFunc type is an adapter to allow the use of ordinary - // function as a Committer. If f is a function with the appropriate - // signature, CommitFunc(f) is a Committer that calls f. - CommitFunc func(context.Context, *Tx) error - - // CommitHook defines the "commit middleware". A function that gets a Committer - // and returns a Committer. For example: - // - // hook := func(next ent.Committer) ent.Committer { - // return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error { - // // Do some stuff before. - // if err := next.Commit(ctx, tx); err != nil { - // return err - // } - // // Do some stuff after. - // return nil - // }) - // } - // - CommitHook func(Committer) Committer -) - -// Commit calls f(ctx, m). -func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error { - return f(ctx, tx) -} - -// Commit commits the transaction. -func (tx *Tx) Commit() error { - txDriver := tx.config.driver.(*txDriver) - var fn Committer = CommitFunc(func(context.Context, *Tx) error { - return txDriver.tx.Commit() - }) - txDriver.mu.Lock() - hooks := append([]CommitHook(nil), txDriver.onCommit...) - txDriver.mu.Unlock() - for i := len(hooks) - 1; i >= 0; i-- { - fn = hooks[i](fn) - } - return fn.Commit(tx.ctx, tx) -} - -// OnCommit adds a hook to call on commit. -func (tx *Tx) OnCommit(f CommitHook) { - txDriver := tx.config.driver.(*txDriver) - txDriver.mu.Lock() - txDriver.onCommit = append(txDriver.onCommit, f) - txDriver.mu.Unlock() -} - -type ( - // Rollbacker is the interface that wraps the Rollback method. - Rollbacker interface { - Rollback(context.Context, *Tx) error - } - - // The RollbackFunc type is an adapter to allow the use of ordinary - // function as a Rollbacker. If f is a function with the appropriate - // signature, RollbackFunc(f) is a Rollbacker that calls f. - RollbackFunc func(context.Context, *Tx) error - - // RollbackHook defines the "rollback middleware". A function that gets a Rollbacker - // and returns a Rollbacker. For example: - // - // hook := func(next ent.Rollbacker) ent.Rollbacker { - // return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error { - // // Do some stuff before. - // if err := next.Rollback(ctx, tx); err != nil { - // return err - // } - // // Do some stuff after. - // return nil - // }) - // } - // - RollbackHook func(Rollbacker) Rollbacker -) - -// Rollback calls f(ctx, m). -func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error { - return f(ctx, tx) -} - -// Rollback rollbacks the transaction. -func (tx *Tx) Rollback() error { - txDriver := tx.config.driver.(*txDriver) - var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error { - return txDriver.tx.Rollback() - }) - txDriver.mu.Lock() - hooks := append([]RollbackHook(nil), txDriver.onRollback...) - txDriver.mu.Unlock() - for i := len(hooks) - 1; i >= 0; i-- { - fn = hooks[i](fn) - } - return fn.Rollback(tx.ctx, tx) -} - -// OnRollback adds a hook to call on rollback. -func (tx *Tx) OnRollback(f RollbackHook) { - txDriver := tx.config.driver.(*txDriver) - txDriver.mu.Lock() - txDriver.onRollback = append(txDriver.onRollback, f) - txDriver.mu.Unlock() -} - -// Client returns a Client that binds to current transaction. -func (tx *Tx) Client() *Client { - tx.clientOnce.Do(func() { - tx.client = &Client{config: tx.config} - tx.client.init() - }) - return tx.client -} - -func (tx *Tx) init() { - tx.DeviceFlow = NewDeviceFlowClient(tx.config) - tx.GithubFlow = NewGithubFlowClient(tx.config) - tx.GoogleFlow = NewGoogleFlowClient(tx.config) - tx.MagicFlow = NewMagicFlowClient(tx.config) -} - -// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. -// The idea is to support transactions without adding any extra code to the builders. -// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance. -// Commit and Rollback are nop for the internal builders and the user must call one -// of them in order to commit or rollback the transaction. -// -// If a closed transaction is embedded in one of the generated entities, and the entity -// applies a query, for example: DeviceFlow.QueryXXX(), the query will be executed -// through the driver which created this transaction. -// -// Note that txDriver is not goroutine safe. -type txDriver struct { - // the driver we started the transaction from. - drv dialect.Driver - // tx is the underlying transaction. - tx dialect.Tx - // completion hooks. - mu sync.Mutex - onCommit []CommitHook - onRollback []RollbackHook -} - -// newTx creates a new transactional driver. -func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { - tx, err := drv.Tx(ctx) - if err != nil { - return nil, err - } - return &txDriver{tx: tx, drv: drv}, nil -} - -// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls -// from the internal builders. Should be called only by the internal builders. -func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } - -// Dialect returns the dialect of the driver we started the transaction from. -func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } - -// Close is a nop close. -func (*txDriver) Close() error { return nil } - -// Commit is a nop commit for the internal builders. -// User must call `Tx.Commit` in order to commit the transaction. -func (*txDriver) Commit() error { return nil } - -// Rollback is a nop rollback for the internal builders. -// User must call `Tx.Rollback` in order to rollback the transaction. -func (*txDriver) Rollback() error { return nil } - -// Exec calls tx.Exec. -func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error { - return tx.tx.Exec(ctx, query, args, v) -} - -// Query calls tx.Query. -func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error { - return tx.tx.Query(ctx, query, args, v) -} - -var _ dialect.Driver = (*txDriver)(nil) diff --git a/internal/provider/device/database.go b/internal/provider/device/database.go deleted file mode 100644 index 15b958c..0000000 --- a/internal/provider/device/database.go +++ /dev/null @@ -1,33 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package device - -import ( - "context" - "github.com/loopholelabs/auth/internal/ent" - "time" -) - -type Database interface { - SetDeviceFlow(ctx context.Context, identifier string, deviceCode string, userCode string) error - GetDeviceFlow(ctx context.Context, deviceCode string) (*ent.DeviceFlow, error) - UpdateDeviceFlow(ctx context.Context, identifier string, session string, expiry time.Time) error - GetDeviceFlowUserCode(ctx context.Context, userCode string) (*ent.DeviceFlow, error) - GetDeviceFlowIdentifier(ctx context.Context, identifier string) (*ent.DeviceFlow, error) - DeleteDeviceFlow(ctx context.Context, deviceCode string) error - GCDeviceFlow(ctx context.Context, expiry time.Duration) (int, error) -} diff --git a/internal/provider/github/database.go b/internal/provider/github/database.go deleted file mode 100644 index a22f189..0000000 --- a/internal/provider/github/database.go +++ /dev/null @@ -1,30 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package github - -import ( - "context" - "github.com/loopholelabs/auth/internal/ent" - "time" -) - -type Database interface { - SetGithubFlow(ctx context.Context, state string, verifier string, challenge string, nextURL string, organization string, deviceIdentifier string) error - GetGithubFlow(ctx context.Context, state string) (*ent.GithubFlow, error) - DeleteGithubFlow(ctx context.Context, state string) error - GCGithubFlow(ctx context.Context, expiry time.Duration) (int, error) -} diff --git a/internal/provider/google/database.go b/internal/provider/google/database.go deleted file mode 100644 index 304760f..0000000 --- a/internal/provider/google/database.go +++ /dev/null @@ -1,30 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package google - -import ( - "context" - "github.com/loopholelabs/auth/internal/ent" - "time" -) - -type Database interface { - SetGoogleFlow(ctx context.Context, state string, verifier string, challenge string, nextURL string, organization string, deviceIdentifier string) error - GetGoogleFlow(ctx context.Context, state string) (*ent.GoogleFlow, error) - DeleteGoogleFlow(ctx context.Context, state string) error - GCGoogleFlow(ctx context.Context, expiry time.Duration) (int, error) -} diff --git a/pkg/config/config.go b/pkg/config/config.go index d7c3576..0aae3f2 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -27,7 +27,6 @@ import ( var ( ErrListenAddressRequired = errors.New("listen address is required") ErrEndpointRequired = errors.New("endpoint is required") - ErrDatabaseURLRequired = errors.New("database url is required") ErrSessionDomainRequired = errors.New("session domain is required") ErrDefaultNextURLRequired = errors.New("default next url is required") ) @@ -44,7 +43,6 @@ type Config struct { Endpoint string `yaml:"endpoint"` SessionDomain string `yaml:"session_domain"` DefaultNextURL string `yaml:"default_next_url"` - DatabaseURL string `yaml:"database_url"` GithubClientID string `yaml:"github_client_id"` GithubClientSecret string `yaml:"github_client_secret"` @@ -73,9 +71,6 @@ func (c *Config) Validate() error { if c.Endpoint == "" { return ErrEndpointRequired } - if c.DatabaseURL == "" { - return ErrDatabaseURLRequired - } if c.SessionDomain == "" { return ErrSessionDomainRequired } @@ -91,7 +86,6 @@ func (c *Config) RootPersistentFlags(flags *pflag.FlagSet) { flags.StringVar(&c.SessionDomain, "auth-session-domain", DefaultSessionDomain, "The auth api's session domain") flags.StringVar(&c.DefaultNextURL, "auth-default-next-url", DefaultNextURL, "The auth api's default next url") - flags.StringVar(&c.DatabaseURL, "auth-database-url", "", "The auth api's database url") flags.StringVar(&c.GithubClientID, "auth-github-client-id", "", "The auth api's github client id") flags.StringVar(&c.GithubClientSecret, "auth-github-client-secret", "", "The auth api's github client secret") flags.StringVar(&c.GoogleClientID, "auth-google-client-id", "", "The auth api's google client id") @@ -117,7 +111,6 @@ func (c *Config) GenerateOptions(storage storage.Storage, tls bool, projectName TLS: tls, SessionDomain: c.SessionDomain, DefaultNextURL: c.DefaultNextURL, - DatabaseURL: c.DatabaseURL, Storage: storage, GithubClientID: c.GithubClientID, GithubClientSecret: c.GithubClientSecret, diff --git a/internal/provider/device/device.go b/pkg/flow/device/device.go similarity index 52% rename from internal/provider/device/device.go rename to pkg/flow/device/device.go index 93fc456..de2335a 100644 --- a/internal/provider/device/device.go +++ b/pkg/flow/device/device.go @@ -1,62 +1,63 @@ /* - Copyright 2023 Loophole Labs + Copyright 2023 Loophole Labs - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ package device import ( "context" + "errors" "github.com/google/uuid" - "github.com/loopholelabs/auth/internal/ent" "github.com/loopholelabs/auth/internal/utils" - "github.com/loopholelabs/auth/pkg/provider" + "github.com/loopholelabs/auth/pkg/flow" + "github.com/loopholelabs/auth/pkg/storage" "github.com/rs/zerolog" "strings" "sync" "time" ) -var _ provider.Provider = (*Device)(nil) +var _ flow.Flow = (*Device)(nil) const ( - Key provider.Key = "device" - GCInterval = time.Minute - Expiry = time.Minute * 5 + Key flow.Key = "device" + GCInterval = time.Minute + Expiry = time.Minute * 5 ) type Device struct { - logger *zerolog.Logger - database Database - wg sync.WaitGroup - ctx context.Context - cancel context.CancelFunc + logger *zerolog.Logger + storage storage.Device + wg sync.WaitGroup + ctx context.Context + cancel context.CancelFunc } -func New(database Database, logger *zerolog.Logger) *Device { +func New(storage storage.Device, logger *zerolog.Logger) *Device { l := logger.With().Str("AUTH", "DEVICE-FLOW").Logger() ctx, cancel := context.WithCancel(context.Background()) return &Device{ - logger: &l, - database: database, - ctx: ctx, - cancel: cancel, + logger: &l, + storage: storage, + ctx: ctx, + cancel: cancel, } } -func (g *Device) Key() provider.Key { +func (g *Device) Key() flow.Key { return Key } @@ -77,7 +78,7 @@ func (g *Device) StartFlow(ctx context.Context) (string, string, error) { userCode := uuid.New().String() identifier := uuid.New().String() - err := g.database.SetDeviceFlow(ctx, identifier, deviceCode, userCode) + err := g.storage.SetDeviceFlow(ctx, identifier, deviceCode, userCode) if err != nil { return "", "", err } @@ -86,18 +87,18 @@ func (g *Device) StartFlow(ctx context.Context) (string, string, error) { } func (g *Device) ValidateFlow(ctx context.Context, deviceCode string) (string, error) { - flow, err := g.database.GetDeviceFlow(ctx, deviceCode) + f, err := g.storage.GetDeviceFlow(ctx, deviceCode) if err != nil { return "", err } - return flow.Identifier, nil + return f.Identifier, nil } func (g *Device) FlowExists(ctx context.Context, identifier string) (bool, error) { - _, err := g.database.GetDeviceFlowIdentifier(ctx, identifier) + _, err := g.storage.GetDeviceFlowIdentifier(ctx, identifier) if err != nil { - if ent.IsNotFound(err) { + if errors.Is(err, storage.ErrNotFound) { return false, nil } return false, err @@ -107,23 +108,23 @@ func (g *Device) FlowExists(ctx context.Context, identifier string) (bool, error } func (g *Device) PollFlow(ctx context.Context, userCode string) (string, time.Time, time.Time, error) { - flow, err := g.database.GetDeviceFlowUserCode(ctx, userCode) + f, err := g.storage.GetDeviceFlowUserCode(ctx, userCode) if err != nil { return "", time.Time{}, time.Time{}, err } - if flow.Session != "" { - err = g.database.DeleteDeviceFlow(ctx, flow.DeviceCode) + if f.Session != "" { + err = g.storage.DeleteDeviceFlow(ctx, f.DeviceCode) if err != nil { return "", time.Time{}, time.Time{}, err } } - return flow.Session, flow.ExpiresAt, flow.LastPoll, nil + return f.Session, f.ExpiresAt, f.LastPoll, nil } func (g *Device) CompleteFlow(ctx context.Context, identifier string, session string, expiry time.Time) error { - err := g.database.UpdateDeviceFlow(ctx, identifier, session, expiry) + err := g.storage.UpdateDeviceFlow(ctx, identifier, session, expiry) if err != nil { return err } @@ -139,7 +140,7 @@ func (g *Device) gc() { g.logger.Info().Msg("GC Stopped") return case <-time.After(GCInterval): - deleted, err := g.database.GCDeviceFlow(g.ctx, Expiry) + deleted, err := g.storage.GCDeviceFlow(g.ctx, Expiry) if err != nil { g.logger.Error().Err(err).Msg("failed to garbage collect expired device flows") } else { diff --git a/internal/provider/magic/database.go b/pkg/flow/flow.go similarity index 53% rename from internal/provider/magic/database.go rename to pkg/flow/flow.go index 1cce025..fee64bb 100644 --- a/internal/provider/magic/database.go +++ b/pkg/flow/flow.go @@ -14,17 +14,28 @@ limitations under the License. */ -package magic +package flow -import ( - "context" - "github.com/loopholelabs/auth/internal/ent" - "time" +import "errors" + +var ( + ErrInvalidOptions = errors.New("invalid options") ) -type Database interface { - SetMagicFlow(ctx context.Context, email string, ip string, secret string, nextURL string, organization string, deviceIdentifier string) error - GetMagicFlow(ctx context.Context, email string) (*ent.MagicFlow, error) - DeleteMagicFlow(ctx context.Context, email string) error - GCMagicFlow(ctx context.Context, expiry time.Duration) (int, error) +// Key uniquely identifies authentication providers +// +// Each provider must create its own globally unique key +type Key string + +// Flow is an authentication flow provider that authorizes +// a user and returns a set of claims +type Flow interface { + // Key returns the authentication provider's unique key + Key() Key + + // Start starts the Provider + Start() error + + // Stop stops the Provider + Stop() error } diff --git a/internal/provider/github/github.go b/pkg/flow/github/github.go similarity index 62% rename from internal/provider/github/github.go rename to pkg/flow/github/github.go index 22e7e28..640ab48 100644 --- a/internal/provider/github/github.go +++ b/pkg/flow/github/github.go @@ -1,17 +1,17 @@ /* - Copyright 2023 Loophole Labs + Copyright 2023 Loophole Labs - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ package github @@ -22,7 +22,8 @@ import ( "errors" "github.com/google/uuid" "github.com/grokify/go-pkce" - "github.com/loopholelabs/auth/pkg/provider" + "github.com/loopholelabs/auth/pkg/flow" + "github.com/loopholelabs/auth/pkg/storage" "github.com/rs/zerolog" "golang.org/x/oauth2" "golang.org/x/oauth2/github" @@ -32,16 +33,16 @@ import ( "time" ) -var _ provider.Provider = (*Github)(nil) +var _ flow.Flow = (*Github)(nil) var ( ErrInvalidResponse = errors.New("invalid response") ) const ( - Key provider.Key = "github" - GCInterval = time.Minute - Expiry = time.Minute * 5 + Key flow.Key = "github" + GCInterval = time.Minute + Expiry = time.Minute * 5 ) var ( @@ -55,39 +56,64 @@ type email struct { Visibility string `json:"visibility"` } +type Options struct { + ClientID string + ClientSecret string + Redirect string +} + type Github struct { - logger *zerolog.Logger - conf *oauth2.Config - database Database - wg sync.WaitGroup - ctx context.Context - cancel context.CancelFunc + logger *zerolog.Logger + storage storage.Github + options *Options + conf *oauth2.Config + wg sync.WaitGroup + ctx context.Context + cancel context.CancelFunc } -func New(clientID string, clientSecret string, redirect string, database Database, logger *zerolog.Logger) *Github { +func New(storage storage.Github, options *Options, logger *zerolog.Logger) *Github { l := logger.With().Str("AUTH", "GITHUB-OAUTH-PROVIDER").Logger() ctx, cancel := context.WithCancel(context.Background()) return &Github{ - logger: &l, - conf: &oauth2.Config{ - RedirectURL: redirect, - ClientID: clientID, - ClientSecret: clientSecret, - Scopes: defaultScopes, - Endpoint: github.Endpoint, - }, - database: database, - ctx: ctx, - cancel: cancel, + logger: &l, + storage: storage, + options: options, + ctx: ctx, + cancel: cancel, } } -func (g *Github) Key() provider.Key { +func (g *Github) Key() flow.Key { return Key } func (g *Github) Start() error { + if g.options == nil { + return flow.ErrInvalidOptions + } + + if g.options.ClientID == "" { + return flow.ErrInvalidOptions + } + + if g.options.ClientSecret == "" { + return flow.ErrInvalidOptions + } + + if g.options.Redirect == "" { + return flow.ErrInvalidOptions + } + + g.conf = &oauth2.Config{ + RedirectURL: g.options.Redirect, + ClientID: g.options.ClientID, + ClientSecret: g.options.ClientSecret, + Scopes: defaultScopes, + Endpoint: github.Endpoint, + } + g.wg.Add(1) go g.gc() return nil @@ -108,7 +134,7 @@ func (g *Github) StartFlow(ctx context.Context, nextURL string, organization str state := uuid.New().String() g.logger.Debug().Msgf("starting flow for state %s with org '%s' and device identifier '%s'", state, organization, deviceIdentifier) - err = g.database.SetGithubFlow(ctx, state, verifier, challenge, nextURL, organization, deviceIdentifier) + err = g.storage.SetGithubFlow(ctx, state, verifier, challenge, nextURL, organization, deviceIdentifier) if err != nil { return "", err } @@ -118,19 +144,19 @@ func (g *Github) StartFlow(ctx context.Context, nextURL string, organization str func (g *Github) CompleteFlow(ctx context.Context, code string, state string) (string, string, string, string, error) { g.logger.Debug().Msgf("completing flow for state %s", state) - flow, err := g.database.GetGithubFlow(ctx, state) + f, err := g.storage.GetGithubFlow(ctx, state) if err != nil { return "", "", "", "", err } g.logger.Debug().Msgf("found flow for state %s, deleting", state) - err = g.database.DeleteGithubFlow(ctx, state) + err = g.storage.DeleteGithubFlow(ctx, state) if err != nil { return "", "", "", "", err } g.logger.Debug().Msgf("exchanging code for token for state %s", state) - token, err := g.conf.Exchange(ctx, code, oauth2.SetAuthURLParam(pkce.ParamCodeVerifier, flow.Verifier)) + token, err := g.conf.Exchange(ctx, code, oauth2.SetAuthURLParam(pkce.ParamCodeVerifier, f.Verifier)) if err != nil { return "", "", "", "", err } @@ -170,7 +196,7 @@ func (g *Github) CompleteFlow(ctx context.Context, code string, state string) (s for _, e := range emails { if e.Primary && e.Verified { g.logger.Debug().Msgf("found primary and verified email %s for state %s", e.Email, state) - return e.Email, flow.Organization, flow.NextURL, flow.DeviceIdentifier, nil + return e.Email, f.Organization, f.NextURL, f.DeviceIdentifier, nil } } @@ -186,7 +212,7 @@ func (g *Github) gc() { g.logger.Info().Msg("GC Stopped") return case <-time.After(GCInterval): - deleted, err := g.database.GCGithubFlow(g.ctx, Expiry) + deleted, err := g.storage.GCGithubFlow(g.ctx, Expiry) if err != nil { g.logger.Error().Err(err).Msg("failed to garbage collect expired github flows") } else { diff --git a/internal/provider/google/google.go b/pkg/flow/google/google.go similarity index 59% rename from internal/provider/google/google.go rename to pkg/flow/google/google.go index 35e57c1..159df32 100644 --- a/internal/provider/google/google.go +++ b/pkg/flow/google/google.go @@ -1,17 +1,17 @@ /* - Copyright 2023 Loophole Labs + Copyright 2023 Loophole Labs - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ package google @@ -22,7 +22,8 @@ import ( "errors" "github.com/google/uuid" "github.com/grokify/go-pkce" - "github.com/loopholelabs/auth/pkg/provider" + "github.com/loopholelabs/auth/pkg/flow" + "github.com/loopholelabs/auth/pkg/storage" "github.com/rs/zerolog" "golang.org/x/oauth2" "golang.org/x/oauth2/google" @@ -32,16 +33,16 @@ import ( "time" ) -var _ provider.Provider = (*Google)(nil) +var _ flow.Flow = (*Google)(nil) var ( ErrInvalidResponse = errors.New("invalid response") ) const ( - Key provider.Key = "google" - GCInterval = time.Minute - Expiry = time.Minute * 5 + Key flow.Key = "google" + GCInterval = time.Minute + Expiry = time.Minute * 5 ) var ( @@ -53,39 +54,64 @@ type email struct { Verified bool `json:"verified"` } +type Options struct { + ClientID string + ClientSecret string + Redirect string +} + type Google struct { - logger *zerolog.Logger - conf *oauth2.Config - database Database - wg sync.WaitGroup - ctx context.Context - cancel context.CancelFunc + logger *zerolog.Logger + storage storage.Google + options *Options + conf *oauth2.Config + wg sync.WaitGroup + ctx context.Context + cancel context.CancelFunc } -func New(clientID string, clientSecret string, redirect string, database Database, logger *zerolog.Logger) *Google { +func New(storage storage.Google, options *Options, logger *zerolog.Logger) *Google { l := logger.With().Str("AUTH", "GOOGLE-OAUTH-PROVIDER").Logger() ctx, cancel := context.WithCancel(context.Background()) return &Google{ - logger: &l, - conf: &oauth2.Config{ - RedirectURL: redirect, - ClientID: clientID, - ClientSecret: clientSecret, - Scopes: defaultScopes, - Endpoint: google.Endpoint, - }, - database: database, - ctx: ctx, - cancel: cancel, + logger: &l, + storage: storage, + options: options, + ctx: ctx, + cancel: cancel, } } -func (g *Google) Key() provider.Key { +func (g *Google) Key() flow.Key { return Key } func (g *Google) Start() error { + if g.options == nil { + return flow.ErrInvalidOptions + } + + if g.options.ClientID == "" { + return flow.ErrInvalidOptions + } + + if g.options.ClientSecret == "" { + return flow.ErrInvalidOptions + } + + if g.options.Redirect == "" { + return flow.ErrInvalidOptions + } + + g.conf = &oauth2.Config{ + RedirectURL: g.options.Redirect, + ClientID: g.options.ClientID, + ClientSecret: g.options.ClientSecret, + Scopes: defaultScopes, + Endpoint: google.Endpoint, + } + g.wg.Add(1) go g.gc() return nil @@ -106,7 +132,7 @@ func (g *Google) StartFlow(ctx context.Context, nextURL string, organization str state := uuid.New().String() g.logger.Debug().Msgf("starting flow for state %s with org '%s' and device identifier '%s'", state, organization, deviceIdentifier) - err = g.database.SetGoogleFlow(ctx, state, verifier, challenge, nextURL, organization, deviceIdentifier) + err = g.storage.SetGoogleFlow(ctx, state, verifier, challenge, nextURL, organization, deviceIdentifier) if err != nil { return "", err } @@ -116,19 +142,19 @@ func (g *Google) StartFlow(ctx context.Context, nextURL string, organization str func (g *Google) CompleteFlow(ctx context.Context, code string, state string) (string, string, string, string, error) { g.logger.Debug().Msgf("completing flow for state %s", state) - flow, err := g.database.GetGoogleFlow(ctx, state) + f, err := g.storage.GetGoogleFlow(ctx, state) if err != nil { return "", "", "", "", err } g.logger.Debug().Msgf("found flow for state %s, deleting", state) - err = g.database.DeleteGoogleFlow(ctx, state) + err = g.storage.DeleteGoogleFlow(ctx, state) if err != nil { return "", "", "", "", err } g.logger.Debug().Msgf("exchanging code for token for state %s", state) - token, err := g.conf.Exchange(ctx, code, oauth2.SetAuthURLParam(pkce.ParamCodeVerifier, flow.Verifier)) + token, err := g.conf.Exchange(ctx, code, oauth2.SetAuthURLParam(pkce.ParamCodeVerifier, f.Verifier)) if err != nil { return "", "", "", "", err } @@ -163,7 +189,7 @@ func (g *Google) CompleteFlow(ctx context.Context, code string, state string) (s return "", "", "", "", err } - return e.Email, flow.Organization, flow.NextURL, flow.DeviceIdentifier, nil + return e.Email, f.Organization, f.NextURL, f.DeviceIdentifier, nil } func (g *Google) gc() { @@ -174,7 +200,7 @@ func (g *Google) gc() { g.logger.Info().Msg("GC Stopped") return case <-time.After(GCInterval): - deleted, err := g.database.GCGoogleFlow(g.ctx, Expiry) + deleted, err := g.storage.GCGoogleFlow(g.ctx, Expiry) if err != nil { g.logger.Error().Err(err).Msg("failed to garbage collect expired google flows") } else { diff --git a/internal/provider/magic/magic.go b/pkg/flow/magic/magic.go similarity index 70% rename from internal/provider/magic/magic.go rename to pkg/flow/magic/magic.go index b9f8e03..b36a15f 100644 --- a/internal/provider/magic/magic.go +++ b/pkg/flow/magic/magic.go @@ -1,17 +1,17 @@ /* - Copyright 2023 Loophole Labs + Copyright 2023 Loophole Labs - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ package magic @@ -23,7 +23,8 @@ import ( "errors" "fmt" "github.com/google/uuid" - "github.com/loopholelabs/auth/pkg/provider" + "github.com/loopholelabs/auth/pkg/flow" + "github.com/loopholelabs/auth/pkg/storage" "github.com/mattevans/postmark-go" "github.com/rs/zerolog" "net/http" @@ -31,11 +32,10 @@ import ( "time" ) -var _ provider.Provider = (*Magic)(nil) +var _ flow.Flow = (*Magic)(nil) var ( - ErrInvalidOptions = errors.New("invalid options") - ErrInvalidSecret = errors.New("invalid secret") + ErrInvalidSecret = errors.New("invalid secret") ) const ( @@ -44,9 +44,9 @@ const ( ) const ( - Key provider.Key = "magic" - GCInterval = time.Minute - Expiry = time.Minute * 5 + Key flow.Key = "magic" + GCInterval = time.Minute + Expiry = time.Minute * 5 ) type Options struct { @@ -60,7 +60,7 @@ type Options struct { type Magic struct { logger *zerolog.Logger - database Database + storage storage.Magic options *Options client *postmark.Client transport *http.Transport @@ -69,38 +69,38 @@ type Magic struct { cancel context.CancelFunc } -func New(database Database, options *Options, logger *zerolog.Logger) *Magic { +func New(storage storage.Magic, options *Options, logger *zerolog.Logger) *Magic { l := logger.With().Str("AUTH", "MAGIC-LINK-PROVIDER").Logger() ctx, cancel := context.WithCancel(context.Background()) return &Magic{ - logger: &l, - database: database, - options: options, - ctx: ctx, - cancel: cancel, + logger: &l, + storage: storage, + options: options, + ctx: ctx, + cancel: cancel, } } -func (g *Magic) Key() provider.Key { +func (g *Magic) Key() flow.Key { return Key } func (g *Magic) Start() error { if g.options == nil { - return ErrInvalidOptions + return flow.ErrInvalidOptions } if g.options.APIToken == "" { - return ErrInvalidOptions + return flow.ErrInvalidOptions } if g.options.From == "" { - return ErrInvalidOptions + return flow.ErrInvalidOptions } if g.options.TemplateID == 0 { - return ErrInvalidOptions + return flow.ErrInvalidOptions } g.transport = &http.Transport{ @@ -122,16 +122,16 @@ func (g *Magic) Stop() error { func (g *Magic) StartFlow(ctx context.Context, email string, ip string, nextURL string, organization string, deviceIdentifier string) (string, error) { secret := uuid.New().String() - _, err := g.database.GetMagicFlow(ctx, email) + _, err := g.storage.GetMagicFlow(ctx, email) if err == nil { - err = g.database.DeleteMagicFlow(ctx, email) + err = g.storage.DeleteMagicFlow(ctx, email) if err != nil { return "", err } } g.logger.Debug().Msgf("starting flow for %s (ip: %s) with org '%s' and device identifier '%s'", email, ip, organization, deviceIdentifier) - err = g.database.SetMagicFlow(ctx, email, ip, secret, nextURL, organization, deviceIdentifier) + err = g.storage.SetMagicFlow(ctx, email, ip, secret, nextURL, organization, deviceIdentifier) if err != nil { return "", err } @@ -195,22 +195,22 @@ func (g *Magic) SendMagic(ctx context.Context, url string, email string, ip stri func (g *Magic) CompleteFlow(ctx context.Context, email string, secret string) (string, string, string, error) { g.logger.Debug().Msgf("completing flow for email %s", email) - flow, err := g.database.GetMagicFlow(ctx, email) + f, err := g.storage.GetMagicFlow(ctx, email) if err != nil { return "", "", "", err } - if flow.Secret != secret { + if f.Secret != secret { return "", "", "", ErrInvalidSecret } g.logger.Debug().Msgf("validated flow for %s, deleting", email) - err = g.database.DeleteMagicFlow(ctx, email) + err = g.storage.DeleteMagicFlow(ctx, email) if err != nil { return "", "", "", err } - return flow.Organization, flow.NextURL, flow.DeviceIdentifier, nil + return f.Organization, f.NextURL, f.DeviceIdentifier, nil } func (g *Magic) gc() { @@ -221,7 +221,7 @@ func (g *Magic) gc() { g.logger.Info().Msg("GC Stopped") return case <-time.After(GCInterval): - deleted, err := g.database.GCMagicFlow(g.ctx, Expiry) + deleted, err := g.storage.GCMagicFlow(g.ctx, Expiry) if err != nil { g.logger.Error().Err(err).Msg("failed to garbage collect expired magic flows") } else { diff --git a/internal/magic/magic.go b/pkg/magic/magic.go similarity index 100% rename from internal/magic/magic.go rename to pkg/magic/magic.go diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index bbe280f..7a147b1 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -25,12 +25,11 @@ import ( "github.com/loopholelabs/auth/internal/api" "github.com/loopholelabs/auth/internal/api/v1/options" "github.com/loopholelabs/auth/internal/controller" - "github.com/loopholelabs/auth/internal/database" - "github.com/loopholelabs/auth/internal/provider/device" - "github.com/loopholelabs/auth/internal/provider/github" - "github.com/loopholelabs/auth/internal/provider/google" - "github.com/loopholelabs/auth/internal/provider/magic" "github.com/loopholelabs/auth/pkg/apikey" + "github.com/loopholelabs/auth/pkg/flow/device" + "github.com/loopholelabs/auth/pkg/flow/github" + "github.com/loopholelabs/auth/pkg/flow/google" + "github.com/loopholelabs/auth/pkg/flow/magic" "github.com/loopholelabs/auth/pkg/servicesession" "github.com/loopholelabs/auth/pkg/session" "github.com/loopholelabs/auth/pkg/storage" @@ -43,12 +42,11 @@ var ( ) type Options struct { + Storage storage.Storage Endpoint string TLS bool SessionDomain string DefaultNextURL string - DatabaseURL string - Storage storage.Storage GithubClientID string GithubClientSecret string GoogleClientID string @@ -65,7 +63,7 @@ type Options struct { type Manager struct { logger *zerolog.Logger controller *controller.Controller - database *database.Database + storage storage.Storage api *api.API ctx context.Context cancel context.CancelFunc @@ -75,10 +73,6 @@ type Manager struct { func New(opts *Options, logger *zerolog.Logger) (*Manager, error) { l := logger.With().Str("AUTH", "MANAGER").Logger() - if opts.DatabaseURL == "" { - return nil, fmt.Errorf("%w: database url is required", ErrInvalidOptions) - } - if opts.DefaultNextURL == "" { return nil, fmt.Errorf("%w: default next url is required", ErrInvalidOptions) } @@ -95,11 +89,6 @@ func New(opts *Options, logger *zerolog.Logger) (*Manager, error) { return nil, fmt.Errorf("%w: session domain is required", ErrInvalidOptions) } - db, err := database.New(opts.DatabaseURL, &l) - if err != nil { - return nil, fmt.Errorf("failed to initialize database: %w", err) - } - scheme := "http" if opts.TLS { scheme = "https" @@ -107,8 +96,12 @@ func New(opts *Options, logger *zerolog.Logger) (*Manager, error) { var githubProvider options.Github if opts.GithubClientID != "" && opts.GithubClientSecret != "" { - ghp := github.New(opts.GithubClientID, opts.GithubClientSecret, fmt.Sprintf("%s://%s/v1/github/callback", scheme, opts.Endpoint), db, &l) - err = ghp.Start() + ghp := github.New(opts.Storage, &github.Options{ + ClientID: opts.GithubClientID, + ClientSecret: opts.GithubClientSecret, + Redirect: fmt.Sprintf("%s://%s/v1/github/callback", scheme, opts.Endpoint), + }, &l) + err := ghp.Start() if err != nil { return nil, fmt.Errorf("failed to start github provider: %w", err) } @@ -119,8 +112,12 @@ func New(opts *Options, logger *zerolog.Logger) (*Manager, error) { var googleProvider options.Google if opts.GoogleClientID != "" && opts.GoogleClientSecret != "" { - ggp := google.New(opts.GoogleClientID, opts.GoogleClientSecret, fmt.Sprintf("%s://%s/v1/google/callback", scheme, opts.Endpoint), db, &l) - err = ggp.Start() + ggp := google.New(opts.Storage, &google.Options{ + ClientID: opts.GoogleClientID, + ClientSecret: opts.GoogleClientSecret, + Redirect: fmt.Sprintf("%s://%s/v1/google/callback", scheme, opts.Endpoint), + }, &l) + err := ggp.Start() if err != nil { return nil, fmt.Errorf("failed to start google provider: %w", err) } @@ -131,8 +128,8 @@ func New(opts *Options, logger *zerolog.Logger) (*Manager, error) { var deviceProvider options.Device if opts.DeviceCode { - dp := device.New(db, &l) - err = dp.Start() + dp := device.New(opts.Storage, &l) + err := dp.Start() if err != nil { return nil, fmt.Errorf("failed to start device code provider: %w", err) } @@ -143,7 +140,7 @@ func New(opts *Options, logger *zerolog.Logger) (*Manager, error) { var magicProvider options.Magic if opts.PostmarkAPIToken != "" && opts.PostmarkTemplateID != 0 && opts.MagicLinkFrom != "" && opts.MagicLinkProjectName != "" && opts.MagicLinkProjectURL != "" { - mp := magic.New(db, &magic.Options{ + mp := magic.New(opts.Storage, &magic.Options{ APIToken: opts.PostmarkAPIToken, TemplateID: opts.PostmarkTemplateID, Tag: opts.PostmarkTag, @@ -151,7 +148,7 @@ func New(opts *Options, logger *zerolog.Logger) (*Manager, error) { Project: opts.MagicLinkProjectName, ProjectURL: opts.MagicLinkProjectURL, }, &l) - err = mp.Start() + err := mp.Start() if err != nil { return nil, fmt.Errorf("failed to start magic link provider: %w", err) } @@ -161,7 +158,7 @@ func New(opts *Options, logger *zerolog.Logger) (*Manager, error) { } c := controller.New(opts.SessionDomain, opts.TLS, opts.Storage, &l) - err = c.Start() + err := c.Start() if err != nil { return nil, fmt.Errorf("failed to start controller: %w", err) } @@ -173,7 +170,7 @@ func New(opts *Options, logger *zerolog.Logger) (*Manager, error) { return &Manager{ logger: &l, controller: c, - database: db, + storage: opts.Storage, api: a, ctx: ctx, cancel: cancel, @@ -217,8 +214,8 @@ func (m *Manager) Cleanup() error { } } - if m.database != nil { - err := m.database.Shutdown() + if m.storage != nil { + err := m.storage.Shutdown() if err != nil { return err } diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go deleted file mode 100644 index ebcb522..0000000 --- a/pkg/provider/provider.go +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2023 Loophole Labs - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package provider - -// Key uniquely identifies authentication providers -// -// Each provider must create its own globally unique key -type Key string - -// Provider is an authentication provider that authorizes -// a user and returns a set of claims -type Provider interface { - // Key returns the authentication provider's unique key - Key() Key - - // Start starts the Provider - Start() error - - // Stop stops the Provider - Stop() error -} diff --git a/pkg/session/session.go b/pkg/session/session.go index 79eb489..b5c0585 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -1,24 +1,24 @@ /* - Copyright 2023 Loophole Labs + Copyright 2023 Loophole Labs - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ package session import ( "github.com/google/uuid" - "github.com/loopholelabs/auth/pkg/provider" + "github.com/loopholelabs/auth/pkg/flow" "github.com/loopholelabs/auth/pkg/sessionKind" "time" ) @@ -37,13 +37,13 @@ type Session struct { Expiry time.Time `json:"expiry"` Kind sessionKind.SessionKind `json:"kind"` Identifier string `json:"identifier"` - Provider provider.Key `json:"provider"` + Provider flow.Key `json:"provider"` Owner string `json:"owner"` Organization string `json:"organization"` } // New returns a new session for a user with the given kind key, provider key, owner identifier, and organization -func New(kind sessionKind.SessionKind, provider provider.Key, owner string, organization string) *Session { +func New(kind sessionKind.SessionKind, provider flow.Key, owner string, organization string) *Session { return &Session{ Creation: time.Now(), Expiry: time.Now().Add(Expiry), diff --git a/pkg/session/session_test.go b/pkg/session/session_test.go index 40dd5a3..ea45deb 100644 --- a/pkg/session/session_test.go +++ b/pkg/session/session_test.go @@ -17,14 +17,14 @@ package session import ( - "github.com/loopholelabs/auth/pkg/provider" + "github.com/loopholelabs/auth/pkg/flow" "github.com/loopholelabs/auth/pkg/sessionKind" "github.com/stretchr/testify/require" "testing" ) func TestSession(t *testing.T) { - pkey := provider.Key("test-provider") + pkey := flow.Key("test-provider") sess := New(sessionKind.Default, pkey, "test-userid", "test-organization") require.Equal(t, sessionKind.Default, sess.Kind) require.Equal(t, pkey, sess.Provider) diff --git a/pkg/storage/flow.go b/pkg/storage/flow.go new file mode 100644 index 0000000..970fc06 --- /dev/null +++ b/pkg/storage/flow.go @@ -0,0 +1,102 @@ +/* + Copyright 2023 Loophole Labs + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package storage + +import ( + "context" + "time" +) + +// DeviceFlow holds the Device Code Authorization Flow +type DeviceFlow struct { + Identifier string `json:"identifier"` + DeviceCode string `json:"device_code"` + UserCode string `json:"user_code"` + Session string `json:"session"` + LastPoll time.Time `json:"last_poll"` + ExpiresAt time.Time `json:"expires_at"` +} + +// GithubFlow holds the Github Authorization Flow +type GithubFlow struct { + Identifier string `json:"identifier"` + Verifier string `json:"verifier"` + Challenge string `json:"challenge"` + NextURL string `json:"next_url"` + Organization string `json:"organization"` + DeviceIdentifier string `json:"device_identifier"` +} + +// GoogleFlow holds the Google Authorization Flow +type GoogleFlow struct { + Identifier string `json:"identifier"` + Verifier string `json:"verifier"` + Challenge string `json:"challenge"` + NextURL string `json:"next_url"` + Organization string `json:"organization"` + DeviceIdentifier string `json:"device_identifier"` +} + +// MagicFlow holds the Magic Authorization Flow +type MagicFlow struct { + Identifier string `json:"identifier"` + Email string `json:"email"` + IPAddress string `json:"ip_address"` + Secret string `json:"secret"` + NextURL string `json:"next_url"` + Organization string `json:"organization"` + DeviceIdentifier string `json:"device_identifier"` +} + +type Device interface { + SetDeviceFlow(ctx context.Context, identifier string, deviceCode string, userCode string) error + GetDeviceFlow(ctx context.Context, deviceCode string) (*DeviceFlow, error) + UpdateDeviceFlow(ctx context.Context, identifier string, session string, expiry time.Time) error + GetDeviceFlowUserCode(ctx context.Context, userCode string) (*DeviceFlow, error) + GetDeviceFlowIdentifier(ctx context.Context, identifier string) (*DeviceFlow, error) + DeleteDeviceFlow(ctx context.Context, deviceCode string) error + GCDeviceFlow(ctx context.Context, expiry time.Duration) (int, error) +} + +type Github interface { + SetGithubFlow(ctx context.Context, state string, verifier string, challenge string, nextURL string, organization string, deviceIdentifier string) error + GetGithubFlow(ctx context.Context, state string) (*GithubFlow, error) + DeleteGithubFlow(ctx context.Context, state string) error + GCGithubFlow(ctx context.Context, expiry time.Duration) (int, error) +} + +type Google interface { + SetGoogleFlow(ctx context.Context, state string, verifier string, challenge string, nextURL string, organization string, deviceIdentifier string) error + GetGoogleFlow(ctx context.Context, state string) (*GoogleFlow, error) + DeleteGoogleFlow(ctx context.Context, state string) error + GCGoogleFlow(ctx context.Context, expiry time.Duration) (int, error) +} + +type Magic interface { + SetMagicFlow(ctx context.Context, email string, ip string, secret string, nextURL string, organization string, deviceIdentifier string) error + GetMagicFlow(ctx context.Context, email string) (*MagicFlow, error) + DeleteMagicFlow(ctx context.Context, email string) error + GCMagicFlow(ctx context.Context, expiry time.Duration) (int, error) +} + +// Flow is the interface for storage of Authorization Flows +type Flow interface { + Device + Github + Google + Magic +} diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index abd3426..79938ed 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -1,17 +1,17 @@ /* - Copyright 2023 Loophole Labs + Copyright 2023 Loophole Labs - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ package storage @@ -44,5 +44,8 @@ type Storage interface { APIKey ServiceKey ServiceSession + Flow Health + + Shutdown() error }