-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MF-1008 - Make token duration configurable #1550
Changes from all commits
d01b78f
5d8af63
a81d03f
b5fa738
18d16f0
a165985
daf6c5c
26946d5
672671d
84d302e
1430651
2940511
677b5ab
e372401
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
kitprometheus "github.com/go-kit/kit/metrics/prometheus" | ||
"github.com/jmoiron/sqlx" | ||
|
@@ -52,6 +53,7 @@ const ( | |
defKetoHost = "mainflux-keto" | ||
defKetoWritePort = "4467" | ||
defKetoReadPort = "4466" | ||
defLoginDuration = "10h" | ||
|
||
envLogLevel = "MF_AUTH_LOG_LEVEL" | ||
envDBHost = "MF_AUTH_DB_HOST" | ||
|
@@ -72,6 +74,7 @@ const ( | |
envKetoHost = "MF_KETO_HOST" | ||
envKetoWritePort = "MF_KETO_WRITE_REMOTE_PORT" | ||
envKetoReadPort = "MF_KETO_READ_REMOTE_PORT" | ||
envLoginDuration = "MF_AUTH_LOGIN_TOKEN_DURATION" | ||
) | ||
|
||
type config struct { | ||
|
@@ -87,6 +90,7 @@ type config struct { | |
ketoHost string | ||
ketoWritePort string | ||
ketoReadPort string | ||
loginDuration time.Duration | ||
} | ||
|
||
type tokenConfig struct { | ||
|
@@ -113,7 +117,7 @@ func main() { | |
|
||
readerConn, writerConn := initKeto(cfg.ketoHost, cfg.ketoReadPort, cfg.ketoWritePort, logger) | ||
|
||
svc := newService(db, dbTracer, cfg.secret, logger, readerConn, writerConn) | ||
svc := newService(db, dbTracer, cfg.secret, logger, readerConn, writerConn, cfg.loginDuration) | ||
errs := make(chan error, 2) | ||
|
||
go startHTTPServer(tracer, svc, cfg.httpPort, cfg.serverCert, cfg.serverKey, logger, errs) | ||
|
@@ -142,6 +146,11 @@ func loadConfig() config { | |
SSLRootCert: mainflux.Env(envDBSSLRootCert, defDBSSLRootCert), | ||
} | ||
|
||
loginDuration, err := time.ParseDuration(mainflux.Env(envLoginDuration, defLoginDuration)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of panic can we use defLoginDuration value Like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's is one way to do it. TBH, since |
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return config{ | ||
logLevel: mainflux.Env(envLogLevel, defLogLevel), | ||
dbConfig: dbConfig, | ||
|
@@ -154,6 +163,7 @@ func loadConfig() config { | |
ketoHost: mainflux.Env(envKetoHost, defKetoHost), | ||
ketoReadPort: mainflux.Env(envKetoReadPort, defKetoReadPort), | ||
ketoWritePort: mainflux.Env(envKetoWritePort, defKetoWritePort), | ||
loginDuration: loginDuration, | ||
} | ||
|
||
} | ||
|
@@ -207,7 +217,7 @@ func connectToDB(dbConfig postgres.Config, logger logger.Logger) *sqlx.DB { | |
return db | ||
} | ||
|
||
func newService(db *sqlx.DB, tracer opentracing.Tracer, secret string, logger logger.Logger, readerConn, writerConn *grpc.ClientConn) auth.Service { | ||
func newService(db *sqlx.DB, tracer opentracing.Tracer, secret string, logger logger.Logger, readerConn, writerConn *grpc.ClientConn, duration time.Duration) auth.Service { | ||
database := postgres.NewDatabase(db) | ||
keysRepo := tracing.New(postgres.New(database), tracer) | ||
|
||
|
@@ -219,7 +229,7 @@ func newService(db *sqlx.DB, tracer opentracing.Tracer, secret string, logger lo | |
idProvider := uuid.New() | ||
t := jwt.New(secret) | ||
|
||
svc := auth.New(keysRepo, groupsRepo, idProvider, t, pa) | ||
svc := auth.New(keysRepo, groupsRepo, idProvider, t, pa, duration) | ||
svc = api.LoggingMiddleware(svc, logger) | ||
svc = api.MetricsMiddleware( | ||
svc, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't remove recoveryDuration, please keep using the constant for recovery duration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't being used but I have kept it back