wmf

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2015 License: MPL-2.0 Imports: 31 Imported by: 5

Documentation

Index

Constants

View Source
const (
	SESSION_NAME      = "user"
	SESSION_LOGIN     = "login"
	OAUTH_ENDPOINT    = "https://oauth.accounts.firefox.com"
	CONTENT_ENDPOINT  = "https://accounts.firefox.com"
	SESSION_USERID    = "userid"
	SESSION_EMAIL     = "email"
	SESSION_TOKEN     = "token"
	SESSION_CSRFTOKEN = "csrftoken"
	SESSION_DEVICEID  = "deviceid"
)

Variables

View Source
var (
	ErrInvalidReply  = errors.New("Invalid Command Response")
	ErrAuthorization = errors.New("Needs Authorization")
	ErrNoUser        = errors.New("No User")
	ErrOAuth         = errors.New("OAuth Error")
	ErrNoClient      = errors.New("No Client for Update")
	ErrTooManyClient = errors.New("Too Many Clients for device")
	ErrDeviceDeleted = errors.New("Device deleted")
	ErrNoLanguage    = errors.New("No Language json file found")
)

Errors

View Source
var ErrInvalidSignature = errors.New("Header does not match signature")
View Source
var (
	ErrInvalidSocket = errors.New("Invalid socket type specified")
)
View Source
var ErrNoAuth = errors.New("No Authorization Header")
View Source
var ErrNotHawkAuth = errors.New("Not a Hawk Authorization Header")
View Source
var ErrReplayedNonce = errors.New("Nonce detected. Replay?")
View Source
var HawkNonces *nonceCache

Functions

func GenNonce

func GenNonce(l int) string

Generate a nonce l bytes long (if l == 0, 6 bytes)

func InitHawkNonces

func InitHawkNonces(count int64)

func SendPush

func SendPush(devRec *storage.Device, config *util.MzConfig) error

Types

type ClientBox

type ClientBox struct {
	sync.RWMutex

	Max int64
	// contains filtered or unexported fields
}
var (
	Clients *ClientBox
)

package globals

func NewClientBox

func NewClientBox() *ClientBox

func (*ClientBox) Add

func (c *ClientBox) Add(id, instance string, sock WWS) error

Client Mapping functions Add a new trackable client.

func (*ClientBox) Clients

func (c *ClientBox) Clients(id string) (map[string]WWS, bool)

func (*ClientBox) Del

func (c *ClientBox) Del(id, instance string) (bool, error)

remove a trackable client, returns if tracking should stop

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

base handler for REST and Socket calls.

func NewHandler

func NewHandler(config *util.MzConfig, logger util.Logger, metrics util.Metrics) *Handler

func (*Handler) Cmd

func (self *Handler) Cmd(resp http.ResponseWriter, req *http.Request)

Handle the Cmd response from the device and pass next command if available.

func (*Handler) Index

func (self *Handler) Index(resp http.ResponseWriter, req *http.Request)

func (*Handler) InitDataJson

func (self *Handler) InitDataJson(resp http.ResponseWriter, req *http.Request)

Return the initData as a JSON object

func (*Handler) Language

func (r *Handler) Language(resp http.ResponseWriter, req *http.Request)

func (*Handler) Metrics

func (self *Handler) Metrics(resp http.ResponseWriter, req *http.Request)

Display the current metrics as a JSON snapshot

func (*Handler) OAuthCallback

func (self *Handler) OAuthCallback(resp http.ResponseWriter, req *http.Request)

func (*Handler) Queue

func (self *Handler) Queue(devRec *storage.Device, cmd string, args, rep *replyType) (status int, err error)

Queue the command from the Web Front End for the device.

func (*Handler) Register

func (self *Handler) Register(resp http.ResponseWriter, req *http.Request)

Register a new device

func (*Handler) RestQueue

func (self *Handler) RestQueue(resp http.ResponseWriter, req *http.Request)

Accept a command to queue from the REST interface

func (*Handler) Signin

func (self *Handler) Signin(resp http.ResponseWriter, req *http.Request)

func (*Handler) Signout

func (self *Handler) Signout(resp http.ResponseWriter, req *http.Request)

func (*Handler) State

func (self *Handler) State(resp http.ResponseWriter, req *http.Request)

Show the state of the user's devices.

func (*Handler) Static

func (self *Handler) Static(resp http.ResponseWriter, req *http.Request)

