Documentation ¶
Overview ¶
Package service implements the gohstd web service, providing remote access to the command history supplied by gohst clients
Index ¶
- Constants
- Variables
- func Auth(inner http.Handler, route string) http.Handler
- func Authenticate(user, password string) bool
- func Authorize(user string, r *http.Request, route string) bool
- func CommandCreate(w http.ResponseWriter, r *http.Request)
- func CommandDelete(w http.ResponseWriter, r *http.Request)
- func CommandIndex(w http.ResponseWriter, r *http.Request)
- func CommandTagCreate(w http.ResponseWriter, r *http.Request)
- func CommandTagDelete(w http.ResponseWriter, r *http.Request)
- func HttpError(w http.ResponseWriter, status int, err error)
- func Logger(inner http.Handler, name string) http.Handler
- func NewRouter(cmd gohst.CommandRepo, user gohst.UserRepo) *mux.Router
- func ParseJsonEntity(r *http.Request, entity interface{}) error
- func RequesterOwnsResource(user string, r *http.Request) bool
- func StandardHeader(inner http.Handler) http.Handler
- func UserLogin(w http.ResponseWriter, r *http.Request)
- func UserRegister(w http.ResponseWriter, r *http.Request)
- func UserShow(w http.ResponseWriter, r *http.Request)
- func UserTagDelete(w http.ResponseWriter, r *http.Request)
- func UserTagRename(w http.ResponseWriter, r *http.Request)
- func UserTagShow(w http.ResponseWriter, r *http.Request)
- type AuthorizationFilter
- type PsqlCommandRepo
- func (r PsqlCommandRepo) AddTag(tx *sql.Tx, user string, invid int, tag string) (err error)
- func (r PsqlCommandRepo) GetCommands(user string, pageSize int) (result gohst.Commands, err error)
- func (r PsqlCommandRepo) GetInvocations(user string, pageSize int) (result gohst.Invocations, err error)
- func (r PsqlCommandRepo) InsertInvocations(user string, invocs gohst.Invocations) (err error)
- type PsqlDao
- type PsqlUserRepo
- type Route
- type Routes
Constants ¶
const AppDB = "_app"
AppDB is an identifier for a specific *sql.DB in our dao map
Variables ¶
var AuthenticationBlackList map[string]struct{}
AuthenticationBlackList contains the sets of service/Routes for which authentication is not necessary. Routes listed here bypass the authentication middleware and subsequently the authorization middleware as well, as to allow anonymous access to those endpoints.
var AuthorizationFilters map[string][]AuthorizationFilter
AuthorizationFilters contains the slice of functions for each service/Route to use for authorizing that endpoint. If a Route isn't found in the map, it requires no authorization
Functions ¶
func Auth ¶
Auth is the http.Handler middleware for performinag authentication and authorization on a request before furthering the request to its actual handler. It consults the AuthenticationBlackList and AuthorizationBlackList to know whether to apply one, both or neither of these steps. Auth may short-circuit a request, returning http status codes 401 or 403. Otherwise, the request is handled as normal by the inner handler.
func Authenticate ¶
Authenticate compares the user and password provided and compares the stored credential for the given user against the given password. Authentication returns true in the case that the given password matches the stored credential and false otherwise.
func Authorize ¶
Authorize searches the AuthorizationFilters for functions pertaining to the given request and applies each filter in order. If any filter returns false, Authorize returns false. Otherwise and including the case of no filters, Authorize returns true.
func CommandCreate ¶
func CommandCreate(w http.ResponseWriter, r *http.Request)
func CommandDelete ¶
func CommandDelete(w http.ResponseWriter, r *http.Request)
func CommandIndex ¶
func CommandIndex(w http.ResponseWriter, r *http.Request)
CommandIndex is the handler for querying a user's commands, along with any query parameters
func CommandTagCreate ¶
func CommandTagCreate(w http.ResponseWriter, r *http.Request)
func CommandTagDelete ¶
func CommandTagDelete(w http.ResponseWriter, r *http.Request)
func HttpError ¶
func HttpError(w http.ResponseWriter, status int, err error)
HttpError is a convenience function for writing the necessary headers and content for returning an error
func NewRouter ¶
NewRouter constructs a *mux.Router based on the routes defined in this package, which can then be passed to the net/http server.
func ParseJsonEntity ¶
func StandardHeader ¶
StandardHeader is a Response Decorator middleware applied to every handler. Note that it can be overwritten by any local handler; it simply provides defaults.
func UserLogin ¶
func UserLogin(w http.ResponseWriter, r *http.Request)
UserLogin is a do-nothing endpoint that merely confirms that authentication was successful. To that end, it is necessary that the endpoint is wrapped in actual authentication middleware.
func UserRegister ¶
func UserRegister(w http.ResponseWriter, r *http.Request)
func UserTagDelete ¶
func UserTagDelete(w http.ResponseWriter, r *http.Request)
func UserTagRename ¶
func UserTagRename(w http.ResponseWriter, r *http.Request)
func UserTagShow ¶
func UserTagShow(w http.ResponseWriter, r *http.Request)
Types ¶
type AuthorizationFilter ¶
AuthorizationFilter is a function type used for determining if a user is authorized to perform a given request. It returns true if a user meets the requirements of the authorization logic, and false otherwise.
type PsqlCommandRepo ¶
type PsqlCommandRepo struct {
// contains filtered or unexported fields
}
PsqlCommandRepo is an implementation of a gohst CommandRepo that uses PostgreSQL as a backing store
func NewPsqlCommandRepo ¶
func NewPsqlCommandRepo(psqldao PsqlDao) *PsqlCommandRepo
func (PsqlCommandRepo) GetCommands ¶
GetCommands returns the [pageSize] most recent Commands for the given user
func (PsqlCommandRepo) GetInvocations ¶
func (r PsqlCommandRepo) GetInvocations(user string, pageSize int) (result gohst.Invocations, err error)
GetInvocations returns the [pageSize] most recent Invocations for the given user
func (PsqlCommandRepo) InsertInvocations ¶
func (r PsqlCommandRepo) InsertInvocations(user string, invocs gohst.Invocations) (err error)
InsertInvocations sets up a transaction for commiting a batch of Invocations
type PsqlDao ¶
type PsqlDao struct {
// contains filtered or unexported fields
}
PsqlDao is an entity that implements per-user connection pool limits and facilitates access to SQL queries loaded from disk.
func NewPsqlDao ¶
func (*PsqlDao) EnsurePool ¶
EnsurePool verifies that we have created a connection pool for the given user
type PsqlUserRepo ¶
type PsqlUserRepo struct {
// contains filtered or unexported fields
}
PsqlUserRepo is an implementation of a gohst UserRepo that uses PostgreSQL as a backing store
func NewPsqlUserRepo ¶
func NewPsqlUserRepo(dao PsqlDao) *PsqlUserRepo
func (PsqlUserRepo) GetUserByName ¶
func (r PsqlUserRepo) GetUserByName(uname string) (user g.User, err error)
func (PsqlUserRepo) InsertUser ¶
func (PsqlUserRepo) UpdateUserPicture ¶
func (r PsqlUserRepo) UpdateUserPicture(user string, location string) error