From 77db3581f6af059431a61b414567ffdc93cec091 Mon Sep 17 00:00:00 2001 From: Gokhan Sari Date: Tue, 19 Nov 2024 16:27:30 +0300 Subject: [PATCH 1/8] Add site creation endpoint --- .idea/dataSources.xml | 11 +- backend/cmd/rest-api/main.go | 8 +- backend/go.mod | 20 +++ backend/go.sum | 120 ++++++++++++++- .../poeticmetric/authentication_service.go | 8 +- backend/pkg/poeticmetric/env_service.go | 6 + backend/pkg/poeticmetric/env_service_mock.go | 74 +++++++++ backend/pkg/poeticmetric/errors.go | 3 +- backend/pkg/poeticmetric/models.go | 5 + backend/pkg/poeticmetric/site_service.go | 13 +- .../pkg/poeticmetric/validation_service.go | 6 +- .../poeticmetric/validation_service_mock.go | 14 +- backend/pkg/restapi/docs/docs.go | 108 ++++++++++---- backend/pkg/restapi/docs/swagger.json | 108 ++++++++++---- backend/pkg/restapi/docs/swagger.yaml | 72 ++++++--- .../restapi/handler/authentication/main.go | 12 +- backend/pkg/restapi/handler/sites/main.go | 31 +++- backend/pkg/service/authentication/main.go | 8 +- .../pkg/service/authentication/main_test.go | 20 +-- backend/pkg/service/env/main.go | 21 ++- backend/pkg/service/site/main.go | 45 +++++- backend/pkg/service/site/main_test.go | 113 +++++++++++++- backend/pkg/service/validation/main.go | 141 +++++++++++++++++- backend/pkg/service/validation/main_test.go | 140 +++++++++++++++-- 24 files changed, 958 insertions(+), 149 deletions(-) create mode 100644 backend/pkg/poeticmetric/env_service_mock.go diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index fd412e99..f723246e 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -39,13 +39,10 @@ org.postgresql.Driver jdbc:postgresql://localhost:15432/poeticmetric - - - - - - - + + + + $ProjectFileDir$ diff --git a/backend/cmd/rest-api/main.go b/backend/cmd/rest-api/main.go index b11f9b09..89666d3d 100644 --- a/backend/cmd/rest-api/main.go +++ b/backend/cmd/rest-api/main.go @@ -73,7 +73,8 @@ func main() { } validationService := validation.New(validation.NewParams{ - Postgres: postgres, + EnvService: envService, + Postgres: postgres, }) emailService, err := email.New(email.NewParams{ @@ -96,7 +97,8 @@ func main() { }) siteService := site.New(site.NewParams{ - Postgres: postgres, + Postgres: postgres, + ValidationService: validationService, }) responder := restapiresponder.New(restapiresponder.NewParams{ @@ -134,6 +136,7 @@ func main() { sensitiveRateLimit := alice.New(middleware.SensitiveRateLimit(responder, limiterStore)) permissionBasicAuthenticated := alice.New(middleware.PermissionBasicAuthenticated(responder)) permissionUserAccessTokenAuthenticated := alice.New(middleware.PermissionUserAccessTokenAuthenticated(responder)) + permissionWrite := alice.New(middleware.PermissionOrganizationOwner(responder)) // handlers: authentication mux.Handle("POST /authentication/user-access-tokens", sensitiveRateLimit.Extend(permissionBasicAuthenticated).ThenFunc(authenticationHandler.CreateUserAccessToken)) @@ -153,6 +156,7 @@ func main() { mux.HandleFunc("/{$}", rootHandler.Index()) // handlers: sites + mux.Handle("POST /sites", permissionWrite.ThenFunc(sitesHandler.Create)) mux.Handle("GET /sites", permissionUserAccessTokenAuthenticated.ThenFunc(sitesHandler.List)) httpServer := http.Server{ diff --git a/backend/go.mod b/backend/go.mod index 18c7dedc..a1936747 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -23,12 +23,15 @@ require ( github.com/swaggo/swag v1.16.4 github.com/ulule/limiter/v3 v3.11.2 golang.org/x/crypto v0.29.0 + google.golang.org/api v0.169.0 gorm.io/driver/clickhouse v0.6.1 gorm.io/driver/postgres v1.5.9 gorm.io/gorm v1.25.12 ) require ( + cloud.google.com/go/compute v1.25.1 // indirect + cloud.google.com/go/compute/metadata v0.2.3 // indirect github.com/ClickHouse/ch-go v0.61.5 // indirect github.com/ClickHouse/clickhouse-go/v2 v2.23.2 // indirect github.com/KyleBanks/depth v1.2.1 // indirect @@ -37,12 +40,20 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-faster/city v1.0.1 // indirect github.com/go-faster/errors v0.7.1 // indirect + github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.20.0 // indirect github.com/go-openapi/spec v0.20.6 // indirect github.com/go-openapi/swag v0.19.15 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/google/s2a-go v0.1.7 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect + github.com/googleapis/gax-go/v2 v2.12.2 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-version v1.6.0 // indirect @@ -67,14 +78,23 @@ require ( github.com/stretchr/objx v0.5.2 // indirect github.com/swaggo/files/v2 v2.0.0 // indirect github.com/th0th/disposableemail v0.0.2-0.20241107110532-1e027547679f // indirect + go.opencensus.io v0.24.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect go.opentelemetry.io/otel v1.29.0 // indirect + go.opentelemetry.io/otel/metric v1.29.0 // indirect go.opentelemetry.io/otel/trace v1.29.0 // indirect go.uber.org/atomic v1.11.0 // indirect golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect + golang.org/x/net v0.29.0 // indirect + golang.org/x/oauth2 v0.18.0 // indirect golang.org/x/sync v0.9.0 // indirect golang.org/x/sys v0.27.0 // indirect golang.org/x/text v0.20.0 // indirect golang.org/x/tools v0.24.0 // indirect + google.golang.org/appengine v1.6.8 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect + google.golang.org/grpc v1.64.1 // indirect + google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/backend/go.sum b/backend/go.sum index c6755391..e7cac70e 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -1,5 +1,11 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go/compute v1.25.1 h1:ZRpHJedLtTpKgr3RV1Fx23NuaAEN1Zfx9hw1u4aJdjU= +cloud.google.com/go/compute v1.25.1/go.mod h1:oopOIR53ly6viBYxaDhBfJwzUAxf1zE//uf3IB011ls= +cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= +cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/ClickHouse/ch-go v0.61.5 h1:zwR8QbYI0tsMiEcze/uIMK+Tz1D3XZXLdNrlaOpeEI4= github.com/ClickHouse/ch-go v0.61.5/go.mod h1:s1LJW/F/LcFs5HJnuogFMta50kKDO0lf9zzfrbl0RQg= github.com/ClickHouse/clickhouse-go v1.5.4 h1:cKjXeYLNWVJIx2J1K6H2CqyRmfwVJVY1OV1coaaFcI0= @@ -28,10 +34,13 @@ github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/caarlos0/env/v11 v11.2.2 h1:95fApNrUyueipoZN/EhA8mMxiNxrBwDa+oAZrMWl3Kg= github.com/caarlos0/env/v11 v11.2.2/go.mod h1:JBfcdeQiBoI3Zh1QRAWfe+tpiNTmDtcCj/hHHHMx0vc= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 h1:F1EaeKL/ta07PY/k9Os/UFtwERei2/XzGemhpGnBKNg= github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -51,6 +60,10 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk= @@ -59,6 +72,7 @@ github.com/go-faster/city v1.0.1 h1:4WAxSZ3V2Ws4QRDrscLEDcibJY8uf41H6AhXDrNDcGw= github.com/go-faster/city v1.0.1/go.mod h1:jKcUJId49qdW3L1qKHH/3wPeUstCVpVSXTM6vO3VcTw= github.com/go-faster/errors v0.7.1 h1:MkJTnDoEdi9pDabt1dpWf7AA8/BaSYZqibYyhZ20AYg= github.com/go-faster/errors v0.7.1/go.mod h1:5ySTjWFiphBs07IKuiL69nxdfd5+fzh1u7FPGZP2quo= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= @@ -78,14 +92,44 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-migrate/migrate/v4 v4.18.1 h1:JML/k+t4tpHCpQTCAD62Nu43NUFzHY4CV3uAuvHGC+Y= github.com/golang-migrate/migrate/v4 v4.18.1/go.mod h1:HAX6m3sQgcdO81tdjn5exv20+3Kb13cmGli1hrD6hks= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.3/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.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= +github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs= +github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= +github.com/googleapis/gax-go/v2 v2.12.2 h1:mhN09QQW1jEWeMF74zGR81R30z4VJzjZsfkUhuHF+DA= +github.com/googleapis/gax-go/v2 v2.12.2/go.mod h1:61M8vcyyXR2kqKFxKrfA22jaA8JGF7Dc8App1U3H6jc= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -157,6 +201,7 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E= github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw= github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= @@ -170,11 +215,16 @@ github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/swaggo/files/v2 v2.0.0 h1:hmAt8Dkynw7Ssz46F6pn8ok6YmGZqHSVLZ+HQM7i0kw= @@ -194,8 +244,10 @@ 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.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= -go.opentelemetry.io/contrib v0.20.0 h1:ubFQUn0VCZ0gPwIoJfBJVpeBlyRMxu8Mm/huKWYd9p0= +go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= +go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8= go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= @@ -209,56 +261,120 @@ go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea h1:vLCWI/yYrdEHyN2JzIzPO3aaQJHQdp89IZBA/+azVC4= golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 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.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +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-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/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-20201110031124-69a78807bb2b/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-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= +golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.169.0 h1:QwWPy71FgMWqJN/l6jVlFHUa29a7dcUy02I8o799nPY= +google.golang.org/api v0.169.0/go.mod h1:gpNOiMA2tZ4mf5R9Iwf4rK/Dcz0fbdIgWYWVoxmsyLg= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= +google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 h1:9+tzLLstTlPTRyJTh+ah5wIMsBW5c4tQwGTN3thOW9Y= +google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 h1:W5Xj/70xIA4x60O/IFyXivR5MGqblAb8R3w26pnD6No= +google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8/go.mod h1:vPrPUTsDCYxXWjP7clS81mZ6/803D8K4iM9Ma27VKas= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 h1:mxSlqyb8ZAHsYDCfiXN1EDdNTdvjUJSLY+OnAUtYNYA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= +google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -277,3 +393,5 @@ gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8= gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/backend/pkg/poeticmetric/authentication_service.go b/backend/pkg/poeticmetric/authentication_service.go index 4f28cdea..5336b9cd 100644 --- a/backend/pkg/poeticmetric/authentication_service.go +++ b/backend/pkg/poeticmetric/authentication_service.go @@ -13,8 +13,8 @@ type AuthenticationService interface { ReadUserAccessToken(ctx context.Context, userAccessTokenID uint) (*AuthenticationUserAccessToken, error) ReadUserByEmailPassword(ctx context.Context, email string, password string) (*User, error) ReadUserByUserAccessToken(ctx context.Context, token string) (*User, *UserAccessToken, error) - ResetUserPassword(ctx context.Context, params *AuthenticationResetUserPasswordParams) error - SendUserPasswordRecoveryEmail(ctx context.Context, params *AuthenticationSendUserPasswordRecoveryEmailParams) error + ResetUserPassword(ctx context.Context, params *ResetUserPasswordParams) error + SendUserPasswordRecoveryEmail(ctx context.Context, params *SendUserPasswordRecoveryEmailParams) error ValidateUserPasswordResetToken(ctx context.Context, token string) (bool, error) } @@ -24,11 +24,11 @@ type AuthenticationUserAccessToken struct { Token string `json:"token"` } -type AuthenticationSendUserPasswordRecoveryEmailParams struct { +type SendUserPasswordRecoveryEmailParams struct { Email *string `json:"email"` } -type AuthenticationResetUserPasswordParams struct { +type ResetUserPasswordParams struct { PasswordResetToken *string UserPassword *string UserPassword2 *string diff --git a/backend/pkg/poeticmetric/env_service.go b/backend/pkg/poeticmetric/env_service.go index e6400da5..9940133a 100644 --- a/backend/pkg/poeticmetric/env_service.go +++ b/backend/pkg/poeticmetric/env_service.go @@ -3,6 +3,7 @@ package poeticmetric import ( "net/smtp" + "golang.org/x/oauth2" "gorm.io/gorm" ) @@ -11,6 +12,7 @@ type EnvService interface { ClickhouseDsn() string Debug() bool FrontendUrl(path string) string + GoogleOAuthConfig() (*oauth2.Config, error) GormConfig() *gorm.Config IsHosted() bool PostgresDatabase() string @@ -36,6 +38,10 @@ type EnvServiceVars struct { ClickhousePort int `env:"CLICKHOUSE_PORT,notEmpty,required"` ClickhouseUser string `env:"CLICKHOUSE_USER,notEmpty,required"` + // Google + GoogleClientID *string `env:"GOOGLE_CLIENT_ID"` + GoogleClientSecret *string `env:"GOOGLE_CLIENT_SECRET"` + // Postgres PostgresDatabase string `env:"POSTGRES_DATABASE,notEmpty,required"` PostgresHost string `env:"POSTGRES_HOST,notEmpty,required"` diff --git a/backend/pkg/poeticmetric/env_service_mock.go b/backend/pkg/poeticmetric/env_service_mock.go new file mode 100644 index 00000000..9b442e76 --- /dev/null +++ b/backend/pkg/poeticmetric/env_service_mock.go @@ -0,0 +1,74 @@ +package poeticmetric + +import ( + "net/smtp" + + "github.com/stretchr/testify/mock" + "golang.org/x/oauth2" + "gorm.io/gorm" +) + +type EnvServiceMock struct { + mock.Mock +} + +func (s *EnvServiceMock) ClickhouseDatabase() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) ClickhouseDsn() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) Debug() bool { + return s.Called().Bool(0) +} + +func (s *EnvServiceMock) FrontendUrl(path string) string { + return s.Called(path).String(0) +} + +func (s *EnvServiceMock) GoogleOAuthConfig() (*oauth2.Config, error) { + args := s.Called() + return args.Get(0).(*oauth2.Config), args.Error(1) +} + +func (s *EnvServiceMock) GormConfig() *gorm.Config { + return s.Called().Get(0).(*gorm.Config) +} + +func (s *EnvServiceMock) IsHosted() bool { + return s.Called().Bool(0) +} + +func (s *EnvServiceMock) PostgresDatabase() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) PostgresDsn() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) RedisAddr() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) RedisPassword() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) RestApiBasePath() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) SmtpAddr() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) SmtpAuth() smtp.Auth { + return s.Called().Get(0).(smtp.Auth) +} + +func (s *EnvServiceMock) SmtpFrom() string { + return s.Called().String(0) +} diff --git a/backend/pkg/poeticmetric/errors.go b/backend/pkg/poeticmetric/errors.go index 86e2fc62..8c442942 100644 --- a/backend/pkg/poeticmetric/errors.go +++ b/backend/pkg/poeticmetric/errors.go @@ -5,5 +5,6 @@ import ( ) var ( - ErrNotFound = errors.New("not found") + ErrNoOrganizationGoogleOauthRefreshToken = errors.New("organization doesn't have a google oauth refresh token") + ErrNotFound = errors.New("not found") ) diff --git a/backend/pkg/poeticmetric/models.go b/backend/pkg/poeticmetric/models.go index 59472762..f4ad9575 100644 --- a/backend/pkg/poeticmetric/models.go +++ b/backend/pkg/poeticmetric/models.go @@ -23,6 +23,11 @@ const ( OrganizationSubscriptionPeriodYear = "YEAR" ) +const ( + SiteNameMaxLength = 50 + SiteNameMinLength = 1 +) + const ( UserNameMaxLength = 70 UserNameMinLength = 1 diff --git a/backend/pkg/poeticmetric/site_service.go b/backend/pkg/poeticmetric/site_service.go index 1afb89ad..0708fe23 100644 --- a/backend/pkg/poeticmetric/site_service.go +++ b/backend/pkg/poeticmetric/site_service.go @@ -5,10 +5,18 @@ import ( "time" ) +type CreateSiteParams struct { + Domain *string `json:"domain"` + GoogleSearchConsoleSiteURL *string `json:"googleSearchConsoleSiteURL"` + IsPublic *bool `json:"isPublic"` + Name *string `json:"name"` + SafeQueryParameters []string `gorm:"serializer:json" json:"safeQueryParameters"` +} + type OrganizationSite struct { CreatedAt time.Time `json:"createdAt"` Domain string `json:"domain"` - GoogleSearchConsoleSiteUrl *string `json:"googleSearchConsoleSiteUrl"` + GoogleSearchConsoleSiteUrl *string `json:"googleSearchConsoleSiteURL"` HasEvents bool `json:"hasEvents"` ID uint `json:"ID"` IsPublic bool `json:"isPublic"` @@ -20,5 +28,6 @@ type OrganizationSite struct { type SiteService interface { ServiceWithPostgres - ListOrganizationSites(ctx context.Context, organizationID uint) ([]*OrganizationSite, error) + Create(ctx context.Context, organizationID uint, params *CreateSiteParams) (*OrganizationSite, error) + List(ctx context.Context, organizationID uint) ([]*OrganizationSite, error) } diff --git a/backend/pkg/poeticmetric/validation_service.go b/backend/pkg/poeticmetric/validation_service.go index 5f74ad29..1c207755 100644 --- a/backend/pkg/poeticmetric/validation_service.go +++ b/backend/pkg/poeticmetric/validation_service.go @@ -7,7 +7,7 @@ import ( type ValidationService interface { ServiceWithPostgres - AuthenticationResetUserPasswordParams(ctx context.Context, params *AuthenticationResetUserPasswordParams) error - AuthenticationSendUserPasswordRecoveryEmailParams(ctx context.Context, params *AuthenticationSendUserPasswordRecoveryEmailParams) error + CreateSiteParams(ctx context.Context, organizationID uint, params *CreateSiteParams) error + ResetUserPasswordParams(ctx context.Context, params *ResetUserPasswordParams) error + SendUserPasswordRecoveryEmailParams(ctx context.Context, params *SendUserPasswordRecoveryEmailParams) error } - diff --git a/backend/pkg/poeticmetric/validation_service_mock.go b/backend/pkg/poeticmetric/validation_service_mock.go index 09cbaa69..3ea5192a 100644 --- a/backend/pkg/poeticmetric/validation_service_mock.go +++ b/backend/pkg/poeticmetric/validation_service_mock.go @@ -7,18 +7,22 @@ import ( "gorm.io/gorm" ) -type MockValidationService struct { +type ValidationServiceMock struct { mock.Mock } -func (m *MockValidationService) Postgres() *gorm.DB { - return m.Called().Get(0).(*gorm.DB) +func (m *ValidationServiceMock) ResetUserPasswordParams(ctx context.Context, params *ResetUserPasswordParams) error { + return m.Called(ctx, params).Error(0) } -func (m *MockValidationService) AuthenticationResetUserPasswordParams(ctx context.Context, params *AuthenticationResetUserPasswordParams) error { +func (m *ValidationServiceMock) SendUserPasswordRecoveryEmailParams(ctx context.Context, params *SendUserPasswordRecoveryEmailParams) error { return m.Called(ctx, params).Error(0) } -func (m *MockValidationService) AuthenticationSendUserPasswordRecoveryEmailParams(ctx context.Context, params *AuthenticationSendUserPasswordRecoveryEmailParams) error { +func (m *ValidationServiceMock) CreateSiteParams(ctx context.Context, organizationID uint, params *CreateSiteParams) error { return m.Called(ctx, params).Error(0) } + +func (m *ValidationServiceMock) Postgres() *gorm.DB { + return m.Called().Get(0).(*gorm.DB) +} diff --git a/backend/pkg/restapi/docs/docs.go b/backend/pkg/restapi/docs/docs.go index 8bde4708..6335ad2b 100644 --- a/backend/pkg/restapi/docs/docs.go +++ b/backend/pkg/restapi/docs/docs.go @@ -30,7 +30,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/poeticmetric.AuthenticationResetUserPasswordParams" + "$ref": "#/definitions/poeticmetric.ResetUserPasswordParams" } } ], @@ -44,7 +44,7 @@ const docTemplate = `{ "422": { "description": "Unprocessable Entity", "schema": { - "$ref": "#/definitions/poeticmetric.AuthenticationResetUserPasswordParams" + "$ref": "#/definitions/poeticmetric.ResetUserPasswordParams" } } } @@ -64,7 +64,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams" + "$ref": "#/definitions/poeticmetric.SendUserPasswordRecoveryEmailParams" } } ], @@ -115,7 +115,7 @@ const docTemplate = `{ "tags": [ "authentication" ], - "summary": "Create user access token", + "summary": "Delete user access token", "responses": { "204": { "description": "No Content" @@ -195,32 +195,41 @@ const docTemplate = `{ } } } + }, + "post": { + "security": [ + { + "UserAccessTokenAuthentication": [] + } + ], + "description": "Create site.", + "tags": [ + "sites" + ], + "summary": "Create site", + "parameters": [ + { + "description": "Params", + "name": "params", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/poeticmetric.CreateSiteParams" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/poeticmetric.OrganizationSite" + } + } + } } } }, "definitions": { - "poeticmetric.AuthenticationResetUserPasswordParams": { - "type": "object", - "properties": { - "passwordResetToken": { - "type": "string" - }, - "userPassword": { - "type": "string" - }, - "userPassword2": { - "type": "string" - } - } - }, - "poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams": { - "type": "object", - "properties": { - "email": { - "type": "string" - } - } - }, "poeticmetric.AuthenticationUserAccessToken": { "type": "object", "properties": { @@ -258,6 +267,29 @@ const docTemplate = `{ } } }, + "poeticmetric.CreateSiteParams": { + "type": "object", + "properties": { + "domain": { + "type": "string" + }, + "googleSearchConsoleSiteURL": { + "type": "string" + }, + "isPublic": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "safeQueryParameters": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "poeticmetric.OrganizationSite": { "type": "object", "properties": { @@ -270,7 +302,7 @@ const docTemplate = `{ "domain": { "type": "string" }, - "googleSearchConsoleSiteUrl": { + "googleSearchConsoleSiteURL": { "type": "string" }, "hasEvents": { @@ -293,6 +325,28 @@ const docTemplate = `{ } } }, + "poeticmetric.ResetUserPasswordParams": { + "type": "object", + "properties": { + "passwordResetToken": { + "type": "string" + }, + "userPassword": { + "type": "string" + }, + "userPassword2": { + "type": "string" + } + } + }, + "poeticmetric.SendUserPasswordRecoveryEmailParams": { + "type": "object", + "properties": { + "email": { + "type": "string" + } + } + }, "responder.DetailResponse": { "type": "object", "properties": { diff --git a/backend/pkg/restapi/docs/swagger.json b/backend/pkg/restapi/docs/swagger.json index dce00fe8..fd36c197 100644 --- a/backend/pkg/restapi/docs/swagger.json +++ b/backend/pkg/restapi/docs/swagger.json @@ -22,7 +22,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/poeticmetric.AuthenticationResetUserPasswordParams" + "$ref": "#/definitions/poeticmetric.ResetUserPasswordParams" } } ], @@ -36,7 +36,7 @@ "422": { "description": "Unprocessable Entity", "schema": { - "$ref": "#/definitions/poeticmetric.AuthenticationResetUserPasswordParams" + "$ref": "#/definitions/poeticmetric.ResetUserPasswordParams" } } } @@ -56,7 +56,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams" + "$ref": "#/definitions/poeticmetric.SendUserPasswordRecoveryEmailParams" } } ], @@ -107,7 +107,7 @@ "tags": [ "authentication" ], - "summary": "Create user access token", + "summary": "Delete user access token", "responses": { "204": { "description": "No Content" @@ -187,32 +187,41 @@ } } } + }, + "post": { + "security": [ + { + "UserAccessTokenAuthentication": [] + } + ], + "description": "Create site.", + "tags": [ + "sites" + ], + "summary": "Create site", + "parameters": [ + { + "description": "Params", + "name": "params", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/poeticmetric.CreateSiteParams" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/poeticmetric.OrganizationSite" + } + } + } } } }, "definitions": { - "poeticmetric.AuthenticationResetUserPasswordParams": { - "type": "object", - "properties": { - "passwordResetToken": { - "type": "string" - }, - "userPassword": { - "type": "string" - }, - "userPassword2": { - "type": "string" - } - } - }, - "poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams": { - "type": "object", - "properties": { - "email": { - "type": "string" - } - } - }, "poeticmetric.AuthenticationUserAccessToken": { "type": "object", "properties": { @@ -250,6 +259,29 @@ } } }, + "poeticmetric.CreateSiteParams": { + "type": "object", + "properties": { + "domain": { + "type": "string" + }, + "googleSearchConsoleSiteURL": { + "type": "string" + }, + "isPublic": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "safeQueryParameters": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "poeticmetric.OrganizationSite": { "type": "object", "properties": { @@ -262,7 +294,7 @@ "domain": { "type": "string" }, - "googleSearchConsoleSiteUrl": { + "googleSearchConsoleSiteURL": { "type": "string" }, "hasEvents": { @@ -285,6 +317,28 @@ } } }, + "poeticmetric.ResetUserPasswordParams": { + "type": "object", + "properties": { + "passwordResetToken": { + "type": "string" + }, + "userPassword": { + "type": "string" + }, + "userPassword2": { + "type": "string" + } + } + }, + "poeticmetric.SendUserPasswordRecoveryEmailParams": { + "type": "object", + "properties": { + "email": { + "type": "string" + } + } + }, "responder.DetailResponse": { "type": "object", "properties": { diff --git a/backend/pkg/restapi/docs/swagger.yaml b/backend/pkg/restapi/docs/swagger.yaml index 54d8b045..ebbaafbf 100644 --- a/backend/pkg/restapi/docs/swagger.yaml +++ b/backend/pkg/restapi/docs/swagger.yaml @@ -1,18 +1,4 @@ definitions: - poeticmetric.AuthenticationResetUserPasswordParams: - properties: - passwordResetToken: - type: string - userPassword: - type: string - userPassword2: - type: string - type: object - poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams: - properties: - email: - type: string - type: object poeticmetric.AuthenticationUserAccessToken: properties: createdAt: @@ -37,6 +23,21 @@ definitions: userPassword2: type: string type: object + poeticmetric.CreateSiteParams: + properties: + domain: + type: string + googleSearchConsoleSiteURL: + type: string + isPublic: + type: boolean + name: + type: string + safeQueryParameters: + items: + type: string + type: array + type: object poeticmetric.OrganizationSite: properties: ID: @@ -45,7 +46,7 @@ definitions: type: string domain: type: string - googleSearchConsoleSiteUrl: + googleSearchConsoleSiteURL: type: string hasEvents: type: boolean @@ -60,6 +61,20 @@ definitions: updatedAt: type: string type: object + poeticmetric.ResetUserPasswordParams: + properties: + passwordResetToken: + type: string + userPassword: + type: string + userPassword2: + type: string + type: object + poeticmetric.SendUserPasswordRecoveryEmailParams: + properties: + email: + type: string + type: object responder.DetailResponse: properties: detail: @@ -83,7 +98,7 @@ paths: name: params required: true schema: - $ref: '#/definitions/poeticmetric.AuthenticationResetUserPasswordParams' + $ref: '#/definitions/poeticmetric.ResetUserPasswordParams' responses: "200": description: OK @@ -92,7 +107,7 @@ paths: "422": description: Unprocessable Entity schema: - $ref: '#/definitions/poeticmetric.AuthenticationResetUserPasswordParams' + $ref: '#/definitions/poeticmetric.ResetUserPasswordParams' summary: Reset user's password tags: - authentication @@ -105,7 +120,7 @@ paths: name: params required: true schema: - $ref: '#/definitions/poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams' + $ref: '#/definitions/poeticmetric.SendUserPasswordRecoveryEmailParams' responses: "201": description: Created @@ -126,7 +141,7 @@ paths: $ref: '#/definitions/responder.DetailResponse' security: - UserAccessTokenAuthentication: [] - summary: Create user access token + summary: Delete user access token tags: - authentication post: @@ -189,6 +204,25 @@ paths: summary: List sites tags: - sites + post: + description: Create site. + parameters: + - description: Params + in: body + name: params + required: true + schema: + $ref: '#/definitions/poeticmetric.CreateSiteParams' + responses: + "201": + description: Created + schema: + $ref: '#/definitions/poeticmetric.OrganizationSite' + security: + - UserAccessTokenAuthentication: [] + summary: Create site + tags: + - sites securityDefinitions: BasicAuthentication: type: basic diff --git a/backend/pkg/restapi/handler/authentication/main.go b/backend/pkg/restapi/handler/authentication/main.go index b0abb051..f5229321 100644 --- a/backend/pkg/restapi/handler/authentication/main.go +++ b/backend/pkg/restapi/handler/authentication/main.go @@ -53,7 +53,7 @@ func (h *Handler) CreateUserAccessToken(w http.ResponseWriter, r *http.Request) // @Router /authentication/user-access-tokens [delete] // @Security UserAccessTokenAuthentication // @Success 204 -// @Summary Create user access token +// @Summary Delete user access token // @Tags authentication func (h *Handler) DeleteUserAccessToken(w http.ResponseWriter, r *http.Request) { authentication := middleware.GetAuthentication(r.Context()) @@ -69,14 +69,14 @@ func (h *Handler) DeleteUserAccessToken(w http.ResponseWriter, r *http.Request) // ResetUserPassword godoc // @Description Reset user's password also deleting all existing user access tokens for that user. -// @Failure 422 {object} poeticmetric.AuthenticationResetUserPasswordParams -// @Param params body poeticmetric.AuthenticationResetUserPasswordParams true "Params" +// @Failure 422 {object} poeticmetric.ResetUserPasswordParams +// @Param params body poeticmetric.ResetUserPasswordParams true "Params" // @Router /authentication/reset-user-password [post] // @Success 200 {object} responder.DetailResponse // @Summary Reset user's password // @Tags authentication func (h *Handler) ResetUserPassword(w http.ResponseWriter, r *http.Request) { - params := poeticmetric.AuthenticationResetUserPasswordParams{} + params := poeticmetric.ResetUserPasswordParams{} err := json.NewDecoder(r.Body).Decode(¶ms) if err != nil { h.responder.Error(w, err) @@ -94,13 +94,13 @@ func (h *Handler) ResetUserPassword(w http.ResponseWriter, r *http.Request) { // SendUserPasswordRecoveryEmail godoc // @Description Send a password recovery e-mail to the user. -// @Param params body poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams true "Params" +// @Param params body poeticmetric.SendUserPasswordRecoveryEmailParams true "Params" // @Router /authentication/send-user-password-recovery-email [post] // @Success 201 {object} responder.DetailResponse // @Summary Send user password recovery e-mail // @Tags authentication func (h *Handler) SendUserPasswordRecoveryEmail(w http.ResponseWriter, r *http.Request) { - params := poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams{} + params := poeticmetric.SendUserPasswordRecoveryEmailParams{} err := json.NewDecoder(r.Body).Decode(¶ms) if err != nil { h.responder.Error(w, err) diff --git a/backend/pkg/restapi/handler/sites/main.go b/backend/pkg/restapi/handler/sites/main.go index a3690cba..6c8aadf6 100644 --- a/backend/pkg/restapi/handler/sites/main.go +++ b/backend/pkg/restapi/handler/sites/main.go @@ -1,6 +1,7 @@ package sites import ( + "encoding/json" "net/http" "github.com/th0th/poeticmetric/backend/pkg/poeticmetric" @@ -24,6 +25,34 @@ func New(params NewParams) *Handler { } } +// Create godoc +// @Description Create site. +// @Param params body poeticmetric.CreateSiteParams true "Params" +// @Router /sites [post] +// @Security UserAccessTokenAuthentication +// @Success 201 {object} poeticmetric.OrganizationSite +// @Summary Create site +// @Tags sites +func (h *Handler) Create(w http.ResponseWriter, r *http.Request) { + auth := middleware.GetAuthentication(r.Context()) + + params := poeticmetric.CreateSiteParams{} + err := json.NewDecoder(r.Body).Decode(¶ms) + if err != nil { + h.responder.Error(w, err) + return + } + + organizationSite, err := h.siteService.Create(r.Context(), auth.User.OrganizationID, ¶ms) + if err != nil { + h.responder.Error(w, err) + return + } + + w.WriteHeader(http.StatusCreated) + h.responder.Json(w, organizationSite) +} + // List godoc // @Description List sites. // @Router /sites [get] @@ -34,7 +63,7 @@ func New(params NewParams) *Handler { func (h *Handler) List(w http.ResponseWriter, r *http.Request) { auth := middleware.GetAuthentication(r.Context()) - organizationSites, err := h.siteService.ListOrganizationSites(r.Context(), auth.User.OrganizationID) + organizationSites, err := h.siteService.List(r.Context(), auth.User.OrganizationID) if err != nil { h.responder.Error(w, err) return diff --git a/backend/pkg/service/authentication/main.go b/backend/pkg/service/authentication/main.go index d07fa3e0..a12018cc 100644 --- a/backend/pkg/service/authentication/main.go +++ b/backend/pkg/service/authentication/main.go @@ -156,8 +156,8 @@ func (s *service) ReadUserByUserAccessToken(ctx context.Context, token string) ( return &user, &userAccessToken, nil } -func (s *service) ResetUserPassword(ctx context.Context, params *poeticmetric.AuthenticationResetUserPasswordParams) error { - err := s.validationService.AuthenticationResetUserPasswordParams(ctx, params) +func (s *service) ResetUserPassword(ctx context.Context, params *poeticmetric.ResetUserPasswordParams) error { + err := s.validationService.ResetUserPasswordParams(ctx, params) if err != nil { return err } @@ -189,8 +189,8 @@ func (s *service) ResetUserPassword(ctx context.Context, params *poeticmetric.Au return nil } -func (s *service) SendUserPasswordRecoveryEmail(ctx context.Context, params *poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams) error { - err := s.validationService.AuthenticationSendUserPasswordRecoveryEmailParams(ctx, params) +func (s *service) SendUserPasswordRecoveryEmail(ctx context.Context, params *poeticmetric.SendUserPasswordRecoveryEmailParams) error { + err := s.validationService.SendUserPasswordRecoveryEmailParams(ctx, params) if err != nil { return err } diff --git a/backend/pkg/service/authentication/main_test.go b/backend/pkg/service/authentication/main_test.go index 5a992490..62d2eacb 100644 --- a/backend/pkg/service/authentication/main_test.go +++ b/backend/pkg/service/authentication/main_test.go @@ -23,7 +23,7 @@ import ( func TestNew(t *testing.T) { emailService := new(email.MockService) postgres := new(gorm.DB) - validationService := new(poeticmetric.MockValidationService) + validationService := new(poeticmetric.ValidationServiceMock) type args struct { params NewParams @@ -327,7 +327,7 @@ func Test_service_ResetUserPassword(t *testing.T) { postgres, gotErr := gorm.Open(postgres2.New(postgres2.Config{Conn: db}), &gorm.Config{}) assert.NoError(t, gotErr) - mockValidationService := new(poeticmetric.MockValidationService) + mockValidationService := new(poeticmetric.ValidationServiceMock) // language=postgresql selectQuery := `SELECT "id" FROM "users" WHERE "users"."password_reset_token" = $1 ORDER BY "users"."id" LIMIT $2` @@ -342,7 +342,7 @@ func Test_service_ResetUserPassword(t *testing.T) { } type args struct { ctx context.Context - params *poeticmetric.AuthenticationResetUserPasswordParams + params *poeticmetric.ResetUserPasswordParams } type payload struct { password *sqlmockhelper.ValueArg @@ -363,7 +363,7 @@ func Test_service_ResetUserPassword(t *testing.T) { }, args: args{ ctx: context.Background(), - params: &poeticmetric.AuthenticationResetUserPasswordParams{ + params: &poeticmetric.ResetUserPasswordParams{ PasswordResetToken: poeticmetric.Pointer("token"), UserPassword: poeticmetric.Pointer("password"), UserPassword2: poeticmetric.Pointer("password"), @@ -380,7 +380,7 @@ func Test_service_ResetUserPassword(t *testing.T) { sqlMock.ExpectExec(updateQuery).WithArgs(passwordArg, sqlmock.AnyArg(), 1).WillReturnResult(sqlmock.NewResult(0, 1)) sqlMock.ExpectCommit() - mockValidationService.On("AuthenticationResetUserPasswordParams", mock.Anything, &poeticmetric.AuthenticationResetUserPasswordParams{ + mockValidationService.On("ResetUserPasswordParams", mock.Anything, &poeticmetric.ResetUserPasswordParams{ PasswordResetToken: poeticmetric.Pointer("token"), UserPassword: poeticmetric.Pointer("password"), UserPassword2: poeticmetric.Pointer("password"), @@ -418,7 +418,7 @@ func Test_service_ResetUserPassword(t *testing.T) { func Test_service_SendUserPasswordRecoveryEmail(t *testing.T) { mockEmailService := new(email.MockService) - mockValidationService := new(poeticmetric.MockValidationService) + mockValidationService := new(poeticmetric.ValidationServiceMock) db, sqlMock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual)) assert.NoError(t, err) @@ -441,7 +441,7 @@ func Test_service_SendUserPasswordRecoveryEmail(t *testing.T) { } type args struct { ctx context.Context - params *poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams + params *poeticmetric.SendUserPasswordRecoveryEmailParams } tests := []struct { name string @@ -459,7 +459,7 @@ func Test_service_SendUserPasswordRecoveryEmail(t *testing.T) { }, args: args{ ctx: context.Background(), - params: &poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams{ + params: &poeticmetric.SendUserPasswordRecoveryEmailParams{ Email: poeticmetric.Pointer("user@domain.tld"), }, }, @@ -484,9 +484,9 @@ func Test_service_SendUserPasswordRecoveryEmail(t *testing.T) { })).Return(nil) mockValidationService.On( - "AuthenticationSendUserPasswordRecoveryEmailParams", + "SendUserPasswordRecoveryEmailParams", mock.Anything, - &poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams{ + &poeticmetric.SendUserPasswordRecoveryEmailParams{ Email: poeticmetric.Pointer("user@domain.tld"), }, ).Return(nil) diff --git a/backend/pkg/service/env/main.go b/backend/pkg/service/env/main.go index e30405bd..da37467d 100644 --- a/backend/pkg/service/env/main.go +++ b/backend/pkg/service/env/main.go @@ -5,8 +5,11 @@ import ( "net/smtp" "os" - env2 "github.com/caarlos0/env/v11" + "github.com/caarlos0/env/v11" "github.com/rs/zerolog" + "golang.org/x/oauth2" + "golang.org/x/oauth2/google" + "google.golang.org/api/searchconsole/v1" "gorm.io/gorm" "gorm.io/gorm/logger" @@ -20,7 +23,7 @@ type service struct { func New() (poeticmetric.EnvService, error) { e := service{} - err := env2.Parse(&e.vars) + err := env.Parse(&e.vars) if err != nil { return nil, err } @@ -55,6 +58,20 @@ func (s *service) FrontendUrl(path string) string { return fmt.Sprintf("%s%s", s.vars.FrontendBaseUrl, path) } +func (s *service) GoogleOAuthConfig() (*oauth2.Config, error) { + if s.vars.GoogleClientID == nil || s.vars.GoogleClientSecret == nil { + return nil, fmt.Errorf("google oauth credentials are not set") + } + + return &oauth2.Config{ + ClientID: *s.vars.GoogleClientID, + ClientSecret: *s.vars.GoogleClientSecret, + Endpoint: google.Endpoint, + RedirectURL: s.FrontendUrl(""), + Scopes: []string{searchconsole.WebmastersReadonlyScope}, + }, nil +} + func (s *service) GormConfig() *gorm.Config { logLevel := logger.Error diff --git a/backend/pkg/service/site/main.go b/backend/pkg/service/site/main.go index 7565580f..40f893b1 100644 --- a/backend/pkg/service/site/main.go +++ b/backend/pkg/service/site/main.go @@ -9,20 +9,57 @@ import ( ) type NewParams struct { - Postgres *gorm.DB + Postgres *gorm.DB + ValidationService poeticmetric.ValidationService } type service struct { - postgres *gorm.DB + postgres *gorm.DB + validationService poeticmetric.ValidationService } func New(params NewParams) poeticmetric.SiteService { return &service{ - postgres: params.Postgres, + postgres: params.Postgres, + validationService: params.ValidationService, } } -func (s *service) ListOrganizationSites(ctx context.Context, organizationID uint) ([]*poeticmetric.OrganizationSite, error) { +func (s *service) Create(ctx context.Context, organizationID uint, params *poeticmetric.CreateSiteParams) (*poeticmetric.OrganizationSite, error) { + err := s.validationService.CreateSiteParams(ctx, organizationID, params) + if err != nil { + return nil, err + } + + postgres := poeticmetric.ServicePostgres(ctx, s) + + site := &poeticmetric.Site{ + Domain: *params.Domain, + IsPublic: *params.IsPublic, + Name: *params.Name, + SafeQueryParameters: params.SafeQueryParameters, + OrganizationID: organizationID, + } + + err = postgres.Create(site).Error + if err != nil { + return nil, err + } + + return &poeticmetric.OrganizationSite{ + CreatedAt: site.CreatedAt, + Domain: site.Domain, + GoogleSearchConsoleSiteUrl: site.GoogleSearchConsoleSiteUrl, + HasEvents: site.HasEvents, + ID: site.ID, + IsPublic: site.IsPublic, + Name: site.Name, + SafeQueryParameters: site.SafeQueryParameters, + UpdatedAt: site.UpdatedAt, + }, nil +} + +func (s *service) List(ctx context.Context, organizationID uint) ([]*poeticmetric.OrganizationSite, error) { postgres := poeticmetric.ServicePostgres(ctx, s) organizationSites := []*poeticmetric.OrganizationSite{} diff --git a/backend/pkg/service/site/main_test.go b/backend/pkg/service/site/main_test.go index 598d8d71..4040e152 100644 --- a/backend/pkg/service/site/main_test.go +++ b/backend/pkg/service/site/main_test.go @@ -7,7 +7,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" "github.com/jinzhu/now" "github.com/stretchr/testify/assert" - postgres2 "gorm.io/driver/postgres" + "github.com/stretchr/testify/mock" + gormpostgres "gorm.io/driver/postgres" "gorm.io/gorm" "github.com/th0th/poeticmetric/backend/pkg/poeticmetric" @@ -16,6 +17,7 @@ import ( func TestNew(t *testing.T) { postgres := &gorm.DB{} + mockValidationService := &poeticmetric.ValidationServiceMock{} type args struct { params NewParams @@ -29,11 +31,13 @@ func TestNew(t *testing.T) { name: "successful", args: args{ params: NewParams{ - Postgres: postgres, + Postgres: postgres, + ValidationService: mockValidationService, }, }, want: &service{ - postgres: postgres, + postgres: postgres, + validationService: mockValidationService, }, }, } @@ -45,7 +49,104 @@ func TestNew(t *testing.T) { } } -func Test_service_ListOrganizationSites(t *testing.T) { +func Test_service_Create(t *testing.T) { + db, sqlMock, err := sqlmock.New( + sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual), + sqlmock.ValueConverterOption(sqlmockhelper.CustomConverter{}), + ) + if err != nil { + t.Fatal(err) + } + postgres, err := gorm.Open(gormpostgres.New(gormpostgres.Config{Conn: db}), &gorm.Config{}) + if err != nil { + t.Fatal(err) + } + + mockValidationService := &poeticmetric.ValidationServiceMock{} + + // language=postgresql + insertQuery := `INSERT INTO "sites" ("created_at","domain","google_search_console_site_url","has_events","is_public","name","organization_id","safe_query_parameters","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9) RETURNING "id"` + + type fields struct { + postgres *gorm.DB + validationService poeticmetric.ValidationService + } + type args struct { + ctx context.Context + organizationID uint + params *poeticmetric.CreateSiteParams + } + tests := []struct { + name string + fields fields + args args + setup func() + want *poeticmetric.OrganizationSite + wantErr assert.ErrorAssertionFunc + }{ + { + name: "success", + fields: fields{ + postgres: postgres, + validationService: mockValidationService, + }, + args: args{ + ctx: context.Background(), + organizationID: 1, + params: &poeticmetric.CreateSiteParams{ + Domain: poeticmetric.Pointer("www.domain.tld"), + IsPublic: poeticmetric.Pointer(true), + Name: poeticmetric.Pointer("random name"), + SafeQueryParameters: []string{}, + }, + }, + setup: func() { + mockValidationService.On("CreateSiteParams", mock.Anything, mock.Anything).Return(nil) + + sqlMock.ExpectBegin() + sqlMock.ExpectQuery(insertQuery). + WithArgs(sqlmock.AnyArg(), "www.domain.tld", sqlmock.AnyArg(), false, true, "random name", uint(1), sqlmock.AnyArg(), sqlmock.AnyArg()). + WillReturnRows(sqlMock.NewRows([]string{"id"}).AddRow(1)) + sqlMock.ExpectCommit() + }, + want: &poeticmetric.OrganizationSite{ + Domain: "www.domain.tld", + GoogleSearchConsoleSiteUrl: nil, + HasEvents: false, + ID: 1, + IsPublic: true, + Name: "random name", + SafeQueryParameters: []string{}, + }, + wantErr: assert.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := &service{ + postgres: tt.fields.postgres, + validationService: tt.fields.validationService, + } + + tt.setup() + + got, gotErr := s.Create(tt.args.ctx, tt.args.organizationID, tt.args.params) + tt.wantErr(t, gotErr) + + assert.Equal(t, tt.want.Domain, got.Domain) + assert.Equal(t, tt.want.GoogleSearchConsoleSiteUrl, got.GoogleSearchConsoleSiteUrl) + assert.Equal(t, tt.want.HasEvents, got.HasEvents) + assert.Equal(t, tt.want.ID, got.ID) + assert.Equal(t, tt.want.IsPublic, got.IsPublic) + assert.Equal(t, tt.want.Name, got.Name) + assert.Equal(t, tt.want.SafeQueryParameters, got.SafeQueryParameters) + + assert.NoError(t, sqlMock.ExpectationsWereMet()) + }) + } +} + +func Test_service_List(t *testing.T) { db, sqlMock, err := sqlmock.New( sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual), sqlmock.ValueConverterOption(sqlmockhelper.CustomConverter{}), @@ -54,7 +155,7 @@ func Test_service_ListOrganizationSites(t *testing.T) { t.Fatal(err) } - postgres, err := gorm.Open(postgres2.New(postgres2.Config{Conn: db}), &gorm.Config{}) + postgres, err := gorm.Open(gormpostgres.New(gormpostgres.Config{Conn: db}), &gorm.Config{}) if err != nil { t.Fatal(err) } @@ -138,7 +239,7 @@ func Test_service_ListOrganizationSites(t *testing.T) { tt.setup() - got, err2 := s.ListOrganizationSites(tt.args.ctx, tt.args.organizationID) + got, err2 := s.List(tt.args.ctx, tt.args.organizationID) tt.wantErr(t, err2) assert.Equal(t, tt.want, got) assert.NoError(t, sqlMock.ExpectationsWereMet()) diff --git a/backend/pkg/service/validation/main.go b/backend/pkg/service/validation/main.go index b2e70ccf..3190971c 100644 --- a/backend/pkg/service/validation/main.go +++ b/backend/pkg/service/validation/main.go @@ -7,30 +7,100 @@ import ( v "github.com/RussellLuo/validating/v3" "github.com/RussellLuo/vext" + "golang.org/x/oauth2" + "google.golang.org/api/option" + "google.golang.org/api/searchconsole/v1" "gorm.io/gorm" "github.com/th0th/poeticmetric/backend/pkg/poeticmetric" ) type NewParams struct { - Postgres *gorm.DB + EnvService poeticmetric.EnvService + Postgres *gorm.DB } type service struct { - postgres *gorm.DB + envService poeticmetric.EnvService + postgres *gorm.DB } func New(params NewParams) poeticmetric.ValidationService { return &service{ - postgres: params.Postgres, + envService: params.EnvService, + postgres: params.Postgres, } } +func (s *service) CreateSiteParams(ctx context.Context, organizationID uint, params *poeticmetric.CreateSiteParams) error { + errs := []error{} + + validationErrs := v.Validate(v.Schema{ + v.F("domain", params.Domain): v.All( + v.Nonzero[*string]().Msg("This field is required."), + + v.Nested(func(x *string) v.Validator { + return v.Value(*x, vext.DNSName().Msg("Please provide a valid domain.")) + }), + + v.Is(func(x *string) bool { + isOk, err := s.uniqueSiteDomain(ctx, *x, nil) + if err != nil { + errs = append(errs, err) + } + + return isOk + }).Msg("This domain is already in use."), + ), + + v.F("googleSearchConsoleSiteURL", params.GoogleSearchConsoleSiteURL): v.Any( + v.Zero[*string](), + + v.All( + v.Is(func(x *string) bool { + isOk, err := s.googleSearchConsoleSiteURL(ctx, organizationID, *x) + if err != nil { + errs = append(errs, err) + } + + return isOk + }), + ), + ), + + v.F("isPublic", params.IsPublic): v.All( + v.Nonzero[*bool]().Msg("This field is required."), + ), + + v.F("name", params.Name): v.All( + v.Nonzero[*string]().Msg("This field is required."), + + v.Nested(func(x *string) v.Validator { + return v.Value(*x, v.LenString(poeticmetric.SiteNameMinLength, poeticmetric.SiteNameMaxLength).Msg(fmt.Sprintf( + "The site name must be between %d and %d characters long.", + poeticmetric.SiteNameMinLength, + poeticmetric.SiteNameMaxLength, + ))) + }), + ), + }) + + if len(errs) > 0 { + return errors.Join(errs...) + } + + if len(validationErrs) > 0 { + return validationErrs + } + + return nil +} + func (s *service) Postgres() *gorm.DB { return s.postgres } -func (s *service) AuthenticationResetUserPasswordParams(ctx context.Context, params *poeticmetric.AuthenticationResetUserPasswordParams) error { +func (s *service) ResetUserPasswordParams(ctx context.Context, params *poeticmetric.ResetUserPasswordParams) error { errs := []error{} validationErrs := v.Validate(v.Schema{ @@ -38,7 +108,7 @@ func (s *service) AuthenticationResetUserPasswordParams(ctx context.Context, par v.Nonzero[*string]().Msg("This field is required."), v.Is(func(x *string) bool { - isValid, err := s.validateUserPasswordResetToken(ctx, *x) + isValid, err := s.userPasswordResetToken(ctx, *x) if err != nil { errs = append(errs, err) } @@ -77,7 +147,7 @@ func (s *service) AuthenticationResetUserPasswordParams(ctx context.Context, par return nil } -func (s *service) AuthenticationSendUserPasswordRecoveryEmailParams(ctx context.Context, params *poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams) error { +func (s *service) SendUserPasswordRecoveryEmailParams(ctx context.Context, params *poeticmetric.SendUserPasswordRecoveryEmailParams) error { validationErrs := v.Validate(v.Schema{ v.F("email", params.Email): v.All( v.Nonzero[*string]().Msg("This field is required."), @@ -95,7 +165,64 @@ func (s *service) AuthenticationSendUserPasswordRecoveryEmailParams(ctx context. return nil } -func (s *service) validateUserPasswordResetToken(ctx context.Context, token string) (bool, error) { +func (s *service) googleSearchConsoleSiteURL(ctx context.Context, organizationID uint, siteURL string) (bool, error) { + postgres := poeticmetric.ServicePostgres(ctx, s) + + organization := poeticmetric.Organization{} + err := postgres.Select("GoogleOauthRefreshToken").First(&organization, poeticmetric.Organization{ID: organizationID}, "ID").Error + if err != nil { + return false, err + } + + if organization.GoogleOauthRefreshToken == nil { + return false, poeticmetric.ErrNoOrganizationGoogleOauthRefreshToken + } + + oAuthConfig, err := s.envService.GoogleOAuthConfig() + if err != nil { + return false, err + } + + searchConsoleService, err := searchconsole.NewService( + ctx, + option.WithTokenSource(oAuthConfig.TokenSource(ctx, &oauth2.Token{RefreshToken: *organization.GoogleOauthRefreshToken})), + ) + if err != nil { + return false, err + } + + site, err := searchConsoleService.Sites.Get(siteURL).Do() + if err != nil { + return false, err + } + + if site.SiteUrl != siteURL { + return false, nil + } + + return true, nil +} + +func (s *service) uniqueSiteDomain(ctx context.Context, domain string, siteID *uint) (bool, error) { + postgres := poeticmetric.ServicePostgres(ctx, s) + + q := postgres.Session(&gorm.Session{}) + if siteID != nil { + q = q.Not(poeticmetric.Site{ID: *siteID}) + } + err := q.First(&poeticmetric.Site{}, poeticmetric.Site{Domain: domain}).Error + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return true, nil + } + + return false, err + } + + return false, nil +} + +func (s *service) userPasswordResetToken(ctx context.Context, token string) (bool, error) { postgres := poeticmetric.ServicePostgres(ctx, s) err := postgres.Select("PasswordResetToken").First(&poeticmetric.User{}, poeticmetric.User{PasswordResetToken: &token}).Error diff --git a/backend/pkg/service/validation/main_test.go b/backend/pkg/service/validation/main_test.go index 84ec4962..43afeb4a 100644 --- a/backend/pkg/service/validation/main_test.go +++ b/backend/pkg/service/validation/main_test.go @@ -13,7 +13,7 @@ import ( "github.com/th0th/poeticmetric/backend/pkg/poeticmetric" ) -func Test_service_AuthenticationResetUserPasswordParams(t *testing.T) { +func Test_service_ResetUserPasswordParams(t *testing.T) { db, sqlMock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual)) assert.NoError(t, err) @@ -28,7 +28,7 @@ func Test_service_AuthenticationResetUserPasswordParams(t *testing.T) { } type args struct { ctx context.Context - params *poeticmetric.AuthenticationResetUserPasswordParams + params *poeticmetric.ResetUserPasswordParams } tests := []struct { name string @@ -44,7 +44,7 @@ func Test_service_AuthenticationResetUserPasswordParams(t *testing.T) { }, args: args{ ctx: context.Background(), - params: &poeticmetric.AuthenticationResetUserPasswordParams{ + params: &poeticmetric.ResetUserPasswordParams{ PasswordResetToken: poeticmetric.Pointer("token"), UserPassword: poeticmetric.Pointer("password"), UserPassword2: poeticmetric.Pointer("password"), @@ -65,7 +65,7 @@ func Test_service_AuthenticationResetUserPasswordParams(t *testing.T) { }, args: args{ ctx: context.Background(), - params: &poeticmetric.AuthenticationResetUserPasswordParams{ + params: &poeticmetric.ResetUserPasswordParams{ PasswordResetToken: poeticmetric.Pointer("token"), UserPassword: poeticmetric.Pointer("pass"), UserPassword2: poeticmetric.Pointer("pass2"), @@ -98,19 +98,19 @@ func Test_service_AuthenticationResetUserPasswordParams(t *testing.T) { tt.setup() - err = s.AuthenticationResetUserPasswordParams(tt.args.ctx, tt.args.params) + err = s.ResetUserPasswordParams(tt.args.ctx, tt.args.params) tt.wantErr(t, err) }) } } -func Test_service_AuthenticationSendUserPasswordRecoveryEmail(t *testing.T) { +func Test_service_SendUserPasswordRecoveryEmail(t *testing.T) { type fields struct { - postgres *gorm.DB + postgres *gorm.DB } type args struct { ctx context.Context - params *poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams + params *poeticmetric.SendUserPasswordRecoveryEmailParams } tests := []struct { name string @@ -122,7 +122,7 @@ func Test_service_AuthenticationSendUserPasswordRecoveryEmail(t *testing.T) { name: "successful", args: args{ ctx: context.Background(), - params: &poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams{ + params: &poeticmetric.SendUserPasswordRecoveryEmailParams{ Email: poeticmetric.Pointer("user@domain.tld"), }, }, @@ -132,7 +132,7 @@ func Test_service_AuthenticationSendUserPasswordRecoveryEmail(t *testing.T) { name: "invalid e-mail", args: args{ ctx: context.Background(), - params: &poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams{ + params: &poeticmetric.SendUserPasswordRecoveryEmailParams{ Email: poeticmetric.Pointer("invalid-email"), }, }, @@ -151,8 +151,126 @@ func Test_service_AuthenticationSendUserPasswordRecoveryEmail(t *testing.T) { postgres: tt.fields.postgres, } - gotErr := s.AuthenticationSendUserPasswordRecoveryEmailParams(tt.args.ctx, tt.args.params) + gotErr := s.SendUserPasswordRecoveryEmailParams(tt.args.ctx, tt.args.params) + tt.wantErr(t, gotErr) + }) + } +} + +func Test_service_uniqueSiteDomain(t *testing.T) { + db, sqlMock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual)) + assert.NoError(t, err) + + postgres, err := gorm.Open(postgres2.New(postgres2.Config{Conn: db}), &gorm.Config{}) + assert.NoError(t, err) + + // language=postgresql + selectQuery := `SELECT * FROM "sites" WHERE "sites"."domain" = $1 ORDER BY "sites"."id" LIMIT $2` + + // language=postgresql + selectWithIdQuery := `SELECT * FROM "sites" WHERE "sites"."id" <> $1 AND "sites"."domain" = $2 ORDER BY "sites"."id" LIMIT $3` + + type fields struct { + postgres *gorm.DB + } + type args struct { + ctx context.Context + domain string + siteID *uint + } + tests := []struct { + name string + fields fields + args args + setup func() + want bool + wantErr assert.ErrorAssertionFunc + }{ + { + name: "valid - nil siteID", + fields: fields{ + postgres: postgres, + }, + args: args{ + ctx: context.Background(), + domain: "www.domain.tld", + siteID: nil, + }, + setup: func() { + sqlMock.ExpectQuery(selectQuery).WithArgs("www.domain.tld", 1).WillReturnRows(sqlmock.NewRows([]string{})) + }, + want: true, + wantErr: assert.NoError, + }, + { + name: "valid", + fields: fields{ + postgres: postgres, + }, + args: args{ + ctx: context.Background(), + domain: "www.domain.tld", + siteID: poeticmetric.Pointer(uint(1)), + }, + setup: func() { + sqlMock. + ExpectQuery(selectWithIdQuery). + WithArgs(1, "www.domain.tld", 1). + WillReturnRows(sqlmock.NewRows([]string{})) + }, + want: true, + wantErr: assert.NoError, + }, + { + name: "invalid - nil siteID", + fields: fields{ + postgres: postgres, + }, + args: args{ + ctx: context.Background(), + domain: "www.domain.tld", + siteID: nil, + }, + setup: func() { + sqlMock. + ExpectQuery(selectQuery). + WithArgs("www.domain.tld", 1). + WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1)) + }, + want: false, + wantErr: assert.NoError, + }, + { + name: "invalid", + fields: fields{ + postgres: postgres, + }, + args: args{ + ctx: context.Background(), + domain: "www.domain.tld", + siteID: poeticmetric.Pointer(uint(1)), + }, + setup: func() { + sqlMock. + ExpectQuery(selectWithIdQuery). + WithArgs(1, "www.domain.tld", 1). + WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1)) + }, + want: false, + wantErr: assert.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := &service{ + postgres: tt.fields.postgres, + } + + tt.setup() + + got, gotErr := s.uniqueSiteDomain(tt.args.ctx, tt.args.domain, tt.args.siteID) tt.wantErr(t, gotErr) + assert.Equal(t, tt.want, got) }) } } From 0d727ad4d2a298a01043a339443c2a73ab697087 Mon Sep 17 00:00:00 2001 From: Gokhan Sari Date: Tue, 19 Nov 2024 16:34:18 +0300 Subject: [PATCH 2/8] Update go modules --- backend/go.mod | 27 +++++++++---------- backend/go.sum | 73 ++++++++++++++++++++------------------------------ 2 files changed, 42 insertions(+), 58 deletions(-) diff --git a/backend/go.mod b/backend/go.mod index a1936747..40d1ab1e 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -23,21 +23,23 @@ require ( github.com/swaggo/swag v1.16.4 github.com/ulule/limiter/v3 v3.11.2 golang.org/x/crypto v0.29.0 - google.golang.org/api v0.169.0 + golang.org/x/oauth2 v0.24.0 + google.golang.org/api v0.206.0 gorm.io/driver/clickhouse v0.6.1 gorm.io/driver/postgres v1.5.9 gorm.io/gorm v1.25.12 ) require ( - cloud.google.com/go/compute v1.25.1 // indirect - cloud.google.com/go/compute/metadata v0.2.3 // indirect + cloud.google.com/go/auth v0.10.2 // indirect + cloud.google.com/go/auth/oauth2adapt v0.2.5 // indirect + cloud.google.com/go/compute/metadata v0.5.2 // indirect github.com/ClickHouse/ch-go v0.61.5 // indirect github.com/ClickHouse/clickhouse-go/v2 v2.23.2 // indirect github.com/KyleBanks/depth v1.2.1 // indirect github.com/andybalholm/brotli v1.1.0 // indirect github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/felixge/httpsnoop v1.0.4 // indirect @@ -50,10 +52,9 @@ require ( github.com/go-openapi/spec v0.20.6 // indirect github.com/go-openapi/swag v0.19.15 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/protobuf v1.5.4 // indirect - github.com/google/s2a-go v0.1.7 // indirect - github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect - github.com/googleapis/gax-go/v2 v2.12.2 // indirect + github.com/google/s2a-go v0.1.8 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect + github.com/googleapis/gax-go/v2 v2.14.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-version v1.6.0 // indirect @@ -85,16 +86,14 @@ require ( go.opentelemetry.io/otel/trace v1.29.0 // indirect go.uber.org/atomic v1.11.0 // indirect golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect - golang.org/x/net v0.29.0 // indirect - golang.org/x/oauth2 v0.18.0 // indirect + golang.org/x/net v0.31.0 // indirect golang.org/x/sync v0.9.0 // indirect golang.org/x/sys v0.27.0 // indirect golang.org/x/text v0.20.0 // indirect golang.org/x/tools v0.24.0 // indirect - google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect - google.golang.org/grpc v1.64.1 // indirect - google.golang.org/protobuf v1.34.2 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect + google.golang.org/grpc v1.67.1 // indirect + google.golang.org/protobuf v1.35.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/backend/go.sum b/backend/go.sum index e7cac70e..5b1749ec 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -1,8 +1,10 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go/compute v1.25.1 h1:ZRpHJedLtTpKgr3RV1Fx23NuaAEN1Zfx9hw1u4aJdjU= -cloud.google.com/go/compute v1.25.1/go.mod h1:oopOIR53ly6viBYxaDhBfJwzUAxf1zE//uf3IB011ls= -cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= -cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= +cloud.google.com/go/auth v0.10.2 h1:oKF7rgBfSHdp/kuhXtqU/tNDr0mZqhYbEh+6SiqzkKo= +cloud.google.com/go/auth v0.10.2/go.mod h1:xxA5AqpDrvS+Gkmo9RqrGGRh6WSNKKOXhY3zNOr38tI= +cloud.google.com/go/auth/oauth2adapt v0.2.5 h1:2p29+dePqsCHPP1bqDJcKj4qxRyYCcbzKpFyKGt3MTk= +cloud.google.com/go/auth/oauth2adapt v0.2.5/go.mod h1:AlmsELtlEBnaNTL7jCj8VQFLy6mbZv0s4Q7NGBeQ5E8= +cloud.google.com/go/compute/metadata v0.5.2 h1:UxK4uu/Tn+I3p2dYWTfiX4wva7aYlKixAHn3fyqngqo= +cloud.google.com/go/compute/metadata v0.5.2/go.mod h1:C66sj2AluDcIqakBq/M8lw8/ybHgOZqin2obFxa/E5k= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -35,8 +37,8 @@ github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0 github.com/caarlos0/env/v11 v11.2.2 h1:95fApNrUyueipoZN/EhA8mMxiNxrBwDa+oAZrMWl3Kg= github.com/caarlos0/env/v11 v11.2.2/go.mod h1:JBfcdeQiBoI3Zh1QRAWfe+tpiNTmDtcCj/hHHHMx0vc= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 h1:F1EaeKL/ta07PY/k9Os/UFtwERei2/XzGemhpGnBKNg= github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80= @@ -107,9 +109,6 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= -github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -121,15 +120,15 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= -github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= +github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM= +github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs= -github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= -github.com/googleapis/gax-go/v2 v2.12.2 h1:mhN09QQW1jEWeMF74zGR81R30z4VJzjZsfkUhuHF+DA= -github.com/googleapis/gax-go/v2 v2.12.2/go.mod h1:61M8vcyyXR2kqKFxKrfA22jaA8JGF7Dc8App1U3H6jc= +github.com/googleapis/enterprise-certificate-proxy v0.3.4 h1:XYIDZApgAnrN1c855gTgghdIA6Stxb52D5RnLI1SLyw= +github.com/googleapis/enterprise-certificate-proxy v0.3.4/go.mod h1:YKe7cfqYXjKGpGvmSg28/fFvhNzinZQm8DGnaburhGA= +github.com/googleapis/gax-go/v2 v2.14.0 h1:f+jMrjBPl+DL9nI4IQzLUxMq7XrAqFYB7hBPqMNIe8o= +github.com/googleapis/gax-go/v2 v2.14.0/go.mod h1:lhBCnjdLrWRaPvLWhmc8IS24m9mr07qSYnHncrgo+zk= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -244,7 +243,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.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= @@ -261,7 +259,6 @@ go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= @@ -273,7 +270,6 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 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.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -285,21 +281,18 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/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-20201110031124-69a78807bb2b/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-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= -golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= +golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= -golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= +golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE= +golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -309,20 +302,16 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -333,34 +322,31 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.169.0 h1:QwWPy71FgMWqJN/l6jVlFHUa29a7dcUy02I8o799nPY= -google.golang.org/api v0.169.0/go.mod h1:gpNOiMA2tZ4mf5R9Iwf4rK/Dcz0fbdIgWYWVoxmsyLg= +google.golang.org/api v0.206.0 h1:A27GClesCSheW5P2BymVHjpEeQ2XHH8DI8Srs2HI2L8= +google.golang.org/api v0.206.0/go.mod h1:BtB8bfjTYIrai3d8UyvPmV9REGgox7coh+ZRwm0b+W8= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= -google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 h1:9+tzLLstTlPTRyJTh+ah5wIMsBW5c4tQwGTN3thOW9Y= -google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 h1:W5Xj/70xIA4x60O/IFyXivR5MGqblAb8R3w26pnD6No= -google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8/go.mod h1:vPrPUTsDCYxXWjP7clS81mZ6/803D8K4iM9Ma27VKas= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 h1:mxSlqyb8ZAHsYDCfiXN1EDdNTdvjUJSLY+OnAUtYNYA= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM= +google.golang.org/genproto v0.0.0-20241104194629-dd2ea8efbc28 h1:KJjNNclfpIkVqrZlTWcgOOaVQ00LdBnoEaRfkUx760s= +google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 h1:M0KvPgPmDZHPlbRbaNU1APr28TvwvvdUPlSv7PUvy8g= +google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:dguCy7UOdZhTvLzDyt15+rOrawrpM4q7DD9dQ1P11P4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 h1:XVhgTWWV3kGQlwJHR3upFWZeTsei6Oks1apkZSeonIE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= -google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -371,10 +357,9 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From b6ef21794e6522ae5dbfbf87ebc15bd917225698 Mon Sep 17 00:00:00 2001 From: Gokhan Sari Date: Tue, 19 Nov 2024 16:35:25 +0300 Subject: [PATCH 3/8] Update main.go --- backend/pkg/service/site/main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/pkg/service/site/main.go b/backend/pkg/service/site/main.go index 40f893b1..12e58e43 100644 --- a/backend/pkg/service/site/main.go +++ b/backend/pkg/service/site/main.go @@ -34,11 +34,12 @@ func (s *service) Create(ctx context.Context, organizationID uint, params *poeti postgres := poeticmetric.ServicePostgres(ctx, s) site := &poeticmetric.Site{ - Domain: *params.Domain, - IsPublic: *params.IsPublic, - Name: *params.Name, - SafeQueryParameters: params.SafeQueryParameters, - OrganizationID: organizationID, + Domain: *params.Domain, + GoogleSearchConsoleSiteUrl: params.GoogleSearchConsoleSiteURL, + IsPublic: *params.IsPublic, + Name: *params.Name, + SafeQueryParameters: params.SafeQueryParameters, + OrganizationID: organizationID, } err = postgres.Create(site).Error From 68a1ddedc448da744b035a649a0611af6dcab7a0 Mon Sep 17 00:00:00 2001 From: Gokhan Sari Date: Tue, 19 Nov 2024 16:27:30 +0300 Subject: [PATCH 4/8] Add site creation endpoint --- .idea/dataSources.xml | 11 +- backend/cmd/rest-api/main.go | 8 +- backend/go.mod | 20 +++ backend/go.sum | 120 ++++++++++++++- .../poeticmetric/authentication_service.go | 8 +- backend/pkg/poeticmetric/env_service.go | 6 + backend/pkg/poeticmetric/env_service_mock.go | 74 +++++++++ backend/pkg/poeticmetric/errors.go | 3 +- backend/pkg/poeticmetric/models.go | 5 + backend/pkg/poeticmetric/site_service.go | 13 +- .../pkg/poeticmetric/validation_service.go | 6 +- .../poeticmetric/validation_service_mock.go | 14 +- backend/pkg/restapi/docs/docs.go | 108 ++++++++++---- backend/pkg/restapi/docs/swagger.json | 108 ++++++++++---- backend/pkg/restapi/docs/swagger.yaml | 72 ++++++--- .../restapi/handler/authentication/main.go | 12 +- backend/pkg/restapi/handler/sites/main.go | 31 +++- backend/pkg/service/authentication/main.go | 8 +- .../pkg/service/authentication/main_test.go | 20 +-- backend/pkg/service/env/main.go | 21 ++- backend/pkg/service/site/main.go | 45 +++++- backend/pkg/service/site/main_test.go | 113 +++++++++++++- backend/pkg/service/validation/main.go | 141 +++++++++++++++++- backend/pkg/service/validation/main_test.go | 140 +++++++++++++++-- 24 files changed, 958 insertions(+), 149 deletions(-) create mode 100644 backend/pkg/poeticmetric/env_service_mock.go diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index fd412e99..f723246e 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -39,13 +39,10 @@ org.postgresql.Driver jdbc:postgresql://localhost:15432/poeticmetric - - - - - - - + + + + $ProjectFileDir$ diff --git a/backend/cmd/rest-api/main.go b/backend/cmd/rest-api/main.go index b11f9b09..89666d3d 100644 --- a/backend/cmd/rest-api/main.go +++ b/backend/cmd/rest-api/main.go @@ -73,7 +73,8 @@ func main() { } validationService := validation.New(validation.NewParams{ - Postgres: postgres, + EnvService: envService, + Postgres: postgres, }) emailService, err := email.New(email.NewParams{ @@ -96,7 +97,8 @@ func main() { }) siteService := site.New(site.NewParams{ - Postgres: postgres, + Postgres: postgres, + ValidationService: validationService, }) responder := restapiresponder.New(restapiresponder.NewParams{ @@ -134,6 +136,7 @@ func main() { sensitiveRateLimit := alice.New(middleware.SensitiveRateLimit(responder, limiterStore)) permissionBasicAuthenticated := alice.New(middleware.PermissionBasicAuthenticated(responder)) permissionUserAccessTokenAuthenticated := alice.New(middleware.PermissionUserAccessTokenAuthenticated(responder)) + permissionWrite := alice.New(middleware.PermissionOrganizationOwner(responder)) // handlers: authentication mux.Handle("POST /authentication/user-access-tokens", sensitiveRateLimit.Extend(permissionBasicAuthenticated).ThenFunc(authenticationHandler.CreateUserAccessToken)) @@ -153,6 +156,7 @@ func main() { mux.HandleFunc("/{$}", rootHandler.Index()) // handlers: sites + mux.Handle("POST /sites", permissionWrite.ThenFunc(sitesHandler.Create)) mux.Handle("GET /sites", permissionUserAccessTokenAuthenticated.ThenFunc(sitesHandler.List)) httpServer := http.Server{ diff --git a/backend/go.mod b/backend/go.mod index 18c7dedc..a1936747 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -23,12 +23,15 @@ require ( github.com/swaggo/swag v1.16.4 github.com/ulule/limiter/v3 v3.11.2 golang.org/x/crypto v0.29.0 + google.golang.org/api v0.169.0 gorm.io/driver/clickhouse v0.6.1 gorm.io/driver/postgres v1.5.9 gorm.io/gorm v1.25.12 ) require ( + cloud.google.com/go/compute v1.25.1 // indirect + cloud.google.com/go/compute/metadata v0.2.3 // indirect github.com/ClickHouse/ch-go v0.61.5 // indirect github.com/ClickHouse/clickhouse-go/v2 v2.23.2 // indirect github.com/KyleBanks/depth v1.2.1 // indirect @@ -37,12 +40,20 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-faster/city v1.0.1 // indirect github.com/go-faster/errors v0.7.1 // indirect + github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.20.0 // indirect github.com/go-openapi/spec v0.20.6 // indirect github.com/go-openapi/swag v0.19.15 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/google/s2a-go v0.1.7 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect + github.com/googleapis/gax-go/v2 v2.12.2 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-version v1.6.0 // indirect @@ -67,14 +78,23 @@ require ( github.com/stretchr/objx v0.5.2 // indirect github.com/swaggo/files/v2 v2.0.0 // indirect github.com/th0th/disposableemail v0.0.2-0.20241107110532-1e027547679f // indirect + go.opencensus.io v0.24.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect go.opentelemetry.io/otel v1.29.0 // indirect + go.opentelemetry.io/otel/metric v1.29.0 // indirect go.opentelemetry.io/otel/trace v1.29.0 // indirect go.uber.org/atomic v1.11.0 // indirect golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect + golang.org/x/net v0.29.0 // indirect + golang.org/x/oauth2 v0.18.0 // indirect golang.org/x/sync v0.9.0 // indirect golang.org/x/sys v0.27.0 // indirect golang.org/x/text v0.20.0 // indirect golang.org/x/tools v0.24.0 // indirect + google.golang.org/appengine v1.6.8 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect + google.golang.org/grpc v1.64.1 // indirect + google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/backend/go.sum b/backend/go.sum index c6755391..e7cac70e 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -1,5 +1,11 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go/compute v1.25.1 h1:ZRpHJedLtTpKgr3RV1Fx23NuaAEN1Zfx9hw1u4aJdjU= +cloud.google.com/go/compute v1.25.1/go.mod h1:oopOIR53ly6viBYxaDhBfJwzUAxf1zE//uf3IB011ls= +cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= +cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/ClickHouse/ch-go v0.61.5 h1:zwR8QbYI0tsMiEcze/uIMK+Tz1D3XZXLdNrlaOpeEI4= github.com/ClickHouse/ch-go v0.61.5/go.mod h1:s1LJW/F/LcFs5HJnuogFMta50kKDO0lf9zzfrbl0RQg= github.com/ClickHouse/clickhouse-go v1.5.4 h1:cKjXeYLNWVJIx2J1K6H2CqyRmfwVJVY1OV1coaaFcI0= @@ -28,10 +34,13 @@ github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/caarlos0/env/v11 v11.2.2 h1:95fApNrUyueipoZN/EhA8mMxiNxrBwDa+oAZrMWl3Kg= github.com/caarlos0/env/v11 v11.2.2/go.mod h1:JBfcdeQiBoI3Zh1QRAWfe+tpiNTmDtcCj/hHHHMx0vc= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 h1:F1EaeKL/ta07PY/k9Os/UFtwERei2/XzGemhpGnBKNg= github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -51,6 +60,10 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk= @@ -59,6 +72,7 @@ github.com/go-faster/city v1.0.1 h1:4WAxSZ3V2Ws4QRDrscLEDcibJY8uf41H6AhXDrNDcGw= github.com/go-faster/city v1.0.1/go.mod h1:jKcUJId49qdW3L1qKHH/3wPeUstCVpVSXTM6vO3VcTw= github.com/go-faster/errors v0.7.1 h1:MkJTnDoEdi9pDabt1dpWf7AA8/BaSYZqibYyhZ20AYg= github.com/go-faster/errors v0.7.1/go.mod h1:5ySTjWFiphBs07IKuiL69nxdfd5+fzh1u7FPGZP2quo= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= @@ -78,14 +92,44 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-migrate/migrate/v4 v4.18.1 h1:JML/k+t4tpHCpQTCAD62Nu43NUFzHY4CV3uAuvHGC+Y= github.com/golang-migrate/migrate/v4 v4.18.1/go.mod h1:HAX6m3sQgcdO81tdjn5exv20+3Kb13cmGli1hrD6hks= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.3/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.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= +github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs= +github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= +github.com/googleapis/gax-go/v2 v2.12.2 h1:mhN09QQW1jEWeMF74zGR81R30z4VJzjZsfkUhuHF+DA= +github.com/googleapis/gax-go/v2 v2.12.2/go.mod h1:61M8vcyyXR2kqKFxKrfA22jaA8JGF7Dc8App1U3H6jc= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -157,6 +201,7 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E= github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw= github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= @@ -170,11 +215,16 @@ github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/swaggo/files/v2 v2.0.0 h1:hmAt8Dkynw7Ssz46F6pn8ok6YmGZqHSVLZ+HQM7i0kw= @@ -194,8 +244,10 @@ 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.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= -go.opentelemetry.io/contrib v0.20.0 h1:ubFQUn0VCZ0gPwIoJfBJVpeBlyRMxu8Mm/huKWYd9p0= +go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= +go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8= go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= @@ -209,56 +261,120 @@ go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea h1:vLCWI/yYrdEHyN2JzIzPO3aaQJHQdp89IZBA/+azVC4= golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 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.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +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-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/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-20201110031124-69a78807bb2b/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-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= +golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.169.0 h1:QwWPy71FgMWqJN/l6jVlFHUa29a7dcUy02I8o799nPY= +google.golang.org/api v0.169.0/go.mod h1:gpNOiMA2tZ4mf5R9Iwf4rK/Dcz0fbdIgWYWVoxmsyLg= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= +google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 h1:9+tzLLstTlPTRyJTh+ah5wIMsBW5c4tQwGTN3thOW9Y= +google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 h1:W5Xj/70xIA4x60O/IFyXivR5MGqblAb8R3w26pnD6No= +google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8/go.mod h1:vPrPUTsDCYxXWjP7clS81mZ6/803D8K4iM9Ma27VKas= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 h1:mxSlqyb8ZAHsYDCfiXN1EDdNTdvjUJSLY+OnAUtYNYA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= +google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -277,3 +393,5 @@ gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8= gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/backend/pkg/poeticmetric/authentication_service.go b/backend/pkg/poeticmetric/authentication_service.go index 4f28cdea..5336b9cd 100644 --- a/backend/pkg/poeticmetric/authentication_service.go +++ b/backend/pkg/poeticmetric/authentication_service.go @@ -13,8 +13,8 @@ type AuthenticationService interface { ReadUserAccessToken(ctx context.Context, userAccessTokenID uint) (*AuthenticationUserAccessToken, error) ReadUserByEmailPassword(ctx context.Context, email string, password string) (*User, error) ReadUserByUserAccessToken(ctx context.Context, token string) (*User, *UserAccessToken, error) - ResetUserPassword(ctx context.Context, params *AuthenticationResetUserPasswordParams) error - SendUserPasswordRecoveryEmail(ctx context.Context, params *AuthenticationSendUserPasswordRecoveryEmailParams) error + ResetUserPassword(ctx context.Context, params *ResetUserPasswordParams) error + SendUserPasswordRecoveryEmail(ctx context.Context, params *SendUserPasswordRecoveryEmailParams) error ValidateUserPasswordResetToken(ctx context.Context, token string) (bool, error) } @@ -24,11 +24,11 @@ type AuthenticationUserAccessToken struct { Token string `json:"token"` } -type AuthenticationSendUserPasswordRecoveryEmailParams struct { +type SendUserPasswordRecoveryEmailParams struct { Email *string `json:"email"` } -type AuthenticationResetUserPasswordParams struct { +type ResetUserPasswordParams struct { PasswordResetToken *string UserPassword *string UserPassword2 *string diff --git a/backend/pkg/poeticmetric/env_service.go b/backend/pkg/poeticmetric/env_service.go index c18d4900..c9c23291 100644 --- a/backend/pkg/poeticmetric/env_service.go +++ b/backend/pkg/poeticmetric/env_service.go @@ -4,6 +4,7 @@ import ( "net/mail" "net/smtp" + "golang.org/x/oauth2" "gorm.io/gorm" ) @@ -12,6 +13,7 @@ type EnvService interface { ClickhouseDsn() string Debug() bool FrontendUrl(path string) string + GoogleOAuthConfig() (*oauth2.Config, error) GormConfig() *gorm.Config IsHosted() bool PostgresDatabase() string @@ -37,6 +39,10 @@ type EnvServiceVars struct { ClickhousePort int `env:"CLICKHOUSE_PORT,notEmpty,required"` ClickhouseUser string `env:"CLICKHOUSE_USER,notEmpty,required"` + // Google + GoogleClientID *string `env:"GOOGLE_CLIENT_ID"` + GoogleClientSecret *string `env:"GOOGLE_CLIENT_SECRET"` + // Postgres PostgresDatabase string `env:"POSTGRES_DATABASE,notEmpty,required"` PostgresHost string `env:"POSTGRES_HOST,notEmpty,required"` diff --git a/backend/pkg/poeticmetric/env_service_mock.go b/backend/pkg/poeticmetric/env_service_mock.go new file mode 100644 index 00000000..9b442e76 --- /dev/null +++ b/backend/pkg/poeticmetric/env_service_mock.go @@ -0,0 +1,74 @@ +package poeticmetric + +import ( + "net/smtp" + + "github.com/stretchr/testify/mock" + "golang.org/x/oauth2" + "gorm.io/gorm" +) + +type EnvServiceMock struct { + mock.Mock +} + +func (s *EnvServiceMock) ClickhouseDatabase() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) ClickhouseDsn() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) Debug() bool { + return s.Called().Bool(0) +} + +func (s *EnvServiceMock) FrontendUrl(path string) string { + return s.Called(path).String(0) +} + +func (s *EnvServiceMock) GoogleOAuthConfig() (*oauth2.Config, error) { + args := s.Called() + return args.Get(0).(*oauth2.Config), args.Error(1) +} + +func (s *EnvServiceMock) GormConfig() *gorm.Config { + return s.Called().Get(0).(*gorm.Config) +} + +func (s *EnvServiceMock) IsHosted() bool { + return s.Called().Bool(0) +} + +func (s *EnvServiceMock) PostgresDatabase() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) PostgresDsn() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) RedisAddr() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) RedisPassword() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) RestApiBasePath() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) SmtpAddr() string { + return s.Called().String(0) +} + +func (s *EnvServiceMock) SmtpAuth() smtp.Auth { + return s.Called().Get(0).(smtp.Auth) +} + +func (s *EnvServiceMock) SmtpFrom() string { + return s.Called().String(0) +} diff --git a/backend/pkg/poeticmetric/errors.go b/backend/pkg/poeticmetric/errors.go index 86e2fc62..8c442942 100644 --- a/backend/pkg/poeticmetric/errors.go +++ b/backend/pkg/poeticmetric/errors.go @@ -5,5 +5,6 @@ import ( ) var ( - ErrNotFound = errors.New("not found") + ErrNoOrganizationGoogleOauthRefreshToken = errors.New("organization doesn't have a google oauth refresh token") + ErrNotFound = errors.New("not found") ) diff --git a/backend/pkg/poeticmetric/models.go b/backend/pkg/poeticmetric/models.go index 59472762..f4ad9575 100644 --- a/backend/pkg/poeticmetric/models.go +++ b/backend/pkg/poeticmetric/models.go @@ -23,6 +23,11 @@ const ( OrganizationSubscriptionPeriodYear = "YEAR" ) +const ( + SiteNameMaxLength = 50 + SiteNameMinLength = 1 +) + const ( UserNameMaxLength = 70 UserNameMinLength = 1 diff --git a/backend/pkg/poeticmetric/site_service.go b/backend/pkg/poeticmetric/site_service.go index 1afb89ad..0708fe23 100644 --- a/backend/pkg/poeticmetric/site_service.go +++ b/backend/pkg/poeticmetric/site_service.go @@ -5,10 +5,18 @@ import ( "time" ) +type CreateSiteParams struct { + Domain *string `json:"domain"` + GoogleSearchConsoleSiteURL *string `json:"googleSearchConsoleSiteURL"` + IsPublic *bool `json:"isPublic"` + Name *string `json:"name"` + SafeQueryParameters []string `gorm:"serializer:json" json:"safeQueryParameters"` +} + type OrganizationSite struct { CreatedAt time.Time `json:"createdAt"` Domain string `json:"domain"` - GoogleSearchConsoleSiteUrl *string `json:"googleSearchConsoleSiteUrl"` + GoogleSearchConsoleSiteUrl *string `json:"googleSearchConsoleSiteURL"` HasEvents bool `json:"hasEvents"` ID uint `json:"ID"` IsPublic bool `json:"isPublic"` @@ -20,5 +28,6 @@ type OrganizationSite struct { type SiteService interface { ServiceWithPostgres - ListOrganizationSites(ctx context.Context, organizationID uint) ([]*OrganizationSite, error) + Create(ctx context.Context, organizationID uint, params *CreateSiteParams) (*OrganizationSite, error) + List(ctx context.Context, organizationID uint) ([]*OrganizationSite, error) } diff --git a/backend/pkg/poeticmetric/validation_service.go b/backend/pkg/poeticmetric/validation_service.go index 5f74ad29..1c207755 100644 --- a/backend/pkg/poeticmetric/validation_service.go +++ b/backend/pkg/poeticmetric/validation_service.go @@ -7,7 +7,7 @@ import ( type ValidationService interface { ServiceWithPostgres - AuthenticationResetUserPasswordParams(ctx context.Context, params *AuthenticationResetUserPasswordParams) error - AuthenticationSendUserPasswordRecoveryEmailParams(ctx context.Context, params *AuthenticationSendUserPasswordRecoveryEmailParams) error + CreateSiteParams(ctx context.Context, organizationID uint, params *CreateSiteParams) error + ResetUserPasswordParams(ctx context.Context, params *ResetUserPasswordParams) error + SendUserPasswordRecoveryEmailParams(ctx context.Context, params *SendUserPasswordRecoveryEmailParams) error } - diff --git a/backend/pkg/poeticmetric/validation_service_mock.go b/backend/pkg/poeticmetric/validation_service_mock.go index 09cbaa69..3ea5192a 100644 --- a/backend/pkg/poeticmetric/validation_service_mock.go +++ b/backend/pkg/poeticmetric/validation_service_mock.go @@ -7,18 +7,22 @@ import ( "gorm.io/gorm" ) -type MockValidationService struct { +type ValidationServiceMock struct { mock.Mock } -func (m *MockValidationService) Postgres() *gorm.DB { - return m.Called().Get(0).(*gorm.DB) +func (m *ValidationServiceMock) ResetUserPasswordParams(ctx context.Context, params *ResetUserPasswordParams) error { + return m.Called(ctx, params).Error(0) } -func (m *MockValidationService) AuthenticationResetUserPasswordParams(ctx context.Context, params *AuthenticationResetUserPasswordParams) error { +func (m *ValidationServiceMock) SendUserPasswordRecoveryEmailParams(ctx context.Context, params *SendUserPasswordRecoveryEmailParams) error { return m.Called(ctx, params).Error(0) } -func (m *MockValidationService) AuthenticationSendUserPasswordRecoveryEmailParams(ctx context.Context, params *AuthenticationSendUserPasswordRecoveryEmailParams) error { +func (m *ValidationServiceMock) CreateSiteParams(ctx context.Context, organizationID uint, params *CreateSiteParams) error { return m.Called(ctx, params).Error(0) } + +func (m *ValidationServiceMock) Postgres() *gorm.DB { + return m.Called().Get(0).(*gorm.DB) +} diff --git a/backend/pkg/restapi/docs/docs.go b/backend/pkg/restapi/docs/docs.go index 8bde4708..6335ad2b 100644 --- a/backend/pkg/restapi/docs/docs.go +++ b/backend/pkg/restapi/docs/docs.go @@ -30,7 +30,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/poeticmetric.AuthenticationResetUserPasswordParams" + "$ref": "#/definitions/poeticmetric.ResetUserPasswordParams" } } ], @@ -44,7 +44,7 @@ const docTemplate = `{ "422": { "description": "Unprocessable Entity", "schema": { - "$ref": "#/definitions/poeticmetric.AuthenticationResetUserPasswordParams" + "$ref": "#/definitions/poeticmetric.ResetUserPasswordParams" } } } @@ -64,7 +64,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams" + "$ref": "#/definitions/poeticmetric.SendUserPasswordRecoveryEmailParams" } } ], @@ -115,7 +115,7 @@ const docTemplate = `{ "tags": [ "authentication" ], - "summary": "Create user access token", + "summary": "Delete user access token", "responses": { "204": { "description": "No Content" @@ -195,32 +195,41 @@ const docTemplate = `{ } } } + }, + "post": { + "security": [ + { + "UserAccessTokenAuthentication": [] + } + ], + "description": "Create site.", + "tags": [ + "sites" + ], + "summary": "Create site", + "parameters": [ + { + "description": "Params", + "name": "params", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/poeticmetric.CreateSiteParams" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/poeticmetric.OrganizationSite" + } + } + } } } }, "definitions": { - "poeticmetric.AuthenticationResetUserPasswordParams": { - "type": "object", - "properties": { - "passwordResetToken": { - "type": "string" - }, - "userPassword": { - "type": "string" - }, - "userPassword2": { - "type": "string" - } - } - }, - "poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams": { - "type": "object", - "properties": { - "email": { - "type": "string" - } - } - }, "poeticmetric.AuthenticationUserAccessToken": { "type": "object", "properties": { @@ -258,6 +267,29 @@ const docTemplate = `{ } } }, + "poeticmetric.CreateSiteParams": { + "type": "object", + "properties": { + "domain": { + "type": "string" + }, + "googleSearchConsoleSiteURL": { + "type": "string" + }, + "isPublic": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "safeQueryParameters": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "poeticmetric.OrganizationSite": { "type": "object", "properties": { @@ -270,7 +302,7 @@ const docTemplate = `{ "domain": { "type": "string" }, - "googleSearchConsoleSiteUrl": { + "googleSearchConsoleSiteURL": { "type": "string" }, "hasEvents": { @@ -293,6 +325,28 @@ const docTemplate = `{ } } }, + "poeticmetric.ResetUserPasswordParams": { + "type": "object", + "properties": { + "passwordResetToken": { + "type": "string" + }, + "userPassword": { + "type": "string" + }, + "userPassword2": { + "type": "string" + } + } + }, + "poeticmetric.SendUserPasswordRecoveryEmailParams": { + "type": "object", + "properties": { + "email": { + "type": "string" + } + } + }, "responder.DetailResponse": { "type": "object", "properties": { diff --git a/backend/pkg/restapi/docs/swagger.json b/backend/pkg/restapi/docs/swagger.json index dce00fe8..fd36c197 100644 --- a/backend/pkg/restapi/docs/swagger.json +++ b/backend/pkg/restapi/docs/swagger.json @@ -22,7 +22,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/poeticmetric.AuthenticationResetUserPasswordParams" + "$ref": "#/definitions/poeticmetric.ResetUserPasswordParams" } } ], @@ -36,7 +36,7 @@ "422": { "description": "Unprocessable Entity", "schema": { - "$ref": "#/definitions/poeticmetric.AuthenticationResetUserPasswordParams" + "$ref": "#/definitions/poeticmetric.ResetUserPasswordParams" } } } @@ -56,7 +56,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams" + "$ref": "#/definitions/poeticmetric.SendUserPasswordRecoveryEmailParams" } } ], @@ -107,7 +107,7 @@ "tags": [ "authentication" ], - "summary": "Create user access token", + "summary": "Delete user access token", "responses": { "204": { "description": "No Content" @@ -187,32 +187,41 @@ } } } + }, + "post": { + "security": [ + { + "UserAccessTokenAuthentication": [] + } + ], + "description": "Create site.", + "tags": [ + "sites" + ], + "summary": "Create site", + "parameters": [ + { + "description": "Params", + "name": "params", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/poeticmetric.CreateSiteParams" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/poeticmetric.OrganizationSite" + } + } + } } } }, "definitions": { - "poeticmetric.AuthenticationResetUserPasswordParams": { - "type": "object", - "properties": { - "passwordResetToken": { - "type": "string" - }, - "userPassword": { - "type": "string" - }, - "userPassword2": { - "type": "string" - } - } - }, - "poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams": { - "type": "object", - "properties": { - "email": { - "type": "string" - } - } - }, "poeticmetric.AuthenticationUserAccessToken": { "type": "object", "properties": { @@ -250,6 +259,29 @@ } } }, + "poeticmetric.CreateSiteParams": { + "type": "object", + "properties": { + "domain": { + "type": "string" + }, + "googleSearchConsoleSiteURL": { + "type": "string" + }, + "isPublic": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "safeQueryParameters": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "poeticmetric.OrganizationSite": { "type": "object", "properties": { @@ -262,7 +294,7 @@ "domain": { "type": "string" }, - "googleSearchConsoleSiteUrl": { + "googleSearchConsoleSiteURL": { "type": "string" }, "hasEvents": { @@ -285,6 +317,28 @@ } } }, + "poeticmetric.ResetUserPasswordParams": { + "type": "object", + "properties": { + "passwordResetToken": { + "type": "string" + }, + "userPassword": { + "type": "string" + }, + "userPassword2": { + "type": "string" + } + } + }, + "poeticmetric.SendUserPasswordRecoveryEmailParams": { + "type": "object", + "properties": { + "email": { + "type": "string" + } + } + }, "responder.DetailResponse": { "type": "object", "properties": { diff --git a/backend/pkg/restapi/docs/swagger.yaml b/backend/pkg/restapi/docs/swagger.yaml index 54d8b045..ebbaafbf 100644 --- a/backend/pkg/restapi/docs/swagger.yaml +++ b/backend/pkg/restapi/docs/swagger.yaml @@ -1,18 +1,4 @@ definitions: - poeticmetric.AuthenticationResetUserPasswordParams: - properties: - passwordResetToken: - type: string - userPassword: - type: string - userPassword2: - type: string - type: object - poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams: - properties: - email: - type: string - type: object poeticmetric.AuthenticationUserAccessToken: properties: createdAt: @@ -37,6 +23,21 @@ definitions: userPassword2: type: string type: object + poeticmetric.CreateSiteParams: + properties: + domain: + type: string + googleSearchConsoleSiteURL: + type: string + isPublic: + type: boolean + name: + type: string + safeQueryParameters: + items: + type: string + type: array + type: object poeticmetric.OrganizationSite: properties: ID: @@ -45,7 +46,7 @@ definitions: type: string domain: type: string - googleSearchConsoleSiteUrl: + googleSearchConsoleSiteURL: type: string hasEvents: type: boolean @@ -60,6 +61,20 @@ definitions: updatedAt: type: string type: object + poeticmetric.ResetUserPasswordParams: + properties: + passwordResetToken: + type: string + userPassword: + type: string + userPassword2: + type: string + type: object + poeticmetric.SendUserPasswordRecoveryEmailParams: + properties: + email: + type: string + type: object responder.DetailResponse: properties: detail: @@ -83,7 +98,7 @@ paths: name: params required: true schema: - $ref: '#/definitions/poeticmetric.AuthenticationResetUserPasswordParams' + $ref: '#/definitions/poeticmetric.ResetUserPasswordParams' responses: "200": description: OK @@ -92,7 +107,7 @@ paths: "422": description: Unprocessable Entity schema: - $ref: '#/definitions/poeticmetric.AuthenticationResetUserPasswordParams' + $ref: '#/definitions/poeticmetric.ResetUserPasswordParams' summary: Reset user's password tags: - authentication @@ -105,7 +120,7 @@ paths: name: params required: true schema: - $ref: '#/definitions/poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams' + $ref: '#/definitions/poeticmetric.SendUserPasswordRecoveryEmailParams' responses: "201": description: Created @@ -126,7 +141,7 @@ paths: $ref: '#/definitions/responder.DetailResponse' security: - UserAccessTokenAuthentication: [] - summary: Create user access token + summary: Delete user access token tags: - authentication post: @@ -189,6 +204,25 @@ paths: summary: List sites tags: - sites + post: + description: Create site. + parameters: + - description: Params + in: body + name: params + required: true + schema: + $ref: '#/definitions/poeticmetric.CreateSiteParams' + responses: + "201": + description: Created + schema: + $ref: '#/definitions/poeticmetric.OrganizationSite' + security: + - UserAccessTokenAuthentication: [] + summary: Create site + tags: + - sites securityDefinitions: BasicAuthentication: type: basic diff --git a/backend/pkg/restapi/handler/authentication/main.go b/backend/pkg/restapi/handler/authentication/main.go index b0abb051..f5229321 100644 --- a/backend/pkg/restapi/handler/authentication/main.go +++ b/backend/pkg/restapi/handler/authentication/main.go @@ -53,7 +53,7 @@ func (h *Handler) CreateUserAccessToken(w http.ResponseWriter, r *http.Request) // @Router /authentication/user-access-tokens [delete] // @Security UserAccessTokenAuthentication // @Success 204 -// @Summary Create user access token +// @Summary Delete user access token // @Tags authentication func (h *Handler) DeleteUserAccessToken(w http.ResponseWriter, r *http.Request) { authentication := middleware.GetAuthentication(r.Context()) @@ -69,14 +69,14 @@ func (h *Handler) DeleteUserAccessToken(w http.ResponseWriter, r *http.Request) // ResetUserPassword godoc // @Description Reset user's password also deleting all existing user access tokens for that user. -// @Failure 422 {object} poeticmetric.AuthenticationResetUserPasswordParams -// @Param params body poeticmetric.AuthenticationResetUserPasswordParams true "Params" +// @Failure 422 {object} poeticmetric.ResetUserPasswordParams +// @Param params body poeticmetric.ResetUserPasswordParams true "Params" // @Router /authentication/reset-user-password [post] // @Success 200 {object} responder.DetailResponse // @Summary Reset user's password // @Tags authentication func (h *Handler) ResetUserPassword(w http.ResponseWriter, r *http.Request) { - params := poeticmetric.AuthenticationResetUserPasswordParams{} + params := poeticmetric.ResetUserPasswordParams{} err := json.NewDecoder(r.Body).Decode(¶ms) if err != nil { h.responder.Error(w, err) @@ -94,13 +94,13 @@ func (h *Handler) ResetUserPassword(w http.ResponseWriter, r *http.Request) { // SendUserPasswordRecoveryEmail godoc // @Description Send a password recovery e-mail to the user. -// @Param params body poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams true "Params" +// @Param params body poeticmetric.SendUserPasswordRecoveryEmailParams true "Params" // @Router /authentication/send-user-password-recovery-email [post] // @Success 201 {object} responder.DetailResponse // @Summary Send user password recovery e-mail // @Tags authentication func (h *Handler) SendUserPasswordRecoveryEmail(w http.ResponseWriter, r *http.Request) { - params := poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams{} + params := poeticmetric.SendUserPasswordRecoveryEmailParams{} err := json.NewDecoder(r.Body).Decode(¶ms) if err != nil { h.responder.Error(w, err) diff --git a/backend/pkg/restapi/handler/sites/main.go b/backend/pkg/restapi/handler/sites/main.go index a3690cba..6c8aadf6 100644 --- a/backend/pkg/restapi/handler/sites/main.go +++ b/backend/pkg/restapi/handler/sites/main.go @@ -1,6 +1,7 @@ package sites import ( + "encoding/json" "net/http" "github.com/th0th/poeticmetric/backend/pkg/poeticmetric" @@ -24,6 +25,34 @@ func New(params NewParams) *Handler { } } +// Create godoc +// @Description Create site. +// @Param params body poeticmetric.CreateSiteParams true "Params" +// @Router /sites [post] +// @Security UserAccessTokenAuthentication +// @Success 201 {object} poeticmetric.OrganizationSite +// @Summary Create site +// @Tags sites +func (h *Handler) Create(w http.ResponseWriter, r *http.Request) { + auth := middleware.GetAuthentication(r.Context()) + + params := poeticmetric.CreateSiteParams{} + err := json.NewDecoder(r.Body).Decode(¶ms) + if err != nil { + h.responder.Error(w, err) + return + } + + organizationSite, err := h.siteService.Create(r.Context(), auth.User.OrganizationID, ¶ms) + if err != nil { + h.responder.Error(w, err) + return + } + + w.WriteHeader(http.StatusCreated) + h.responder.Json(w, organizationSite) +} + // List godoc // @Description List sites. // @Router /sites [get] @@ -34,7 +63,7 @@ func New(params NewParams) *Handler { func (h *Handler) List(w http.ResponseWriter, r *http.Request) { auth := middleware.GetAuthentication(r.Context()) - organizationSites, err := h.siteService.ListOrganizationSites(r.Context(), auth.User.OrganizationID) + organizationSites, err := h.siteService.List(r.Context(), auth.User.OrganizationID) if err != nil { h.responder.Error(w, err) return diff --git a/backend/pkg/service/authentication/main.go b/backend/pkg/service/authentication/main.go index d07fa3e0..a12018cc 100644 --- a/backend/pkg/service/authentication/main.go +++ b/backend/pkg/service/authentication/main.go @@ -156,8 +156,8 @@ func (s *service) ReadUserByUserAccessToken(ctx context.Context, token string) ( return &user, &userAccessToken, nil } -func (s *service) ResetUserPassword(ctx context.Context, params *poeticmetric.AuthenticationResetUserPasswordParams) error { - err := s.validationService.AuthenticationResetUserPasswordParams(ctx, params) +func (s *service) ResetUserPassword(ctx context.Context, params *poeticmetric.ResetUserPasswordParams) error { + err := s.validationService.ResetUserPasswordParams(ctx, params) if err != nil { return err } @@ -189,8 +189,8 @@ func (s *service) ResetUserPassword(ctx context.Context, params *poeticmetric.Au return nil } -func (s *service) SendUserPasswordRecoveryEmail(ctx context.Context, params *poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams) error { - err := s.validationService.AuthenticationSendUserPasswordRecoveryEmailParams(ctx, params) +func (s *service) SendUserPasswordRecoveryEmail(ctx context.Context, params *poeticmetric.SendUserPasswordRecoveryEmailParams) error { + err := s.validationService.SendUserPasswordRecoveryEmailParams(ctx, params) if err != nil { return err } diff --git a/backend/pkg/service/authentication/main_test.go b/backend/pkg/service/authentication/main_test.go index 5a992490..62d2eacb 100644 --- a/backend/pkg/service/authentication/main_test.go +++ b/backend/pkg/service/authentication/main_test.go @@ -23,7 +23,7 @@ import ( func TestNew(t *testing.T) { emailService := new(email.MockService) postgres := new(gorm.DB) - validationService := new(poeticmetric.MockValidationService) + validationService := new(poeticmetric.ValidationServiceMock) type args struct { params NewParams @@ -327,7 +327,7 @@ func Test_service_ResetUserPassword(t *testing.T) { postgres, gotErr := gorm.Open(postgres2.New(postgres2.Config{Conn: db}), &gorm.Config{}) assert.NoError(t, gotErr) - mockValidationService := new(poeticmetric.MockValidationService) + mockValidationService := new(poeticmetric.ValidationServiceMock) // language=postgresql selectQuery := `SELECT "id" FROM "users" WHERE "users"."password_reset_token" = $1 ORDER BY "users"."id" LIMIT $2` @@ -342,7 +342,7 @@ func Test_service_ResetUserPassword(t *testing.T) { } type args struct { ctx context.Context - params *poeticmetric.AuthenticationResetUserPasswordParams + params *poeticmetric.ResetUserPasswordParams } type payload struct { password *sqlmockhelper.ValueArg @@ -363,7 +363,7 @@ func Test_service_ResetUserPassword(t *testing.T) { }, args: args{ ctx: context.Background(), - params: &poeticmetric.AuthenticationResetUserPasswordParams{ + params: &poeticmetric.ResetUserPasswordParams{ PasswordResetToken: poeticmetric.Pointer("token"), UserPassword: poeticmetric.Pointer("password"), UserPassword2: poeticmetric.Pointer("password"), @@ -380,7 +380,7 @@ func Test_service_ResetUserPassword(t *testing.T) { sqlMock.ExpectExec(updateQuery).WithArgs(passwordArg, sqlmock.AnyArg(), 1).WillReturnResult(sqlmock.NewResult(0, 1)) sqlMock.ExpectCommit() - mockValidationService.On("AuthenticationResetUserPasswordParams", mock.Anything, &poeticmetric.AuthenticationResetUserPasswordParams{ + mockValidationService.On("ResetUserPasswordParams", mock.Anything, &poeticmetric.ResetUserPasswordParams{ PasswordResetToken: poeticmetric.Pointer("token"), UserPassword: poeticmetric.Pointer("password"), UserPassword2: poeticmetric.Pointer("password"), @@ -418,7 +418,7 @@ func Test_service_ResetUserPassword(t *testing.T) { func Test_service_SendUserPasswordRecoveryEmail(t *testing.T) { mockEmailService := new(email.MockService) - mockValidationService := new(poeticmetric.MockValidationService) + mockValidationService := new(poeticmetric.ValidationServiceMock) db, sqlMock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual)) assert.NoError(t, err) @@ -441,7 +441,7 @@ func Test_service_SendUserPasswordRecoveryEmail(t *testing.T) { } type args struct { ctx context.Context - params *poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams + params *poeticmetric.SendUserPasswordRecoveryEmailParams } tests := []struct { name string @@ -459,7 +459,7 @@ func Test_service_SendUserPasswordRecoveryEmail(t *testing.T) { }, args: args{ ctx: context.Background(), - params: &poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams{ + params: &poeticmetric.SendUserPasswordRecoveryEmailParams{ Email: poeticmetric.Pointer("user@domain.tld"), }, }, @@ -484,9 +484,9 @@ func Test_service_SendUserPasswordRecoveryEmail(t *testing.T) { })).Return(nil) mockValidationService.On( - "AuthenticationSendUserPasswordRecoveryEmailParams", + "SendUserPasswordRecoveryEmailParams", mock.Anything, - &poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams{ + &poeticmetric.SendUserPasswordRecoveryEmailParams{ Email: poeticmetric.Pointer("user@domain.tld"), }, ).Return(nil) diff --git a/backend/pkg/service/env/main.go b/backend/pkg/service/env/main.go index a48636ab..e5985433 100644 --- a/backend/pkg/service/env/main.go +++ b/backend/pkg/service/env/main.go @@ -6,8 +6,11 @@ import ( "net/smtp" "os" - env2 "github.com/caarlos0/env/v11" + "github.com/caarlos0/env/v11" "github.com/rs/zerolog" + "golang.org/x/oauth2" + "golang.org/x/oauth2/google" + "google.golang.org/api/searchconsole/v1" "gorm.io/gorm" "gorm.io/gorm/logger" @@ -21,7 +24,7 @@ type service struct { func New() (poeticmetric.EnvService, error) { e := service{} - err := env2.Parse(&e.vars) + err := env.Parse(&e.vars) if err != nil { return nil, err } @@ -56,6 +59,20 @@ func (s *service) FrontendUrl(path string) string { return fmt.Sprintf("%s%s", s.vars.FrontendBaseUrl, path) } +func (s *service) GoogleOAuthConfig() (*oauth2.Config, error) { + if s.vars.GoogleClientID == nil || s.vars.GoogleClientSecret == nil { + return nil, fmt.Errorf("google oauth credentials are not set") + } + + return &oauth2.Config{ + ClientID: *s.vars.GoogleClientID, + ClientSecret: *s.vars.GoogleClientSecret, + Endpoint: google.Endpoint, + RedirectURL: s.FrontendUrl(""), + Scopes: []string{searchconsole.WebmastersReadonlyScope}, + }, nil +} + func (s *service) GormConfig() *gorm.Config { logLevel := logger.Error diff --git a/backend/pkg/service/site/main.go b/backend/pkg/service/site/main.go index 7565580f..40f893b1 100644 --- a/backend/pkg/service/site/main.go +++ b/backend/pkg/service/site/main.go @@ -9,20 +9,57 @@ import ( ) type NewParams struct { - Postgres *gorm.DB + Postgres *gorm.DB + ValidationService poeticmetric.ValidationService } type service struct { - postgres *gorm.DB + postgres *gorm.DB + validationService poeticmetric.ValidationService } func New(params NewParams) poeticmetric.SiteService { return &service{ - postgres: params.Postgres, + postgres: params.Postgres, + validationService: params.ValidationService, } } -func (s *service) ListOrganizationSites(ctx context.Context, organizationID uint) ([]*poeticmetric.OrganizationSite, error) { +func (s *service) Create(ctx context.Context, organizationID uint, params *poeticmetric.CreateSiteParams) (*poeticmetric.OrganizationSite, error) { + err := s.validationService.CreateSiteParams(ctx, organizationID, params) + if err != nil { + return nil, err + } + + postgres := poeticmetric.ServicePostgres(ctx, s) + + site := &poeticmetric.Site{ + Domain: *params.Domain, + IsPublic: *params.IsPublic, + Name: *params.Name, + SafeQueryParameters: params.SafeQueryParameters, + OrganizationID: organizationID, + } + + err = postgres.Create(site).Error + if err != nil { + return nil, err + } + + return &poeticmetric.OrganizationSite{ + CreatedAt: site.CreatedAt, + Domain: site.Domain, + GoogleSearchConsoleSiteUrl: site.GoogleSearchConsoleSiteUrl, + HasEvents: site.HasEvents, + ID: site.ID, + IsPublic: site.IsPublic, + Name: site.Name, + SafeQueryParameters: site.SafeQueryParameters, + UpdatedAt: site.UpdatedAt, + }, nil +} + +func (s *service) List(ctx context.Context, organizationID uint) ([]*poeticmetric.OrganizationSite, error) { postgres := poeticmetric.ServicePostgres(ctx, s) organizationSites := []*poeticmetric.OrganizationSite{} diff --git a/backend/pkg/service/site/main_test.go b/backend/pkg/service/site/main_test.go index 598d8d71..4040e152 100644 --- a/backend/pkg/service/site/main_test.go +++ b/backend/pkg/service/site/main_test.go @@ -7,7 +7,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" "github.com/jinzhu/now" "github.com/stretchr/testify/assert" - postgres2 "gorm.io/driver/postgres" + "github.com/stretchr/testify/mock" + gormpostgres "gorm.io/driver/postgres" "gorm.io/gorm" "github.com/th0th/poeticmetric/backend/pkg/poeticmetric" @@ -16,6 +17,7 @@ import ( func TestNew(t *testing.T) { postgres := &gorm.DB{} + mockValidationService := &poeticmetric.ValidationServiceMock{} type args struct { params NewParams @@ -29,11 +31,13 @@ func TestNew(t *testing.T) { name: "successful", args: args{ params: NewParams{ - Postgres: postgres, + Postgres: postgres, + ValidationService: mockValidationService, }, }, want: &service{ - postgres: postgres, + postgres: postgres, + validationService: mockValidationService, }, }, } @@ -45,7 +49,104 @@ func TestNew(t *testing.T) { } } -func Test_service_ListOrganizationSites(t *testing.T) { +func Test_service_Create(t *testing.T) { + db, sqlMock, err := sqlmock.New( + sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual), + sqlmock.ValueConverterOption(sqlmockhelper.CustomConverter{}), + ) + if err != nil { + t.Fatal(err) + } + postgres, err := gorm.Open(gormpostgres.New(gormpostgres.Config{Conn: db}), &gorm.Config{}) + if err != nil { + t.Fatal(err) + } + + mockValidationService := &poeticmetric.ValidationServiceMock{} + + // language=postgresql + insertQuery := `INSERT INTO "sites" ("created_at","domain","google_search_console_site_url","has_events","is_public","name","organization_id","safe_query_parameters","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9) RETURNING "id"` + + type fields struct { + postgres *gorm.DB + validationService poeticmetric.ValidationService + } + type args struct { + ctx context.Context + organizationID uint + params *poeticmetric.CreateSiteParams + } + tests := []struct { + name string + fields fields + args args + setup func() + want *poeticmetric.OrganizationSite + wantErr assert.ErrorAssertionFunc + }{ + { + name: "success", + fields: fields{ + postgres: postgres, + validationService: mockValidationService, + }, + args: args{ + ctx: context.Background(), + organizationID: 1, + params: &poeticmetric.CreateSiteParams{ + Domain: poeticmetric.Pointer("www.domain.tld"), + IsPublic: poeticmetric.Pointer(true), + Name: poeticmetric.Pointer("random name"), + SafeQueryParameters: []string{}, + }, + }, + setup: func() { + mockValidationService.On("CreateSiteParams", mock.Anything, mock.Anything).Return(nil) + + sqlMock.ExpectBegin() + sqlMock.ExpectQuery(insertQuery). + WithArgs(sqlmock.AnyArg(), "www.domain.tld", sqlmock.AnyArg(), false, true, "random name", uint(1), sqlmock.AnyArg(), sqlmock.AnyArg()). + WillReturnRows(sqlMock.NewRows([]string{"id"}).AddRow(1)) + sqlMock.ExpectCommit() + }, + want: &poeticmetric.OrganizationSite{ + Domain: "www.domain.tld", + GoogleSearchConsoleSiteUrl: nil, + HasEvents: false, + ID: 1, + IsPublic: true, + Name: "random name", + SafeQueryParameters: []string{}, + }, + wantErr: assert.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := &service{ + postgres: tt.fields.postgres, + validationService: tt.fields.validationService, + } + + tt.setup() + + got, gotErr := s.Create(tt.args.ctx, tt.args.organizationID, tt.args.params) + tt.wantErr(t, gotErr) + + assert.Equal(t, tt.want.Domain, got.Domain) + assert.Equal(t, tt.want.GoogleSearchConsoleSiteUrl, got.GoogleSearchConsoleSiteUrl) + assert.Equal(t, tt.want.HasEvents, got.HasEvents) + assert.Equal(t, tt.want.ID, got.ID) + assert.Equal(t, tt.want.IsPublic, got.IsPublic) + assert.Equal(t, tt.want.Name, got.Name) + assert.Equal(t, tt.want.SafeQueryParameters, got.SafeQueryParameters) + + assert.NoError(t, sqlMock.ExpectationsWereMet()) + }) + } +} + +func Test_service_List(t *testing.T) { db, sqlMock, err := sqlmock.New( sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual), sqlmock.ValueConverterOption(sqlmockhelper.CustomConverter{}), @@ -54,7 +155,7 @@ func Test_service_ListOrganizationSites(t *testing.T) { t.Fatal(err) } - postgres, err := gorm.Open(postgres2.New(postgres2.Config{Conn: db}), &gorm.Config{}) + postgres, err := gorm.Open(gormpostgres.New(gormpostgres.Config{Conn: db}), &gorm.Config{}) if err != nil { t.Fatal(err) } @@ -138,7 +239,7 @@ func Test_service_ListOrganizationSites(t *testing.T) { tt.setup() - got, err2 := s.ListOrganizationSites(tt.args.ctx, tt.args.organizationID) + got, err2 := s.List(tt.args.ctx, tt.args.organizationID) tt.wantErr(t, err2) assert.Equal(t, tt.want, got) assert.NoError(t, sqlMock.ExpectationsWereMet()) diff --git a/backend/pkg/service/validation/main.go b/backend/pkg/service/validation/main.go index b2e70ccf..3190971c 100644 --- a/backend/pkg/service/validation/main.go +++ b/backend/pkg/service/validation/main.go @@ -7,30 +7,100 @@ import ( v "github.com/RussellLuo/validating/v3" "github.com/RussellLuo/vext" + "golang.org/x/oauth2" + "google.golang.org/api/option" + "google.golang.org/api/searchconsole/v1" "gorm.io/gorm" "github.com/th0th/poeticmetric/backend/pkg/poeticmetric" ) type NewParams struct { - Postgres *gorm.DB + EnvService poeticmetric.EnvService + Postgres *gorm.DB } type service struct { - postgres *gorm.DB + envService poeticmetric.EnvService + postgres *gorm.DB } func New(params NewParams) poeticmetric.ValidationService { return &service{ - postgres: params.Postgres, + envService: params.EnvService, + postgres: params.Postgres, } } +func (s *service) CreateSiteParams(ctx context.Context, organizationID uint, params *poeticmetric.CreateSiteParams) error { + errs := []error{} + + validationErrs := v.Validate(v.Schema{ + v.F("domain", params.Domain): v.All( + v.Nonzero[*string]().Msg("This field is required."), + + v.Nested(func(x *string) v.Validator { + return v.Value(*x, vext.DNSName().Msg("Please provide a valid domain.")) + }), + + v.Is(func(x *string) bool { + isOk, err := s.uniqueSiteDomain(ctx, *x, nil) + if err != nil { + errs = append(errs, err) + } + + return isOk + }).Msg("This domain is already in use."), + ), + + v.F("googleSearchConsoleSiteURL", params.GoogleSearchConsoleSiteURL): v.Any( + v.Zero[*string](), + + v.All( + v.Is(func(x *string) bool { + isOk, err := s.googleSearchConsoleSiteURL(ctx, organizationID, *x) + if err != nil { + errs = append(errs, err) + } + + return isOk + }), + ), + ), + + v.F("isPublic", params.IsPublic): v.All( + v.Nonzero[*bool]().Msg("This field is required."), + ), + + v.F("name", params.Name): v.All( + v.Nonzero[*string]().Msg("This field is required."), + + v.Nested(func(x *string) v.Validator { + return v.Value(*x, v.LenString(poeticmetric.SiteNameMinLength, poeticmetric.SiteNameMaxLength).Msg(fmt.Sprintf( + "The site name must be between %d and %d characters long.", + poeticmetric.SiteNameMinLength, + poeticmetric.SiteNameMaxLength, + ))) + }), + ), + }) + + if len(errs) > 0 { + return errors.Join(errs...) + } + + if len(validationErrs) > 0 { + return validationErrs + } + + return nil +} + func (s *service) Postgres() *gorm.DB { return s.postgres } -func (s *service) AuthenticationResetUserPasswordParams(ctx context.Context, params *poeticmetric.AuthenticationResetUserPasswordParams) error { +func (s *service) ResetUserPasswordParams(ctx context.Context, params *poeticmetric.ResetUserPasswordParams) error { errs := []error{} validationErrs := v.Validate(v.Schema{ @@ -38,7 +108,7 @@ func (s *service) AuthenticationResetUserPasswordParams(ctx context.Context, par v.Nonzero[*string]().Msg("This field is required."), v.Is(func(x *string) bool { - isValid, err := s.validateUserPasswordResetToken(ctx, *x) + isValid, err := s.userPasswordResetToken(ctx, *x) if err != nil { errs = append(errs, err) } @@ -77,7 +147,7 @@ func (s *service) AuthenticationResetUserPasswordParams(ctx context.Context, par return nil } -func (s *service) AuthenticationSendUserPasswordRecoveryEmailParams(ctx context.Context, params *poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams) error { +func (s *service) SendUserPasswordRecoveryEmailParams(ctx context.Context, params *poeticmetric.SendUserPasswordRecoveryEmailParams) error { validationErrs := v.Validate(v.Schema{ v.F("email", params.Email): v.All( v.Nonzero[*string]().Msg("This field is required."), @@ -95,7 +165,64 @@ func (s *service) AuthenticationSendUserPasswordRecoveryEmailParams(ctx context. return nil } -func (s *service) validateUserPasswordResetToken(ctx context.Context, token string) (bool, error) { +func (s *service) googleSearchConsoleSiteURL(ctx context.Context, organizationID uint, siteURL string) (bool, error) { + postgres := poeticmetric.ServicePostgres(ctx, s) + + organization := poeticmetric.Organization{} + err := postgres.Select("GoogleOauthRefreshToken").First(&organization, poeticmetric.Organization{ID: organizationID}, "ID").Error + if err != nil { + return false, err + } + + if organization.GoogleOauthRefreshToken == nil { + return false, poeticmetric.ErrNoOrganizationGoogleOauthRefreshToken + } + + oAuthConfig, err := s.envService.GoogleOAuthConfig() + if err != nil { + return false, err + } + + searchConsoleService, err := searchconsole.NewService( + ctx, + option.WithTokenSource(oAuthConfig.TokenSource(ctx, &oauth2.Token{RefreshToken: *organization.GoogleOauthRefreshToken})), + ) + if err != nil { + return false, err + } + + site, err := searchConsoleService.Sites.Get(siteURL).Do() + if err != nil { + return false, err + } + + if site.SiteUrl != siteURL { + return false, nil + } + + return true, nil +} + +func (s *service) uniqueSiteDomain(ctx context.Context, domain string, siteID *uint) (bool, error) { + postgres := poeticmetric.ServicePostgres(ctx, s) + + q := postgres.Session(&gorm.Session{}) + if siteID != nil { + q = q.Not(poeticmetric.Site{ID: *siteID}) + } + err := q.First(&poeticmetric.Site{}, poeticmetric.Site{Domain: domain}).Error + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return true, nil + } + + return false, err + } + + return false, nil +} + +func (s *service) userPasswordResetToken(ctx context.Context, token string) (bool, error) { postgres := poeticmetric.ServicePostgres(ctx, s) err := postgres.Select("PasswordResetToken").First(&poeticmetric.User{}, poeticmetric.User{PasswordResetToken: &token}).Error diff --git a/backend/pkg/service/validation/main_test.go b/backend/pkg/service/validation/main_test.go index 84ec4962..43afeb4a 100644 --- a/backend/pkg/service/validation/main_test.go +++ b/backend/pkg/service/validation/main_test.go @@ -13,7 +13,7 @@ import ( "github.com/th0th/poeticmetric/backend/pkg/poeticmetric" ) -func Test_service_AuthenticationResetUserPasswordParams(t *testing.T) { +func Test_service_ResetUserPasswordParams(t *testing.T) { db, sqlMock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual)) assert.NoError(t, err) @@ -28,7 +28,7 @@ func Test_service_AuthenticationResetUserPasswordParams(t *testing.T) { } type args struct { ctx context.Context - params *poeticmetric.AuthenticationResetUserPasswordParams + params *poeticmetric.ResetUserPasswordParams } tests := []struct { name string @@ -44,7 +44,7 @@ func Test_service_AuthenticationResetUserPasswordParams(t *testing.T) { }, args: args{ ctx: context.Background(), - params: &poeticmetric.AuthenticationResetUserPasswordParams{ + params: &poeticmetric.ResetUserPasswordParams{ PasswordResetToken: poeticmetric.Pointer("token"), UserPassword: poeticmetric.Pointer("password"), UserPassword2: poeticmetric.Pointer("password"), @@ -65,7 +65,7 @@ func Test_service_AuthenticationResetUserPasswordParams(t *testing.T) { }, args: args{ ctx: context.Background(), - params: &poeticmetric.AuthenticationResetUserPasswordParams{ + params: &poeticmetric.ResetUserPasswordParams{ PasswordResetToken: poeticmetric.Pointer("token"), UserPassword: poeticmetric.Pointer("pass"), UserPassword2: poeticmetric.Pointer("pass2"), @@ -98,19 +98,19 @@ func Test_service_AuthenticationResetUserPasswordParams(t *testing.T) { tt.setup() - err = s.AuthenticationResetUserPasswordParams(tt.args.ctx, tt.args.params) + err = s.ResetUserPasswordParams(tt.args.ctx, tt.args.params) tt.wantErr(t, err) }) } } -func Test_service_AuthenticationSendUserPasswordRecoveryEmail(t *testing.T) { +func Test_service_SendUserPasswordRecoveryEmail(t *testing.T) { type fields struct { - postgres *gorm.DB + postgres *gorm.DB } type args struct { ctx context.Context - params *poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams + params *poeticmetric.SendUserPasswordRecoveryEmailParams } tests := []struct { name string @@ -122,7 +122,7 @@ func Test_service_AuthenticationSendUserPasswordRecoveryEmail(t *testing.T) { name: "successful", args: args{ ctx: context.Background(), - params: &poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams{ + params: &poeticmetric.SendUserPasswordRecoveryEmailParams{ Email: poeticmetric.Pointer("user@domain.tld"), }, }, @@ -132,7 +132,7 @@ func Test_service_AuthenticationSendUserPasswordRecoveryEmail(t *testing.T) { name: "invalid e-mail", args: args{ ctx: context.Background(), - params: &poeticmetric.AuthenticationSendUserPasswordRecoveryEmailParams{ + params: &poeticmetric.SendUserPasswordRecoveryEmailParams{ Email: poeticmetric.Pointer("invalid-email"), }, }, @@ -151,8 +151,126 @@ func Test_service_AuthenticationSendUserPasswordRecoveryEmail(t *testing.T) { postgres: tt.fields.postgres, } - gotErr := s.AuthenticationSendUserPasswordRecoveryEmailParams(tt.args.ctx, tt.args.params) + gotErr := s.SendUserPasswordRecoveryEmailParams(tt.args.ctx, tt.args.params) + tt.wantErr(t, gotErr) + }) + } +} + +func Test_service_uniqueSiteDomain(t *testing.T) { + db, sqlMock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual)) + assert.NoError(t, err) + + postgres, err := gorm.Open(postgres2.New(postgres2.Config{Conn: db}), &gorm.Config{}) + assert.NoError(t, err) + + // language=postgresql + selectQuery := `SELECT * FROM "sites" WHERE "sites"."domain" = $1 ORDER BY "sites"."id" LIMIT $2` + + // language=postgresql + selectWithIdQuery := `SELECT * FROM "sites" WHERE "sites"."id" <> $1 AND "sites"."domain" = $2 ORDER BY "sites"."id" LIMIT $3` + + type fields struct { + postgres *gorm.DB + } + type args struct { + ctx context.Context + domain string + siteID *uint + } + tests := []struct { + name string + fields fields + args args + setup func() + want bool + wantErr assert.ErrorAssertionFunc + }{ + { + name: "valid - nil siteID", + fields: fields{ + postgres: postgres, + }, + args: args{ + ctx: context.Background(), + domain: "www.domain.tld", + siteID: nil, + }, + setup: func() { + sqlMock.ExpectQuery(selectQuery).WithArgs("www.domain.tld", 1).WillReturnRows(sqlmock.NewRows([]string{})) + }, + want: true, + wantErr: assert.NoError, + }, + { + name: "valid", + fields: fields{ + postgres: postgres, + }, + args: args{ + ctx: context.Background(), + domain: "www.domain.tld", + siteID: poeticmetric.Pointer(uint(1)), + }, + setup: func() { + sqlMock. + ExpectQuery(selectWithIdQuery). + WithArgs(1, "www.domain.tld", 1). + WillReturnRows(sqlmock.NewRows([]string{})) + }, + want: true, + wantErr: assert.NoError, + }, + { + name: "invalid - nil siteID", + fields: fields{ + postgres: postgres, + }, + args: args{ + ctx: context.Background(), + domain: "www.domain.tld", + siteID: nil, + }, + setup: func() { + sqlMock. + ExpectQuery(selectQuery). + WithArgs("www.domain.tld", 1). + WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1)) + }, + want: false, + wantErr: assert.NoError, + }, + { + name: "invalid", + fields: fields{ + postgres: postgres, + }, + args: args{ + ctx: context.Background(), + domain: "www.domain.tld", + siteID: poeticmetric.Pointer(uint(1)), + }, + setup: func() { + sqlMock. + ExpectQuery(selectWithIdQuery). + WithArgs(1, "www.domain.tld", 1). + WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1)) + }, + want: false, + wantErr: assert.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := &service{ + postgres: tt.fields.postgres, + } + + tt.setup() + + got, gotErr := s.uniqueSiteDomain(tt.args.ctx, tt.args.domain, tt.args.siteID) tt.wantErr(t, gotErr) + assert.Equal(t, tt.want, got) }) } } From 4065084102f9efdd3990c08884f8cbfefd8edf69 Mon Sep 17 00:00:00 2001 From: Gokhan Sari Date: Tue, 19 Nov 2024 16:34:18 +0300 Subject: [PATCH 5/8] Update go modules --- backend/go.mod | 27 +++++++++---------- backend/go.sum | 73 ++++++++++++++++++++------------------------------ 2 files changed, 42 insertions(+), 58 deletions(-) diff --git a/backend/go.mod b/backend/go.mod index a1936747..40d1ab1e 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -23,21 +23,23 @@ require ( github.com/swaggo/swag v1.16.4 github.com/ulule/limiter/v3 v3.11.2 golang.org/x/crypto v0.29.0 - google.golang.org/api v0.169.0 + golang.org/x/oauth2 v0.24.0 + google.golang.org/api v0.206.0 gorm.io/driver/clickhouse v0.6.1 gorm.io/driver/postgres v1.5.9 gorm.io/gorm v1.25.12 ) require ( - cloud.google.com/go/compute v1.25.1 // indirect - cloud.google.com/go/compute/metadata v0.2.3 // indirect + cloud.google.com/go/auth v0.10.2 // indirect + cloud.google.com/go/auth/oauth2adapt v0.2.5 // indirect + cloud.google.com/go/compute/metadata v0.5.2 // indirect github.com/ClickHouse/ch-go v0.61.5 // indirect github.com/ClickHouse/clickhouse-go/v2 v2.23.2 // indirect github.com/KyleBanks/depth v1.2.1 // indirect github.com/andybalholm/brotli v1.1.0 // indirect github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/felixge/httpsnoop v1.0.4 // indirect @@ -50,10 +52,9 @@ require ( github.com/go-openapi/spec v0.20.6 // indirect github.com/go-openapi/swag v0.19.15 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/protobuf v1.5.4 // indirect - github.com/google/s2a-go v0.1.7 // indirect - github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect - github.com/googleapis/gax-go/v2 v2.12.2 // indirect + github.com/google/s2a-go v0.1.8 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect + github.com/googleapis/gax-go/v2 v2.14.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-version v1.6.0 // indirect @@ -85,16 +86,14 @@ require ( go.opentelemetry.io/otel/trace v1.29.0 // indirect go.uber.org/atomic v1.11.0 // indirect golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect - golang.org/x/net v0.29.0 // indirect - golang.org/x/oauth2 v0.18.0 // indirect + golang.org/x/net v0.31.0 // indirect golang.org/x/sync v0.9.0 // indirect golang.org/x/sys v0.27.0 // indirect golang.org/x/text v0.20.0 // indirect golang.org/x/tools v0.24.0 // indirect - google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect - google.golang.org/grpc v1.64.1 // indirect - google.golang.org/protobuf v1.34.2 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect + google.golang.org/grpc v1.67.1 // indirect + google.golang.org/protobuf v1.35.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/backend/go.sum b/backend/go.sum index e7cac70e..5b1749ec 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -1,8 +1,10 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go/compute v1.25.1 h1:ZRpHJedLtTpKgr3RV1Fx23NuaAEN1Zfx9hw1u4aJdjU= -cloud.google.com/go/compute v1.25.1/go.mod h1:oopOIR53ly6viBYxaDhBfJwzUAxf1zE//uf3IB011ls= -cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= -cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= +cloud.google.com/go/auth v0.10.2 h1:oKF7rgBfSHdp/kuhXtqU/tNDr0mZqhYbEh+6SiqzkKo= +cloud.google.com/go/auth v0.10.2/go.mod h1:xxA5AqpDrvS+Gkmo9RqrGGRh6WSNKKOXhY3zNOr38tI= +cloud.google.com/go/auth/oauth2adapt v0.2.5 h1:2p29+dePqsCHPP1bqDJcKj4qxRyYCcbzKpFyKGt3MTk= +cloud.google.com/go/auth/oauth2adapt v0.2.5/go.mod h1:AlmsELtlEBnaNTL7jCj8VQFLy6mbZv0s4Q7NGBeQ5E8= +cloud.google.com/go/compute/metadata v0.5.2 h1:UxK4uu/Tn+I3p2dYWTfiX4wva7aYlKixAHn3fyqngqo= +cloud.google.com/go/compute/metadata v0.5.2/go.mod h1:C66sj2AluDcIqakBq/M8lw8/ybHgOZqin2obFxa/E5k= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -35,8 +37,8 @@ github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0 github.com/caarlos0/env/v11 v11.2.2 h1:95fApNrUyueipoZN/EhA8mMxiNxrBwDa+oAZrMWl3Kg= github.com/caarlos0/env/v11 v11.2.2/go.mod h1:JBfcdeQiBoI3Zh1QRAWfe+tpiNTmDtcCj/hHHHMx0vc= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 h1:F1EaeKL/ta07PY/k9Os/UFtwERei2/XzGemhpGnBKNg= github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80= @@ -107,9 +109,6 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= -github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -121,15 +120,15 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= -github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= +github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM= +github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs= -github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= -github.com/googleapis/gax-go/v2 v2.12.2 h1:mhN09QQW1jEWeMF74zGR81R30z4VJzjZsfkUhuHF+DA= -github.com/googleapis/gax-go/v2 v2.12.2/go.mod h1:61M8vcyyXR2kqKFxKrfA22jaA8JGF7Dc8App1U3H6jc= +github.com/googleapis/enterprise-certificate-proxy v0.3.4 h1:XYIDZApgAnrN1c855gTgghdIA6Stxb52D5RnLI1SLyw= +github.com/googleapis/enterprise-certificate-proxy v0.3.4/go.mod h1:YKe7cfqYXjKGpGvmSg28/fFvhNzinZQm8DGnaburhGA= +github.com/googleapis/gax-go/v2 v2.14.0 h1:f+jMrjBPl+DL9nI4IQzLUxMq7XrAqFYB7hBPqMNIe8o= +github.com/googleapis/gax-go/v2 v2.14.0/go.mod h1:lhBCnjdLrWRaPvLWhmc8IS24m9mr07qSYnHncrgo+zk= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -244,7 +243,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.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= @@ -261,7 +259,6 @@ go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= @@ -273,7 +270,6 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 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.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -285,21 +281,18 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/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-20201110031124-69a78807bb2b/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-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= -golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= +golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= -golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= +golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE= +golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -309,20 +302,16 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -333,34 +322,31 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.169.0 h1:QwWPy71FgMWqJN/l6jVlFHUa29a7dcUy02I8o799nPY= -google.golang.org/api v0.169.0/go.mod h1:gpNOiMA2tZ4mf5R9Iwf4rK/Dcz0fbdIgWYWVoxmsyLg= +google.golang.org/api v0.206.0 h1:A27GClesCSheW5P2BymVHjpEeQ2XHH8DI8Srs2HI2L8= +google.golang.org/api v0.206.0/go.mod h1:BtB8bfjTYIrai3d8UyvPmV9REGgox7coh+ZRwm0b+W8= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= -google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 h1:9+tzLLstTlPTRyJTh+ah5wIMsBW5c4tQwGTN3thOW9Y= -google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 h1:W5Xj/70xIA4x60O/IFyXivR5MGqblAb8R3w26pnD6No= -google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8/go.mod h1:vPrPUTsDCYxXWjP7clS81mZ6/803D8K4iM9Ma27VKas= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 h1:mxSlqyb8ZAHsYDCfiXN1EDdNTdvjUJSLY+OnAUtYNYA= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM= +google.golang.org/genproto v0.0.0-20241104194629-dd2ea8efbc28 h1:KJjNNclfpIkVqrZlTWcgOOaVQ00LdBnoEaRfkUx760s= +google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 h1:M0KvPgPmDZHPlbRbaNU1APr28TvwvvdUPlSv7PUvy8g= +google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:dguCy7UOdZhTvLzDyt15+rOrawrpM4q7DD9dQ1P11P4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 h1:XVhgTWWV3kGQlwJHR3upFWZeTsei6Oks1apkZSeonIE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= -google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -371,10 +357,9 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 3b8b8893b0eb27fee5ae407582e971e30be83d17 Mon Sep 17 00:00:00 2001 From: Gokhan Sari Date: Tue, 19 Nov 2024 16:35:25 +0300 Subject: [PATCH 6/8] Update main.go --- backend/pkg/service/site/main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/pkg/service/site/main.go b/backend/pkg/service/site/main.go index 40f893b1..12e58e43 100644 --- a/backend/pkg/service/site/main.go +++ b/backend/pkg/service/site/main.go @@ -34,11 +34,12 @@ func (s *service) Create(ctx context.Context, organizationID uint, params *poeti postgres := poeticmetric.ServicePostgres(ctx, s) site := &poeticmetric.Site{ - Domain: *params.Domain, - IsPublic: *params.IsPublic, - Name: *params.Name, - SafeQueryParameters: params.SafeQueryParameters, - OrganizationID: organizationID, + Domain: *params.Domain, + GoogleSearchConsoleSiteUrl: params.GoogleSearchConsoleSiteURL, + IsPublic: *params.IsPublic, + Name: *params.Name, + SafeQueryParameters: params.SafeQueryParameters, + OrganizationID: organizationID, } err = postgres.Create(site).Error From cefa39e460de08cb20da2bb730d98e0cb431fbf6 Mon Sep 17 00:00:00 2001 From: Gokhan Sari Date: Thu, 21 Nov 2024 00:14:07 +0300 Subject: [PATCH 7/8] Handle organization's not having google oauth refresh token --- backend/pkg/service/validation/main.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/backend/pkg/service/validation/main.go b/backend/pkg/service/validation/main.go index 3190971c..156d04ea 100644 --- a/backend/pkg/service/validation/main.go +++ b/backend/pkg/service/validation/main.go @@ -33,6 +33,14 @@ func New(params NewParams) poeticmetric.ValidationService { } func (s *service) CreateSiteParams(ctx context.Context, organizationID uint, params *poeticmetric.CreateSiteParams) error { + postgres := poeticmetric.ServicePostgres(ctx, s) + + organization := poeticmetric.Organization{} + err := postgres.Select("GoogleOauthRefreshToken").First(&organization, poeticmetric.Organization{ID: organizationID}, "ID").Error + if err != nil { + return err + } + errs := []error{} validationErrs := v.Validate(v.Schema{ @@ -44,9 +52,9 @@ func (s *service) CreateSiteParams(ctx context.Context, organizationID uint, par }), v.Is(func(x *string) bool { - isOk, err := s.uniqueSiteDomain(ctx, *x, nil) - if err != nil { - errs = append(errs, err) + isOk, err2 := s.uniqueSiteDomain(ctx, *x, nil) + if err2 != nil { + errs = append(errs, err2) } return isOk @@ -57,10 +65,14 @@ func (s *service) CreateSiteParams(ctx context.Context, organizationID uint, par v.Zero[*string](), v.All( + v.Is(func(_ any) bool { + return organization.GoogleOauthRefreshToken != nil + }).Msg("You need to connect your Google Search Console account to use this feature."), + v.Is(func(x *string) bool { - isOk, err := s.googleSearchConsoleSiteURL(ctx, organizationID, *x) - if err != nil { - errs = append(errs, err) + isOk, err2 := s.googleSearchConsoleSiteURL(ctx, organizationID, *x) + if err2 != nil { + errs = append(errs, err2) } return isOk From 6fc6faf9ffb71f7a1ef6a6d70ad9b29b9cecfc78 Mon Sep 17 00:00:00 2001 From: Gokhan Sari Date: Thu, 21 Nov 2024 00:21:37 +0300 Subject: [PATCH 8/8] Update run_tests.yaml --- .github/workflows/run_tests.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run_tests.yaml b/.github/workflows/run_tests.yaml index 6ecad2c9..bfcd8a5a 100644 --- a/.github/workflows/run_tests.yaml +++ b/.github/workflows/run_tests.yaml @@ -3,7 +3,7 @@ on: pull_request: jobs: frontend: - if: "contains(github.event.pull_request.labels.*.name, 'status: ready for review')" + if: "!contains(github.event.pull_request.labels.*.name, 'status: in progress')" name: Run frontend tests runs-on: ubuntu-latest steps: @@ -69,7 +69,7 @@ jobs: workdir: frontend backend: - if: "contains(github.event.pull_request.labels.*.name, 'status: ready for review')" + if: "!contains(github.event.pull_request.labels.*.name, 'status: in progress')" name: Run backend tests runs-on: ubuntu-latest steps: