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