service

package
v0.0.0-...-38f047e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2016 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package service implements the gohstd web service, providing remote access to the command history supplied by gohst clients

Index

Constants

View Source
const AppDB = "_app"

AppDB is an identifier for a specific *sql.DB in our dao map

Variables

View Source
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.

View Source
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

func Auth(inner http.Handler, route string) http.Handler

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

func Authenticate(user, password string) bool

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

func Authorize(user string, r *http.Request, route string) bool

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 Logger

func Logger(inner http.Handler, name string) http.Handler

func NewRouter

func NewRouter(cmd gohst.CommandRepo, user gohst.UserRepo) *mux.Router

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 ParseJsonEntity(r *http.Request, entity interface{}) error

func RequesterOwnsResource

func RequesterOwnsResource(user string, r *http.Request) bool

func StandardHeader

func StandardHeader(inner http.Handler) http.Handler

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 UserShow

func UserShow(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

type AuthorizationFilter func(user string, r *http.Request) bool

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) AddTag

func (r PsqlCommandRepo) AddTag(tx *sql.Tx, user string, invid int, tag string) (err error)

AddTag persists a Tag to an Invocation, as part of a transaction.

func (PsqlCommandRepo) GetCommands

func (r PsqlCommandRepo) GetCommands(user string, pageSize int) (result gohst.Commands, err error)

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 NewPsqlDao(conn string) *PsqlDao

func (*PsqlDao) EnsurePool

func (r *PsqlDao) EnsurePool(user string) *sql.DB

EnsurePool verifies that we have created a connection pool for the given user

func (*PsqlDao) Query

func (r *PsqlDao) Query(identifier string) string

Query fetches an SQL query that matches the given identifier

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 (r PsqlUserRepo) InsertUser(user g.User, secret g.Secret) error

func (PsqlUserRepo) UpdateUserPicture

func (r PsqlUserRepo) UpdateUserPicture(user string, location string) error

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

Route represents a URI route for the server to support. A definition of a Route declares support for an HTTP endpoint and maps that URI to the appropriate HTTP handler.

type Routes

type Routes []Route

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL