aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2022-10-25 13:40:49 +0000
committerr <r@freesoftwareextremist.com>2022-10-25 14:14:46 +0000
commit887ed241d64ba5db3fd3d87194fb5595e5ad7d73 (patch)
tree40fe52d870ac31dce139ceb11b40e0161bf10946 /util
parentb4ccde54a70495937a5667950363cbf2c24d40bf (diff)
downloadbloat-887ed241d64ba5db3fd3d87194fb5595e5ad7d73.tar.gz
bloat-887ed241d64ba5db3fd3d87194fb5595e5ad7d73.zip
Use cookies for session storage
Remove the server side session storage and store all the session related data in the client side cookies. This decreases the exposure of the auth tokens. It also simplifies the installation process as bloat no longer requires write access to the filesystem. This is a breaking change, all the existing sessions will stop working.
Diffstat (limited to 'util')
-rw-r--r--util/kv.go91
1 files changed, 0 insertions, 91 deletions
diff --git a/util/kv.go b/util/kv.go
deleted file mode 100644
index df61654..0000000
--- a/util/kv.go
+++ /dev/null
@@ -1,91 +0,0 @@
-package util
-
-import (
- "errors"
- "io/ioutil"
- "os"
- "path/filepath"
- "strings"
- "sync"
-)
-
-var (
- errInvalidKey = errors.New("invalid key")
- errNoSuchKey = errors.New("no such key")
-)
-
-type Database struct {
- cache map[string][]byte
- basedir string
- m sync.RWMutex
-}
-
-func NewDatabse(basedir string) (db *Database, err error) {
- err = os.Mkdir(basedir, 0755)
- if err != nil && !os.IsExist(err) {
- return
- }
-
- return &Database{
- cache: make(map[string][]byte),
- basedir: basedir,
- }, nil
-}
-
-func (db *Database) Set(key string, val []byte) (err error) {
- if len(key) < 1 || strings.ContainsRune(key, os.PathSeparator) {
- return errInvalidKey
- }
-
- err = ioutil.WriteFile(filepath.Join(db.basedir, key), val, 0644)
- if err != nil {
- return
- }
-
- db.m.Lock()
- db.cache[key] = val
- db.m.Unlock()
-
- return
-}
-
-func (db *Database) Get(key string) (val []byte, err error) {
- if len(key) < 1 || strings.ContainsRune(key, os.PathSeparator) {
- return nil, errInvalidKey
- }
-
- db.m.RLock()
- data, ok := db.cache[key]
- db.m.RUnlock()
-
- if !ok {
- data, err = ioutil.ReadFile(filepath.Join(db.basedir, key))
- if err != nil {
- err = errNoSuchKey
- return nil, err
- }
-
- db.m.Lock()
- db.cache[key] = data
- db.m.Unlock()
- }
-
- val = make([]byte, len(data))
- copy(val, data)
-
- return
-}
-
-func (db *Database) Remove(key string) {
- if len(key) < 1 || strings.ContainsRune(key, os.PathSeparator) {
- return
- }
-
- os.Remove(filepath.Join(db.basedir, key))
-
- db.m.Lock()
- delete(db.cache, key)
- db.m.Unlock()
-
- return
-}