From b89616a904cc6021386433ac4116a8e3e343ce79 Mon Sep 17 00:00:00 2001 From: Las Zenow Date: Thu, 3 Dec 2020 15:43:47 +0000 Subject: [PATCH] Set the session key from an env variable --- README.md | 11 +++++++++-- lib/session.go | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 986d400..7968a0a 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,19 @@ $ echo "CREATE EXTENSION pg_trgm;"|psql trantor Now you can install Trantor itself: ``` -# go get gitlab.com/trantor/trantor +$ git clone gitlab.com/trantor/trantor +$ cd trantor +$ go build +``` + +Generate a random session key: +``` +$ base64 /dev/random | head -c 50 ``` You can run it (using `/var/lib/trantor` for storage): ``` -# $GOPATH/bin/trantor -assets $GOPATH/src/pkg/gitlab.com/trantor/trantor/ -store /var/lib/trantor +$ SESSION_KEY= ./trantor -store /var/lib/trantor ``` The first time you run it, the database will be initialized. To initialize an admin user, include the -set-admin-user and -set-admin-pass variables diff --git a/lib/session.go b/lib/session.go index 1e83167..b3087b4 100644 --- a/lib/session.go +++ b/lib/session.go @@ -3,13 +3,14 @@ package trantor import ( "encoding/hex" "net/http" + "os" "github.com/gorilla/securecookie" "github.com/gorilla/sessions" "gitlab.com/trantor/trantor/lib/database" ) -var sesStore = sessions.NewCookieStore(securecookie.GenerateRandomKey(64)) +var sesStore = sessions.NewCookieStore([]byte(os.Getenv("SESSION_KEY"))) type Notification struct { Title string