mirror of
https://github.com/cuigh/swirl
synced 2025-04-10 15:35:38 +00:00
Allow customizing auth expiration
This commit is contained in:
parent
462b6bed2d
commit
93be76045c
9
main.go
9
main.go
@ -5,7 +5,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/cuigh/auxo/app"
|
||||
"github.com/cuigh/auxo/app/flag"
|
||||
@ -32,7 +31,11 @@ func main() {
|
||||
app.Version = "0.7.1"
|
||||
app.Desc = "A web management UI for Docker, focused on swarm cluster"
|
||||
app.Action = func(ctx *app.Context) {
|
||||
misc.LoadOptions()
|
||||
err := config.UnmarshalOption("swirl", &misc.Options)
|
||||
if err != nil {
|
||||
log.Get(app.Name).Error("Load options failed: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
setting, err := biz.Setting.Get()
|
||||
if err != nil {
|
||||
@ -85,7 +88,7 @@ func server(setting *model.Setting) *web.Server {
|
||||
// create biz group
|
||||
form := &auth.Form{
|
||||
Identifier: security.Identifier,
|
||||
Timeout: time.Minute * 30,
|
||||
Timeout: misc.Options.AuthTimeout,
|
||||
SlidingExpiration: true,
|
||||
}
|
||||
g := ws.Group("", form, filter.NewAuthorizer(security.Checker))
|
||||
|
20
misc/misc.go
20
misc/misc.go
@ -1,6 +1,8 @@
|
||||
package misc
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/cuigh/auxo/config"
|
||||
)
|
||||
|
||||
@ -8,9 +10,11 @@ const (
|
||||
keyDockerEndpoint = "swirl.docker_endpoint"
|
||||
keyDBType = "swirl.db_type"
|
||||
keyDBAddress = "swirl.db_address"
|
||||
keyAuthTimeout = "swirl.auth_timeout"
|
||||
envDockerEndpoint = "DOCKER_ENDPOINT"
|
||||
envDBType = "DB_TYPE"
|
||||
envDBAddress = "DB_ADDRESS"
|
||||
envAuthTimeout = "AUTH_TIMEOUT"
|
||||
)
|
||||
|
||||
// TimeZones holds some commonly used time-zones.
|
||||
@ -45,20 +49,22 @@ var TimeZones = []struct {
|
||||
{"GMT-12", -12 * 60 * 60},
|
||||
}
|
||||
|
||||
// Options holds custom options of swirl.
|
||||
var Options = &struct {
|
||||
DockerEndpoint string
|
||||
DBType string
|
||||
DBAddress string
|
||||
}{}
|
||||
AuthTimeout time.Duration
|
||||
}{
|
||||
DBType: "mongo",
|
||||
DBAddress: "localhost:27017/swirl",
|
||||
AuthTimeout: 30 * time.Minute,
|
||||
}
|
||||
|
||||
// BindOptions binds options to environment variables.
|
||||
func BindOptions() {
|
||||
config.BindEnv(keyDockerEndpoint, envDockerEndpoint)
|
||||
config.BindEnv(keyDBType, envDBType)
|
||||
config.BindEnv(keyDBAddress, envDBAddress)
|
||||
}
|
||||
|
||||
func LoadOptions() {
|
||||
Options.DockerEndpoint = config.GetString(keyDockerEndpoint)
|
||||
Options.DBType = config.GetString(keyDBType)
|
||||
Options.DBAddress = config.GetString(keyDBAddress)
|
||||
config.BindEnv(keyAuthTimeout, envAuthTimeout)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user