app

package
v0.0.0-...-8e2c34a Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package app provides support for the ReST API

Index

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 (
	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 (
	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 CreateOrgMsg

type CreateOrgMsg struct {
	Name string `json:"name"`
}

CreateOrgMsg is what a client should marshal to send as a json body to CreateOrg

type CreateUserMsg

type CreateUserMsg struct {
	DisplayName string `json:"display_name"`
	Email       string `json:"email"`
	Org         string `json:"org"`
	Password    string `json:"password"`
}

CreateUserMsg is what a client should marshal to send as a json body to CreateUser

type Instance

type Instance struct {
	ST      *state.Instance
	Started time.Time
}

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)

CreateOrg creates a new org based on seed data in the POST body

func (Instance) CreateUser

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

CreateUser creates a new org based on seed data in the POST body

func (*Instance) NewToken

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

NewToken returns a response containing a new JWT

func (Instance) ReadOrg

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

ReadOrg reads an organization

func (Instance) ReadUser

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

ReadUser reads a user

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

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

UpdateOrg updates org owner or status

func (Instance) UpdateUser

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

UpdateUser updates user display name, password, or status

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.Instance
	User user.Instance
}

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

type UpdateOrgOwnerMsg

type UpdateOrgOwnerMsg struct {
	Owner string `json:"owner"`
}

UpdateOrgOwnerMsg is the body format for updating the org owner

func (*UpdateOrgOwnerMsg) UnmarshalJSON

func (m *UpdateOrgOwnerMsg) UnmarshalJSON(bs []byte) error

UnmarshalJSON is a custom unmarshal for UpdateOrgOwnerMsg

type UpdateStatusMsg

type UpdateStatusMsg struct {
	Status models.Status `json:"status"`
}

UpdateStatusMsg is what a client should marshal to send as a json body to status update endpoints

func (*UpdateStatusMsg) UnmarshalJSON

func (m *UpdateStatusMsg) UnmarshalJSON(bs []byte) error

UnmarshalJSON is a custom unmarshal for UpdateStatusMsg

type UpdateUserDisplayNameMsg

type UpdateUserDisplayNameMsg struct {
	DisplayName string `json:"display_name"`
}

UpdateUserDisplayNameMsg is the body format to update the user display name

func (*UpdateUserDisplayNameMsg) UnmarshalJSON

func (m *UpdateUserDisplayNameMsg) UnmarshalJSON(bs []byte) error

UnmarshalJSON is a custom unmarshal for UpdateUserDisplayNameMsg

type UpdateUserPasswordMsg

type UpdateUserPasswordMsg struct {
	Password string `json:"password"`
}

UpdateUserPasswordMsg is the body format to update the user password

func (*UpdateUserPasswordMsg) UnmarshalJSON

func (m *UpdateUserPasswordMsg) UnmarshalJSON(bs []byte) error

UnmarshalJSON is a custom unmarshal for UpdateUserPasswordMsg

Directories

Path Synopsis
Package client is an app client library
Package client is an app client library

Jump to

Keyboard shortcuts

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