Skip to content

Commit

Permalink
Replace with valid auth svc, add admin auth to event types
Browse files Browse the repository at this point in the history
  • Loading branch information
violog committed Jul 5, 2024
1 parent 649a7d3 commit 6bd9357
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 19 deletions.
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ require (
github.com/go-co-op/gocron/v2 v2.2.2
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/google/jsonapi v1.0.0
github.com/google/uuid v1.6.0
github.com/iden3/go-rapidsnark/types v0.0.3
github.com/labstack/gommon v0.4.0
github.com/rarimo/decentralized-auth-svc v0.0.0-20240522134350-2694eafa9509
github.com/rarimo/geo-auth-svc v0.2.0
github.com/rarimo/saver-grpc-lib v1.0.0
github.com/rarimo/zkverifier-kit v1.0.0
github.com/rubenv/sql-migrate v1.6.1
github.com/stretchr/testify v1.9.0
gitlab.com/distributed_lab/ape v1.7.1
gitlab.com/distributed_lab/figure/v3 v3.1.4
gitlab.com/distributed_lab/kit v1.11.3
Expand Down Expand Up @@ -83,6 +81,7 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
Expand Down Expand Up @@ -123,7 +122,6 @@ require (
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rarimo/broadcaster-svc v1.0.2 // indirect
github.com/rarimo/geo-auth-svc v0.1.1-0.20240705093615-133c4e6dfd40 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
Expand All @@ -137,6 +135,7 @@ require (
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2114,10 +2114,8 @@ github.com/rarimo/broadcaster-svc v1.0.2 h1:ExQcjjWCRP5+POLDlZHrTD1ffUsBH+Dgv5FA
github.com/rarimo/broadcaster-svc v1.0.2/go.mod h1:lYIHy+X4IqQt4eBdtMN/V352H3EV0/gO8G+32SFwUWI=
github.com/rarimo/cosmos-sdk v0.46.7 h1:jU2PiWzc+19SF02cXM0O0puKPeH1C6Q6t2lzJ9s1ejc=
github.com/rarimo/cosmos-sdk v0.46.7/go.mod h1:fqKqz39U5IlEFb4nbQ72951myztsDzFKKDtffYJ63nk=
github.com/rarimo/decentralized-auth-svc v0.0.0-20240522134350-2694eafa9509 h1:U3gu/Z61tVIVEVoWL1YdwiNzkaXlkgd7cSeEslVfsLI=
github.com/rarimo/decentralized-auth-svc v0.0.0-20240522134350-2694eafa9509/go.mod h1:V9XSqZSBN/YmLdI6PW6GL2xNeJ94IXAnhcuvyQfVBL8=
github.com/rarimo/geo-auth-svc v0.1.1-0.20240705093615-133c4e6dfd40 h1:1AD0ePxRMxMGwvIrTFYlzYQwpVUkObYNGQIqD11d+oc=
github.com/rarimo/geo-auth-svc v0.1.1-0.20240705093615-133c4e6dfd40/go.mod h1:SB4bo1xHYDAsBaQGX2+FoEgD3xxqYmcgr4XTTjy4/OM=
github.com/rarimo/geo-auth-svc v0.2.0 h1:yQvcIBNx+Tc1jJdtpWDfyLc0HogU+okA08HEZ55wv5U=
github.com/rarimo/geo-auth-svc v0.2.0/go.mod h1:SB4bo1xHYDAsBaQGX2+FoEgD3xxqYmcgr4XTTjy4/OM=
github.com/rarimo/saver-grpc-lib v1.0.0 h1:MGUVjYg7unmodYczVsLqlqZNkT4CIgKqdo6aQtL1qdE=
github.com/rarimo/saver-grpc-lib v1.0.0/go.mod h1:DpugWK5B7Hi0bdC3MPe/9FD2zCxaRwsyykdwxtF1Zgg=
github.com/rarimo/zkverifier-kit v1.0.0 h1:zMW85hyDP3Uk6p9Dk9U4TBzOf0Pry+RNlWpli1tUZ1Q=
Expand Down
2 changes: 1 addition & 1 deletion internal/config/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config

import (
"github.com/rarimo/decentralized-auth-svc/pkg/auth"
"github.com/rarimo/geo-auth-svc/pkg/auth"
"github.com/rarimo/geo-auth-svc/pkg/hmacsig"
"github.com/rarimo/geo-points-svc/internal/data/evtypes"
"github.com/rarimo/saver-grpc-lib/broadcaster"
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/claim_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"net/http"

"github.com/rarimo/decentralized-auth-svc/pkg/auth"
"github.com/rarimo/geo-auth-svc/pkg/auth"
"github.com/rarimo/geo-points-svc/internal/config"
"github.com/rarimo/geo-points-svc/internal/data"
"github.com/rarimo/geo-points-svc/internal/data/evtypes"
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/create_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"net/http"

"github.com/rarimo/decentralized-auth-svc/pkg/auth"
"github.com/rarimo/geo-auth-svc/pkg/auth"
"github.com/rarimo/geo-points-svc/internal/data"
"github.com/rarimo/geo-points-svc/internal/data/evtypes"
"github.com/rarimo/geo-points-svc/internal/data/evtypes/models"
Expand Down
6 changes: 6 additions & 0 deletions internal/service/handlers/create_event_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"net/http"

"github.com/rarimo/geo-auth-svc/pkg/auth"
"github.com/rarimo/geo-points-svc/internal/data/evtypes/models"
"github.com/rarimo/geo-points-svc/internal/service/requests"
"gitlab.com/distributed_lab/ape"
Expand All @@ -16,6 +17,11 @@ func CreateEventType(w http.ResponseWriter, r *http.Request) {
return
}

if !auth.Authenticates(UserClaims(r), auth.AdminGrant) {
ape.RenderErr(w, problems.Unauthorized())
return
}

evType, err := EventTypesQ(r).Get(req.Data.Attributes.Name)
if err != nil {
Log(r).WithError(err).Error("Failed to get event type by name")
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"net/http"

"github.com/rarimo/decentralized-auth-svc/resources"
"github.com/rarimo/geo-auth-svc/pkg/hmacsig"
"github.com/rarimo/geo-auth-svc/resources"
"github.com/rarimo/geo-points-svc/internal/config"
"github.com/rarimo/geo-points-svc/internal/data"
"github.com/rarimo/geo-points-svc/internal/data/evtypes"
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/fulfill_qr_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"

"github.com/labstack/gommon/log"
"github.com/rarimo/decentralized-auth-svc/pkg/auth"
"github.com/rarimo/geo-auth-svc/pkg/auth"
"github.com/rarimo/geo-points-svc/internal/data"
"github.com/rarimo/geo-points-svc/internal/data/evtypes"
"github.com/rarimo/geo-points-svc/internal/service/requests"
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/get_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package handlers
import (
"net/http"

"github.com/rarimo/decentralized-auth-svc/pkg/auth"
"github.com/rarimo/geo-auth-svc/pkg/auth"
"github.com/rarimo/geo-points-svc/internal/data"
"github.com/rarimo/geo-points-svc/internal/service/requests"
"github.com/rarimo/geo-points-svc/resources"
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/get_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package handlers
import (
"net/http"

"github.com/rarimo/decentralized-auth-svc/pkg/auth"
"github.com/rarimo/geo-auth-svc/pkg/auth"
"github.com/rarimo/geo-points-svc/internal/data/evtypes"
"github.com/rarimo/geo-points-svc/internal/service/requests"
"github.com/rarimo/geo-points-svc/resources"
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/list_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"net/http"

"github.com/rarimo/decentralized-auth-svc/pkg/auth"
"github.com/rarimo/geo-auth-svc/pkg/auth"
"github.com/rarimo/geo-points-svc/internal/data"
"github.com/rarimo/geo-points-svc/internal/data/evtypes"
"github.com/rarimo/geo-points-svc/internal/data/evtypes/models"
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"net/http"

"github.com/rarimo/decentralized-auth-svc/pkg/auth"
"github.com/rarimo/geo-auth-svc/pkg/auth"
"github.com/rarimo/geo-points-svc/internal/data/pg"
"gitlab.com/distributed_lab/ape"
"gitlab.com/distributed_lab/ape/problems"
Expand Down
6 changes: 6 additions & 0 deletions internal/service/handlers/update_event_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"net/http"

"github.com/rarimo/geo-auth-svc/pkg/auth"
"github.com/rarimo/geo-points-svc/internal/data/evtypes/models"
"github.com/rarimo/geo-points-svc/internal/service/requests"
"github.com/rarimo/geo-points-svc/resources"
Expand All @@ -17,6 +18,11 @@ func UpdateEventType(w http.ResponseWriter, r *http.Request) {
return
}

if !auth.Authenticates(UserClaims(r), auth.AdminGrant) {
ape.RenderErr(w, problems.Unauthorized())
return
}

evType := EventTypes(r).Get(req.Data.Attributes.Name)
if evType == nil {
evType, err = EventTypesQ(r).Get(req.Data.Attributes.Name)
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/verify_passport.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/google/jsonapi"
zkptypes "github.com/iden3/go-rapidsnark/types"
"github.com/rarimo/decentralized-auth-svc/pkg/auth"
"github.com/rarimo/geo-auth-svc/pkg/auth"
"github.com/rarimo/geo-points-svc/internal/data"
"github.com/rarimo/geo-points-svc/internal/data/evtypes"
"github.com/rarimo/geo-points-svc/internal/data/evtypes/models"
Expand Down
1 change: 0 additions & 1 deletion internal/service/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func Run(ctx context.Context, cfg config.Config) {
r.Get("/balances", handlers.Leaderboard)
r.Route("/event_types", func(r chi.Router) {
r.Get("/", handlers.ListEventTypes)
// TODO: add admin auth to create/update endpoints
r.Post("/", handlers.CreateEventType)
r.Get("/{name}", handlers.GetEventType)
r.Patch("/{name}", handlers.UpdateEventType)
Expand Down

0 comments on commit 6bd9357

Please sign in to comment.