server

package
v0.0.0-...-5c09645 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package server defines the ReST service

Index

Constants

View Source
const (
	APIPath    = "/api/" + Version
	TokenRoute = APIPath + "/token"

	OkPath      = "/ok"
	OkRoute     = APIPath + OkPath
	OrgPath     = "/org"
	OrgRoute    = APIPath + OrgPath
	StatusPath  = "/status"
	StatusRoute = APIPath + StatusPath // auth + Ok
	UserPath    = "/user"
	UserRoute   = APIPath + UserPath
)

path/route constants

View Source
const (
	IDHeader           = "X-GrokLOC-ID"
	TokenRequestHeader = "X-GrokLOC-TokenRequest"
)

API headers TokenRequest is formatted as security.EncodedSHA256(id+api-secret)

View Source
const (
	AuthUser = iota
	AuthOrg
	AuthRoot
)

Auth levels to be found in ctx with key authLevelCtxKey

View Source
const (
	IDParam = "id"
)

URL parameter names

View Source
const Version = "v0"

Version is the current API version

Variables

This section is empty.

Functions

func Ok

func Ok(w http.ResponseWriter, r *http.Request)

Ok is just a ping-acknowledgement

Types

type Instance

type Instance struct {
	ST             *app.State
	Started        time.Time
	OrgController  *org.Controller
	UserController *user.Controller
}

Instance is a single app server

func New

func New(level env.Level) (*Instance, error)

New creates a new app server Instance

func (*Instance) CreateOrg

func (srv *Instance) CreateOrg(w http.ResponseWriter, r *http.Request)

func (*Instance) CreateUser

func (srv *Instance) CreateUser(w http.ResponseWriter, r *http.Request)

func (*Instance) NewToken

func (srv *Instance) NewToken(w http.ResponseWriter, r *http.Request)

NewToken returns a response containing a new JWT

func (*Instance) RequestLogger

func (srv *Instance) RequestLogger(next http.Handler) http.Handler

RequestLogger is a middleware that adds logging to each request

func (*Instance) Router

func (srv *Instance) Router() *chi.Mux

Router provides API route handlers

func (*Instance) WithSession

func (srv *Instance) WithSession(next http.Handler) http.Handler

WithSession reads the user and org using the X-GrokLOC-ID header, performs basic validation, and then adds a user and org instance to the context.

func (Instance) WithToken

func (srv Instance) WithToken(next http.Handler) http.Handler

WithToken extracts the JWT from the X-GrokLOC-Token header and validates the claims

type Session

type Session struct {
	Org  org.Org
	User user.User
}

Session is the org and user instances for a user account

type Token

type Token struct {
	Bearer  string `json:"bearer"`
	Expires int64  `json:"expires"`
}

Token describes the token value and the expiration unixtime

Jump to

Keyboard shortcuts

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