summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimport/session_store.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/helsinki.at/rhimport/session_store.go')
-rw-r--r--src/helsinki.at/rhimport/session_store.go52
1 files changed, 30 insertions, 22 deletions
diff --git a/src/helsinki.at/rhimport/session_store.go b/src/helsinki.at/rhimport/session_store.go
index 43b5d23..b7ea3d9 100644
--- a/src/helsinki.at/rhimport/session_store.go
+++ b/src/helsinki.at/rhimport/session_store.go
@@ -28,13 +28,15 @@ import (
"encoding/base32"
"fmt"
"github.com/satori/go.uuid"
+ "net/http"
"strings"
)
type newSessionResponse struct {
- id string
- session *SessionChan
- err error
+ id string
+ session *SessionChan
+ responsecode int
+ errorstring string
}
type newSessionRequest struct {
@@ -43,8 +45,9 @@ type newSessionRequest struct {
}
type getSessionResponse struct {
- session *SessionChan
- err error
+ session *SessionChan
+ responsecode int
+ errorstring string
}
type getSessionRequest struct {
@@ -54,7 +57,8 @@ type getSessionRequest struct {
}
type removeSessionResponse struct {
- err error
+ responsecode int
+ errorstring string
}
type removeSessionRequest struct {
@@ -73,12 +77,16 @@ type SessionStore struct {
}
func (self *SessionStore) new(ctx *ImportContext) (resp newSessionResponse) {
+ resp.responsecode = http.StatusOK
+ resp.errorstring = "OK"
if !ctx.Trusted {
if ok, err := ctx.rddb.CheckPassword(ctx.UserName, ctx.Password); err != nil {
- resp.err = err
+ resp.responsecode = http.StatusInternalServerError
+ resp.errorstring = err.Error()
return
} else if !ok {
- resp.err = fmt.Errorf("invalid username and/or password")
+ resp.responsecode = http.StatusUnauthorized
+ resp.errorstring = "invalid username and/or password"
return
}
}
@@ -94,15 +102,20 @@ func (self *SessionStore) new(ctx *ImportContext) (resp newSessionResponse) {
}
func (self *SessionStore) get(user, id string) (resp getSessionResponse) {
+ resp.responsecode = http.StatusOK
+ resp.errorstring = "OK"
if session, exists := self.store[user][id]; exists {
resp.session = session.getInterface()
} else {
- resp.err = fmt.Errorf("SessionStore: session '%s/%s' not found", user, id)
+ resp.responsecode = http.StatusNotFound
+ resp.errorstring = fmt.Sprintf("SessionStore: session '%s/%s' not found", user, id)
}
return
}
func (self *SessionStore) remove(user, id string) (resp removeSessionResponse) {
+ resp.responsecode = http.StatusOK
+ resp.errorstring = "OK"
if session, exists := self.store[user][id]; exists {
go session.Cleanup() // cleanup could take a while -> don't block all the other stuff
delete(self.store[user], id)
@@ -114,7 +127,8 @@ func (self *SessionStore) remove(user, id string) (resp removeSessionResponse) {
}
}
} else {
- resp.err = fmt.Errorf("SessionStore: session '%s/%s' not found", user, id)
+ resp.responsecode = http.StatusNotFound
+ resp.errorstring = fmt.Sprintf("SessionStore: session '%s/%s' not found", user, id)
}
return
}
@@ -144,7 +158,7 @@ type SessionStoreChan struct {
removeChan chan<- removeSessionRequest
}
-func (self *SessionStoreChan) New(ctx *ImportContext) (string, *SessionChan, error) {
+func (self *SessionStoreChan) New(ctx *ImportContext) (string, *SessionChan, int, string) {
res_ch := make(chan newSessionResponse)
req := newSessionRequest{}
req.ctx = ctx
@@ -152,13 +166,10 @@ func (self *SessionStoreChan) New(ctx *ImportContext) (string, *SessionChan, err
self.newChan <- req
res := <-res_ch
- if res.err != nil {
- return "", nil, res.err
- }
- return res.id, res.session, nil
+ return res.id, res.session, res.responsecode, res.errorstring
}
-func (self *SessionStoreChan) Get(user, id string) (*SessionChan, error) {
+func (self *SessionStoreChan) Get(user, id string) (*SessionChan, int, string) {
res_ch := make(chan getSessionResponse)
req := getSessionRequest{}
req.user = user
@@ -167,13 +178,10 @@ func (self *SessionStoreChan) Get(user, id string) (*SessionChan, error) {
self.getChan <- req
res := <-res_ch
- if res.err != nil {
- return nil, res.err
- }
- return res.session, nil
+ return res.session, res.responsecode, res.errorstring
}
-func (self *SessionStoreChan) Remove(user, id string) error {
+func (self *SessionStoreChan) Remove(user, id string) (int, string) {
res_ch := make(chan removeSessionResponse)
req := removeSessionRequest{}
req.user = user
@@ -182,7 +190,7 @@ func (self *SessionStoreChan) Remove(user, id string) error {
self.removeChan <- req
res := <-res_ch
- return res.err
+ return res.responsecode, res.errorstring
}
func (self *SessionStore) GetInterface() *SessionStoreChan {