diff --git a/cmd/web_server/middleware/login_session.go b/cmd/web_server/middleware/login_session.go index 3c8bb3b..c2b3431 100644 --- a/cmd/web_server/middleware/login_session.go +++ b/cmd/web_server/middleware/login_session.go @@ -1,8 +1,6 @@ package middleware import ( - "time" - "github.com/gin-gonic/gin" "github.com/google/uuid" auth_module "github.com/oj-lab/platform/modules/auth" @@ -10,7 +8,6 @@ import ( ) const ( - loginSessionCookieMaxAge = time.Hour * 24 * 7 loginSessionKeyIdCookieName = "LS_KEY_ID" loginSessionKeyAccountCookieName = "LS_KEY_ACCOUNT" loginSessionGinCtxKey = "login_session" @@ -70,7 +67,7 @@ func GetLoginSessionFromGinCtx(ginCtx *gin.Context) (*auth_module.LoginSession, func SetLoginSessionKeyCookie(ginCtx *gin.Context, key auth_module.LoginSessionKey) { ginCtx.SetCookie(loginSessionKeyAccountCookieName, key.Account, - int(loginSessionCookieMaxAge.Seconds()), "/", "", false, true) + int(auth_module.LoginSessionDuration.Seconds()), "/", "", false, true) ginCtx.SetCookie(loginSessionKeyIdCookieName, key.Id.String(), - int(loginSessionCookieMaxAge.Seconds()), "/", "", false, true) + int(auth_module.LoginSessionDuration.Seconds()), "/", "", false, true) } diff --git a/config.toml b/config.toml index b2e1608..fc0a571 100644 --- a/config.toml +++ b/config.toml @@ -29,7 +29,7 @@ port = 50051 [minio] endpoint = "localhost:9000" -accessKeyID = "minio-root-user" -secretAccessKey = "minio-root-password" +access_key_id = "minio-root-user" +secret_access_key = "minio-root-password" useSSL = false -bucketName = "oj-lab-problem-package" +bucket_name = "oj-lab-problem-package" diff --git a/modules/agent/minio/client.go b/modules/agent/minio/client.go index daea446..9627ad5 100644 --- a/modules/agent/minio/client.go +++ b/modules/agent/minio/client.go @@ -11,11 +11,11 @@ import ( const ( minioEndpointProp = "minio.endpoint" - minioAccessKeyProp = "minio.accessKeyID" - minioSecretAccessKeyProp = "minio.secretAccessKey" - minioUseSSLProp = "minio.useSSL" + minioAccessKeyProp = "minio.access_key_id" + minioSecretAccessKeyProp = "minio.secret_access_key" + minioUseSSLProp = "minio.use_ssl" minioRegionProp = "minio.region" - minioBucketNameProp = "minio.bucketName" + minioBucketNameProp = "minio.bucket_name" ) var ( diff --git a/modules/auth/login_session.go b/modules/auth/login_session.go index 680ec4d..6ff81de 100644 --- a/modules/auth/login_session.go +++ b/modules/auth/login_session.go @@ -3,10 +3,23 @@ package auth_module import ( "context" "encoding/json" + "time" "github.com/google/uuid" + config_module "github.com/oj-lab/platform/modules/config" ) +const defaultLoginSessionDuration = time.Hour * 24 * 7 + +var LoginSessionDuration time.Duration + +func init() { + LoginSessionDuration = config_module.AppConfig().GetDuration("service.login_session_duration") + if LoginSessionDuration == 0 { + LoginSessionDuration = defaultLoginSessionDuration + } +} + type LoginSessionKey struct { Account string Id uuid.UUID diff --git a/modules/auth/redis.go b/modules/auth/redis.go index d1fdfc0..1b8545e 100644 --- a/modules/auth/redis.go +++ b/modules/auth/redis.go @@ -3,7 +3,6 @@ package auth_module import ( "context" "fmt" - "time" redis_agent "github.com/oj-lab/platform/modules/agent/redis" log_module "github.com/oj-lab/platform/modules/log" @@ -11,7 +10,6 @@ import ( ) const loginSessionKeyFormat = "LS_%s_%s" // "LS__" -const loginSessionDuration = time.Minute * 15 func getLoginSessionRedisKey(key LoginSessionKey) string { return fmt.Sprintf(loginSessionKeyFormat, key.Account, key.Id.String()) @@ -25,7 +23,7 @@ func SetLoginSession(ctx context.Context, key LoginSessionKey, data LoginSession return err } // TODO: Watch Redis JSON SET usage, currently not support atomic SETEX - err = redisClient.Set(ctx, getLoginSessionRedisKey(key), value, loginSessionDuration).Err() + err = redisClient.Set(ctx, getLoginSessionRedisKey(key), value, LoginSessionDuration).Err() if err != nil { return err }