Documentation ¶
Index ¶
- type RequestData
- type Server
- type Session
- type SessionRepo
- type SessionRepoSqlite3
- type ShoeClient
- func (c *ShoeClient) Authenticate(username, password string) (string, error)
- func (c *ShoeClient) ChangePasswd(username, password, token string) (err error)
- func (c *ShoeClient) CreateUser(username, password string) (err error)
- func (c *ShoeClient) Logout(token string) error
- func (c *ShoeClient) Request(endpoint string, data *RequestData) (*http.Response, error)
- func (c *ShoeClient) RequestSecret() (string, error)
- type User
- type UserRepo
- type UserRepoSqlite3
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RequestData ¶
RequestData is our general purpose container for data sent between client and server. Different field may be used for different endpoints.
func ParseRequestData ¶
func ParseRequestData(body io.ReadCloser) (*RequestData, error)
ParseRequestData is used to unmarshal data in requests and responses.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the handle on the main server instance
func NewServer ¶
func NewServer(u UserRepo, s SessionRepo) *Server
NewServer correctly instantiates a new server
type Session ¶
type Session struct { ID int `db:"id"` UserID int `db:"userid"` Token string `db:"token"` Origin string `db:"origin"` Expires string `db:"expires"` // time of expiration in string form }
Session reflects a session entry in the database
type SessionRepo ¶
type SessionRepo interface { Create(s *Session) error DeleteByToken(s *Session) error GetByID(s *Session) error GetByToken(s *Session) error }
SessionRepo defines the basic interface for managing authentication sessions
type SessionRepoSqlite3 ¶
type SessionRepoSqlite3 struct {
// contains filtered or unexported fields
}
SessionRepoSqlite3 fulfills SessionRepo using a Sqlite3 database
func NewSessionRepoSqlite3 ¶
func NewSessionRepoSqlite3(db *sqlx.DB) (*SessionRepoSqlite3, error)
NewSessionRepoSqlite3 prepares a repo given a sqlite db handle
func (*SessionRepoSqlite3) Create ¶
func (repo *SessionRepoSqlite3) Create(s *Session) error
Create tries to insert a session and fills in the ID of the provided Session struct
func (*SessionRepoSqlite3) DeleteByToken ¶
func (repo *SessionRepoSqlite3) DeleteByToken(s *Session) (err error)
Delete deletes the given session using the ID field
func (*SessionRepoSqlite3) GetByID ¶
func (repo *SessionRepoSqlite3) GetByID(s *Session) (err error)
GetByID fills the passed Session struct's fields using the ID field, which must be filled in
func (*SessionRepoSqlite3) GetByToken ¶
func (repo *SessionRepoSqlite3) GetByToken(s *Session) (err error)
GetByID fills the passed Session struct's fields using the ID field, which must be filled in
type ShoeClient ¶
type ShoeClient struct {
// contains filtered or unexported fields
}
ShoeClient is a convenience wrapper around http.Client
func NewShoeClient ¶
func NewShoeClient(host string, CA []byte, skipVerify bool) *ShoeClient
NewShoeClient configures a ShoeClient for communicating with a ShoeServer
func (*ShoeClient) Authenticate ¶
func (c *ShoeClient) Authenticate(username, password string) (string, error)
func (*ShoeClient) ChangePasswd ¶
func (c *ShoeClient) ChangePasswd(username, password, token string) (err error)
func (*ShoeClient) CreateUser ¶
func (c *ShoeClient) CreateUser(username, password string) (err error)
func (*ShoeClient) Logout ¶
func (c *ShoeClient) Logout(token string) error
func (*ShoeClient) Request ¶
func (c *ShoeClient) Request(endpoint string, data *RequestData) (*http.Response, error)
RequestSecret requests secrets from a ShoeServer
func (*ShoeClient) RequestSecret ¶
func (c *ShoeClient) RequestSecret() (string, error)
RequestSecret requests secrets from a ShoeServer
type User ¶
type User struct { ID int `db:"id"` Username string `db:"username"` Password string `db:"password"` Salt string `db:"salt"` }
User reflects a user entry in the database This implementation doesn't actually use the salt field because of the bcrypt package provided by Go.
type UserRepo ¶
type UserRepo interface { CreateUser(user *User) error UpdateUserPasswd(user *User) error GetUserByID(user *User) error GetUserByUsername(user *User) error }
UserRepo is a general interface definition for getting persistent user data
type UserRepoSqlite3 ¶
type UserRepoSqlite3 struct {
// contains filtered or unexported fields
}
UserRepoSqlite3 fulfills UserRepo using a Sqlite3 database
func NewUserRepoSqlite3 ¶
func NewUserRepoSqlite3(db *sqlx.DB) (*UserRepoSqlite3, error)
NewUserRepoSqlite3 prepares a repo given a sqlite db handle
func (*UserRepoSqlite3) CreateUser ¶
func (repo *UserRepoSqlite3) CreateUser(s *User) error
CreateUser tries to insert a user and fills in the ID of the provided user
func (*UserRepoSqlite3) GetUserByID ¶
func (repo *UserRepoSqlite3) GetUserByID(s *User) (err error)
GetUserByID fills the passed User struct's fields using the ID field, which must be filled in
func (*UserRepoSqlite3) GetUserByUsername ¶
func (repo *UserRepoSqlite3) GetUserByUsername(s *User) (err error)
GetUserByUsername fills the passed User struct's fields using the username field, which must be filled in
func (*UserRepoSqlite3) UpdateUserPasswd ¶
func (repo *UserRepoSqlite3) UpdateUserPasswd(s *User) (err error)
UpdateUserPasswd attempts to update the given user's corresponding password and salt