Skip to content

Commit

Permalink
Merge pull request #232 from iegomez/cleanup/update-go-and-dependencies
Browse files Browse the repository at this point in the history
Update go and dependencies.
  • Loading branch information
iegomez authored Jun 5, 2022
2 parents 98d8b4a + 05b64b5 commit e051c0b
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 220 deletions.
27 changes: 6 additions & 21 deletions backends/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package backends

import (
"context"
"errors"
"fmt"
"strconv"
"strings"
Expand All @@ -24,17 +23,15 @@ type RedisClient interface {
Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *goredis.StatusCmd
SAdd(ctx context.Context, key string, members ...interface{}) *goredis.IntCmd
Expire(ctx context.Context, key string, expiration time.Duration) *goredis.BoolCmd
ReloadState(ctx context.Context) error
ReloadState(ctx context.Context)
}

type SingleRedisClient struct {
*goredis.Client
}

var SingleClientError = errors.New("unsupported reload state operation for Redis single client")

func (c SingleRedisClient) ReloadState(ctx context.Context) error {
return SingleClientError
func (c SingleRedisClient) ReloadState(ctx context.Context) {
// NO-OP
}

type Redis struct {
Expand Down Expand Up @@ -147,11 +144,7 @@ func (o Redis) GetUser(username, password, _ string) (bool, error) {

//If using Redis Cluster, reload state and attempt once more.
if isMovedError(err) {
err = o.conn.ReloadState(o.ctx)
if err != nil {
log.Debugf("redis reload state error: %s", err)
return false, err
}
o.conn.ReloadState(o.ctx)

//Retry once.
ok, err = o.getUser(username, password)
Expand Down Expand Up @@ -191,11 +184,7 @@ func (o Redis) GetSuperuser(username string) (bool, error) {

//If using Redis Cluster, reload state and attempt once more.
if isMovedError(err) {
err = o.conn.ReloadState(o.ctx)
if err != nil {
log.Debugf("redis reload state error: %s", err)
return false, err
}
o.conn.ReloadState(o.ctx)

//Retry once.
ok, err = o.getSuperuser(username)
Expand Down Expand Up @@ -231,11 +220,7 @@ func (o Redis) CheckAcl(username, topic, clientid string, acc int32) (bool, erro

//If using Redis Cluster, reload state and attempt once more.
if isMovedError(err) {
err = o.conn.ReloadState(o.ctx)
if err != nil {
log.Debugf("redis reload state error: %s", err)
return false, err
}
o.conn.ReloadState(o.ctx)

//Retry once.
ok, err = o.checkAcl(username, topic, clientid, acc)
Expand Down
11 changes: 2 additions & 9 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,7 @@ func (s *redisStore) checkRecord(ctx context.Context, record string, expirationT
}

if isMovedError(err) {
err = s.client.ReloadState(ctx)
// This should not happen, ever!
if err == bes.SingleClientError {
return false, false
}
s.client.ReloadState(ctx)

//Retry once.
present, granted, err = s.getAndRefresh(ctx, record, expirationTime)
Expand Down Expand Up @@ -299,10 +295,7 @@ func (s *redisStore) setRecord(ctx context.Context, record, granted string, expi

// If record was moved, reload and retry.
if isMovedError(err) {
err = s.client.ReloadState(ctx)
if err != nil {
return err
}
s.client.ReloadState(ctx)

//Retry once.
err = s.set(ctx, record, granted, expirationTime)
Expand Down
60 changes: 39 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
module github.com/iegomez/mosquitto-go-auth

go 1.12
go 1.18

require (
github.com/go-redis/redis/v8 v8.0.0-beta.2
github.com/go-sql-driver/mysql v1.5.0
github.com/golang-jwt/jwt v3.2.1+incompatible
github.com/golang/protobuf v1.4.2
github.com/gopherjs/gopherjs v0.0.0-20190328170749-bb2674552d8f // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
github.com/jmoiron/sqlx v1.3.4
github.com/klauspost/compress v1.10.6 // indirect
github.com/lib/pq v1.5.2
github.com/go-redis/redis/v8 v8.11.5
github.com/go-sql-driver/mysql v1.6.0
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/protobuf v1.5.2
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/jmoiron/sqlx v1.3.5
github.com/lib/pq v1.10.6
github.com/mattn/go-sqlite3 v2.0.3+incompatible
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/robertkrimen/otto v0.0.0-20200922221731-ef014fd054ac
github.com/sirupsen/logrus v1.6.0
github.com/smartystreets/assertions v0.0.0-20190401211740-f487f9de1cd3 // indirect
github.com/robertkrimen/otto v0.0.0-20211024170158-b87d35c0b86f
github.com/sirupsen/logrus v1.8.1
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a
github.com/stretchr/testify v1.6.1
go.mongodb.org/mongo-driver v1.5.1
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 // indirect
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a // indirect
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 // indirect
google.golang.org/genproto v0.0.0-20200521103424-e9a78aa275b7 // indirect
google.golang.org/grpc v1.29.1
github.com/stretchr/testify v1.7.0
go.mongodb.org/mongo-driver v1.9.1
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
google.golang.org/grpc v1.47.0
)

require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gopherjs/gopherjs v0.0.0-20190328170749-bb2674552d8f // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/klauspost/compress v1.15.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/smartystreets/assertions v0.0.0-20190401211740-f487f9de1cd3 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
golang.org/x/net v0.0.0-20220531201128-c960675eff93 // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20220602131408-e326c6e8e9c8 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
Loading

0 comments on commit e051c0b

Please sign in to comment.