Skip to content

Commit

Permalink
feat: token timeout in configuration file (#262)
Browse files Browse the repository at this point in the history
* feat: token timeout in configuration file

* docker integration
  • Loading branch information
pedrofaria authored Jan 20, 2024
1 parent 140cbcf commit 8484245
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM golang:1.21.1-bullseye
FROM golang:1.21-bullseye

RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y git build-essential nodejs zip
&& apt-get install -y git build-essential nodejs="16.*" zip

RUN go install golang.org/x/tools/gopls@latest \
&& go install github.com/go-delve/delve/cmd/dlv@latest \
Expand Down
1 change: 1 addition & 0 deletions build/docker/docker_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ webserver:
read_timeout: 5

auth:
timeout: $ACCWEB_TIMEOUT
admin_password: $ACCWEB_ADMIN_PASSWORD
moderator_password: $ACCWEB_MOD_PASSWORD
read_only_password: $ACCWEB_RO_PASSWORD
Expand Down
4 changes: 4 additions & 0 deletions build/sample_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ webserver:
read_timeout: 5

auth:
# Set the session duration (Default value is 20 minutes).
# duration documentation can be found at https://pkg.go.dev/time#ParseDuration
timeout: 20m

# Set the admin, moderator and read only user password.
# accweb won't start without an admin password.
admin_password: admin-password
Expand Down
1 change: 1 addition & 0 deletions dev_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ auth:
admin_password: admin
moderator_password: mod
read_only_password: ro
timeout: 5h
acc:
server_path: "/app/fake-accserver/build/osx"
server_exe: accServer.exe
Expand Down
2 changes: 1 addition & 1 deletion internal/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func setupAuthRouters(r *gin.Engine, config *cfg.Config) *jwt.GinJWTMiddleware {
SigningAlgorithm: "RS256",
PrivKeyFile: config.Auth.PrivateKeyPath,
PubKeyFile: config.Auth.PublicKeyPath,
Timeout: 20 * time.Minute,
Timeout: *config.Auth.Timeout,
MaxRefresh: time.Hour,
IdentityKey: identityKey,
PayloadFunc: func(data interface{}) jwt.MapClaims {
Expand Down
21 changes: 14 additions & 7 deletions internal/pkg/cfg/cfg.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package cfg

import (
"io/ioutil"
"os"
"time"

"github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -40,11 +41,12 @@ type CORS struct {
}

type Auth struct {
PublicKeyPath string `yaml:"public_key_path"`
PrivateKeyPath string `yaml:"private_key_path"`
AdminPassword string `yaml:"admin_password"`
ModeratorPassword string `yaml:"moderator_password"`
ReadOnlyPassword string `yaml:"read_only_password"`
PublicKeyPath string `yaml:"public_key_path"`
PrivateKeyPath string `yaml:"private_key_path"`
AdminPassword string `yaml:"admin_password"`
ModeratorPassword string `yaml:"moderator_password"`
ReadOnlyPassword string `yaml:"read_only_password"`
Timeout *time.Duration `yaml:"timeout"`
}

type ACC struct {
Expand All @@ -54,7 +56,7 @@ type ACC struct {

// Load loads the application config from config.yml.
func Load(file string) *Config {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
logrus.WithError(err).Fatal("Error loading configuration file")
}
Expand All @@ -76,6 +78,11 @@ func Load(file string) *Config {
config.Auth.PublicKeyPath = "secrets/token.public"
}

if config.Auth.Timeout == nil {
m5 := 5 * time.Minute
config.Auth.Timeout = &m5
}

skipWine = config.SkipWine

return &config
Expand Down

0 comments on commit 8484245

Please sign in to comment.