2016-08-19 00:45:39 +00:00
|
|
|
package kolide
|
2016-08-05 17:47:41 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
2016-09-05 19:50:57 +00:00
|
|
|
"golang.org/x/net/context"
|
2016-08-05 17:47:41 +00:00
|
|
|
)
|
|
|
|
|
|
2016-08-19 00:45:39 +00:00
|
|
|
// SessionStore is the abstract interface that all session backends must
|
|
|
|
|
// conform to.
|
|
|
|
|
type SessionStore interface {
|
|
|
|
|
// Given a session key, find and return a session object or an error if one
|
|
|
|
|
// could not be found for the given key
|
2016-10-14 15:59:27 +00:00
|
|
|
SessionByKey(key string) (*Session, error)
|
2016-08-05 17:47:41 +00:00
|
|
|
|
2016-08-19 00:45:39 +00:00
|
|
|
// Given a session id, find and return a session object or an error if one
|
|
|
|
|
// could not be found for the given id
|
2016-10-14 15:59:27 +00:00
|
|
|
SessionByID(id uint) (*Session, error)
|
2016-08-05 17:47:41 +00:00
|
|
|
|
2016-08-19 00:45:39 +00:00
|
|
|
// Find all of the active sessions for a given user
|
2016-10-14 15:59:27 +00:00
|
|
|
ListSessionsForUser(id uint) ([]*Session, error)
|
2016-08-05 17:47:41 +00:00
|
|
|
|
2016-09-14 16:11:06 +00:00
|
|
|
// Store a new session struct
|
|
|
|
|
NewSession(session *Session) (*Session, error)
|
2016-08-19 00:45:39 +00:00
|
|
|
|
|
|
|
|
// Destroy the currently tracked session
|
|
|
|
|
DestroySession(session *Session) error
|
|
|
|
|
|
|
|
|
|
// Destroy all of the sessions for a given user
|
|
|
|
|
DestroyAllSessionsForUser(id uint) error
|
|
|
|
|
|
|
|
|
|
// Mark the currently tracked session as access to extend expiration
|
|
|
|
|
MarkSessionAccessed(session *Session) error
|
|
|
|
|
}
|
2016-08-05 17:47:41 +00:00
|
|
|
|
2016-09-05 19:50:57 +00:00
|
|
|
type SessionService interface {
|
2016-09-28 11:35:15 +00:00
|
|
|
Login(ctx context.Context, username, password string) (user *User, token string, err error)
|
|
|
|
|
Logout(ctx context.Context) (err error)
|
|
|
|
|
DestroySession(ctx context.Context) (err error)
|
|
|
|
|
GetInfoAboutSessionsForUser(ctx context.Context, id uint) (sessions []*Session, err error)
|
|
|
|
|
DeleteSessionsForUser(ctx context.Context, id uint) (err error)
|
|
|
|
|
GetInfoAboutSession(ctx context.Context, id uint) (session *Session, err error)
|
|
|
|
|
GetSessionByKey(ctx context.Context, key string) (session *Session, err error)
|
|
|
|
|
DeleteSession(ctx context.Context, id uint) (err error)
|
2016-09-05 19:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-05 17:47:41 +00:00
|
|
|
// Session is the model object which represents what an active session is
|
|
|
|
|
type Session struct {
|
2016-11-16 13:47:49 +00:00
|
|
|
CreateTimestamp
|
2016-11-16 17:48:43 +00:00
|
|
|
ID uint
|
2016-11-16 13:47:49 +00:00
|
|
|
AccessedAt time.Time `db:"accessed_at"`
|
2016-11-16 23:12:59 +00:00
|
|
|
UserID uint `db:"user_id"`
|
2016-11-16 17:48:43 +00:00
|
|
|
Key string
|
2016-08-05 17:47:41 +00:00
|
|
|
}
|