1
0
mirror of https://github.com/bingohuang/docker-labs.git synced 2025-10-04 17:33:21 +08:00

Enable use of override for session timeout in hours, fix captcha bypass bug. (#51)

* - Enable use of override for session timeout. This is more useful than having to hard-code and rebuild the code for the previous 4 hour limit. Just set environmental variable and start the app.
- Future work may involve breaking down into minutes, but this is a good minimum delivery to provide value to end-user/developer.

- Fixes bug in Captcha code by introducing new landing page. This is not a new go template, it's a separate HTML file because SRP - single reponsibility principle. Happy for this to be refacted after merging commit.

- Fix for including Docker 1.12 override has been removed for later PR.

* Merge

* Reinstate 'material' JS include'

* https for JS includes

* HTTPs for JS in bypass
This commit is contained in:
Alex Ellis
2016-11-30 18:17:18 +00:00
committed by Marcos Nils
parent d3e20724e9
commit 5eda323477
6 changed files with 78 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ import (
"log"
"math"
"os"
"strconv"
"sync"
"time"
@@ -91,18 +92,35 @@ func CloseSession(s *Session) error {
return nil
}
// Todo: this handles minimum viable product and removes hard-coding of hours value :)
// For future enhance to return time.Duration and parse a string / flag.
func getExpiryHours() int {
hours := 4
override := os.Getenv("EXPIRY")
if len(override) > 0 {
value, err := strconv.Atoi(override)
if err == nil {
hours = value
}
}
return hours
}
func NewSession() (*Session, error) {
hours := getExpiryHours()
duration := time.Duration(hours) * time.Hour
s := &Session{}
s.Id = uuid.NewV4().String()
s.Instances = map[string]*Instance{}
s.CreatedAt = time.Now()
s.ExpiresAt = s.CreatedAt.Add(4 * time.Hour)
s.ExpiresAt = s.CreatedAt.Add(duration)
log.Printf("NewSession id=[%s]\n", s.Id)
sessions[s.Id] = s
// Schedule cleanup of the session
CloseSessionAfter(s, 4*time.Hour)
CloseSessionAfter(s, duration)
if err := CreateNetwork(s.Id); err != nil {
log.Println("ERROR NETWORKING")