Handle requests for static content (should be an NGINX rule)

func (*Handler) Status

func (self *Handler) Status(resp http.ResponseWriter, req *http.Request)

Show the status of the program (For Load Balancers)

func (*Handler) UserDevices

func (self *Handler) UserDevices(resp http.ResponseWriter, req *http.Request)

func (*Handler) Validate

func (self *Handler) Validate(resp http.ResponseWriter, req *http.Request)

Validate a given assertion (useful for client)

func (*Handler) WSSocketHandler

func (self *Handler) WSSocketHandler(ws *websocket.Conn)

Handle Websocket processing.

type Hawk

type Hawk struct {
	Id        string
	Time      string
	Nonce     string
	Method    string
	Path      string
	Host      string
	Port      string
	Extra     string
	Hash      string
	Signature string
	// contains filtered or unexported fields
}

minimal HAWK for now (e.g. no bewit because IAGNI)

func (*Hawk) AsHeader

func (self *Hawk) AsHeader(req *http.Request, id, body, extra, secret string) string

Return a Hawk Authorization header

func (*Hawk) Clear

func (self *Hawk) Clear()

Clear the stickier bits

func (*Hawk) Compare

func (self *Hawk) Compare(sig string) bool

Compare a signature value against the generated Signature.

func (*Hawk) GenerateSignature

func (self *Hawk) GenerateSignature(req *http.Request, extra, body, secret string) (err error)

Initialize self from request, extra and secret

Things to check:
* Are all values being sent? (e.g. extra, time, secret)
* Do the secrets match?
* is the other format string formatted correctly? (two \n before extra, 0 after)

func (*Hawk) ParseAuthHeader

func (self *Hawk) ParseAuthHeader(req *http.Request, logger util.Logger) (err error)

Initialize self from the AuthHeader

type LangPath

type LangPath struct {
	Root string
	Lang string
	// contains filtered or unexported fields
}

func NewLangPath

func NewLangPath(tmpl *template.Template, docroot, defaultLanguage string) (*LangPath, error)

Language Path

func (*LangPath) Check

func (r *LangPath) Check(lang string) (string, error)

func (*LangPath) Load

func (r *LangPath) Load(lang string) (err error)

func (*LangPath) Localize

func (r *LangPath) Localize(key string) string

func (*LangPath) Write

func (r *LangPath) Write(lang string, out io.Writer) (err error)

type LanguagePrefs

type LanguagePrefs []lang_loc

func (LanguagePrefs) Len

func (r LanguagePrefs) Len() int

func (LanguagePrefs) Less

func (r LanguagePrefs) Less(i, j int) bool

func (LanguagePrefs) Swap

func (r LanguagePrefs) Swap(i, j int)

type MockWSConn

type MockWSConn struct {
	Buff      []byte
	Connected bool
}

== Mock Websocket Interface (used for testing)

func (*MockWSConn) Close

func (*MockWSConn) Close() error

func (*MockWSConn) IsClientConn

func (r *MockWSConn) IsClientConn() bool

func (*MockWSConn) Receive

func (r *MockWSConn) Receive() []byte

absolute minimum of functions for what we need.

func (*MockWSConn) Write

func (r *MockWSConn) Write(b []byte) (int, error)

type Sock

type Sock interface {
	Close() error
	IsClientConn() bool
	Write([]byte) (int, error)
}

Interface for Socket calls (with limited calls we need)

type WWS

type WWS interface {
	Run()
	Close() error
	Born() time.Time
	Device() *storage.Device
	Handler() *Handler
	Logger() util.Logger
	Socket() Sock
}

Websocket Handler function.

type WWSs

type WWSs struct {
	// contains filtered or unexported fields
}

func (*WWSs) Born

func (r *WWSs) Born() time.Time

func (*WWSs) Close

func (self *WWSs) Close() error

func (*WWSs) Device

func (r *WWSs) Device() *storage.Device

func (*WWSs) Handler

func (r *WWSs) Handler() *Handler

func (*WWSs) Logger

func (r *WWSs) Logger() util.Logger

func (*WWSs) Run

func (self *WWSs) Run()

Workhorse function.

func (*WWSs) Socket

func (r *WWSs) Socket() Sock

type Worker

type Worker interface {
	Run()
}

Directories

Path Synopsis
This file manages schema modification.
This file manages schema modification.

Jump to

Keyboard shortcuts

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