Documentation ¶
Index ¶
- func AddRoutes(s *Server, e *echo.Echo)
- func CheckAuthorization(ctx context.Context, method string, urs string, auth string, mc MemCache, ...) error
- func ErrBadRequest(c echo.Context, err error) error
- func ErrConflict(c echo.Context, err error) error
- func ErrEntityTooLarge(c echo.Context, err error) error
- func ErrForbidden(c echo.Context, err error) error
- func ErrNotFound(c echo.Context, err error) error
- func ErrResponse(c echo.Context, status int, msg string) error
- func ErrUnauthorized(c echo.Context, err error) error
- func ErrorHandler(err error, c echo.Context)
- func JSON(c echo.Context, status int, i interface{}) error
- func NewHandler(s *Server) http.Handler
- func SetContextLogger(l ContextLogger)
- type Access
- type AccessAction
- type AccessContext
- type AccessFn
- type AccessResource
- type ContextLogger
- type Fire
- type LogLevel
- type MemCache
- type Server
- func (s *Server) SetAccessFn(fn AccessFn)
- func (s *Server) SetInternalAuth(internalAuth string)
- func (s *Server) SetNowFn(nowFn func() time.Time)
- func (s *Server) SetRequestor(req user.Requestor)
- func (s *Server) SetTasks(tasks Tasks)
- func (s *Server) UserPublicKey(ctx context.Context, pkid keyup.ID) (*keyup.UserPublicKey, error)
- type Tasks
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckAuthorization ¶
func CheckAuthorization(ctx context.Context, method string, urs string, auth string, mc MemCache, now time.Time, upk *keyup.UserPublicKey) error
CheckAuthorization returns errors if authorization fails.
func ErrEntityTooLarge ¶
ErrEntityTooLarge response.
func ErrResponse ¶
ErrResponse is a generate error response.
func ErrUnauthorized ¶
ErrUnauthorized response.
func ErrorHandler ¶
func ErrorHandler(err error, c echo.Context)
ErrorHandler returns error handler that returns in the format: {"error": {"message": "error message", status: 500}}".
func NewHandler ¶
NewHandler returns http.Handler for Server.
func SetContextLogger ¶
func SetContextLogger(l ContextLogger)
SetContextLogger sets logger for the package
Types ¶
type Access ¶
type Access struct { Allow bool Message string // StatusCode (optional) for custom HTTP status (if denied) StatusCode int }
Access returns whether to allow or deny.
func AccessDenyErrored ¶
AccessDenyErrored deny access (an error occurred trying to determine access).
func AccessDenyTooManyRequests ¶
AccessDenyTooManyRequests deny access (too many requests).
type AccessAction ¶
type AccessAction string
AccessAction is action for access control.
const ( // Put action. Put AccessAction = "put" // Post action. Post AccessAction = "post" )
type AccessContext ¶
AccessContext is context for request.
type AccessFn ¶
type AccessFn func(c AccessContext, resource AccessResource, action AccessAction) Access
AccessFn returns access to resource. If error message begins with an integer, it will use that as the http status code. For example, "429: too many requests".
type AccessResource ¶
type AccessResource string
AccessResource is resource for access control.
const ( // UserPublicKeyResource for a user public key. UserPublicKeyResource AccessResource = "user-public-key" // SigchainResource for sigchain. SigchainResource AccessResource = "sigchain" )
type ContextLogger ¶
type ContextLogger interface { Debugf(ctx context.Context, format string, args ...interface{}) Infof(ctx context.Context, format string, args ...interface{}) Warningf(ctx context.Context, format string, args ...interface{}) Errorf(ctx context.Context, format string, args ...interface{}) }
ContextLogger interface used in this package with request context.
type Fire ¶
type Fire interface { keyup.Datastore keyup.LogEntries }
Fire defines interface for remote store (like Firestore).
type MemCache ¶
type MemCache interface { // Get returns value at key. Get(ctx context.Context, k string) (string, error) // Put puts a value at key. Set(ctx context.Context, k string, v string) error // Expire key. Expire(ctx context.Context, k string, dt time.Duration) error }
MemCache defines interface for memcache. Used to prevent nonce re-use for authenticated requests.
func NewMemTestCache ¶
NewMemTestCache returns in memory MemCache (for testing).
type Server ¶
type Server struct { // URL (base) of form http://host:port with no trailing slash to help // authorization checks in testing where the host is ambiguous. URL string // contains filtered or unexported fields }
Server ...
func (*Server) SetAccessFn ¶
SetAccessFn sets access control.
func (*Server) SetInternalAuth ¶
SetInternalAuth for authorizing internal requests, like tasks.
func (*Server) UserPublicKey ¶
UserPublicKey ...