api

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package api implments the SIOT http interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAppHandler

func NewAppHandler(args ServerArgs) http.Handler

NewAppHandler returns a new application (root) http handler

func NewNodesHandler added in v0.0.12

func NewNodesHandler(v RequestValidator, authToken string,
	nc *nats.Conn) http.Handler

NewNodesHandler returns a new node handler

func NewSendPoints added in v0.0.11

func NewSendPoints(portalURL, deviceID, authToken string, timeout time.Duration, debug bool) func(data.Points) error

NewSendPoints returns a function that can be used to send points to a SimpleIoT portal instance

func NewV1Handler

func NewV1Handler(args ServerArgs) http.Handler

NewV1Handler returns a handle for V1 API

func ShiftPath

func ShiftPath(p string) (head, tail string)

ShiftPath is used to extract on segement of URL for processing

Types

type AlwaysValid added in v0.0.5

type AlwaysValid struct{}

AlwaysValid is used to disable authentication

func (AlwaysValid) NewToken added in v0.0.5

func (AlwaysValid) NewToken(_ string) (string, error)

NewToken stub

func (AlwaysValid) Valid added in v0.0.5

func (AlwaysValid) Valid(*http.Request) (bool, string)

Valid stub

type App

type App struct {
	PublicHandler  http.Handler
	V1ApiHandler   http.Handler
	WebsocketProxy http.Handler
}

App is a struct that implements http.Handler interface

func (*App) ServeHTTP

func (h *App) ServeHTTP(res http.ResponseWriter, req *http.Request)

Top level handler for http requests in the coap-server process

type Auth added in v0.0.5

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

Auth handles user authentication requests.

func NewAuthHandler added in v0.0.5

func NewAuthHandler(nc *nats.Conn) Auth

NewAuthHandler returns a new authentication handler using the given key.

func (Auth) ServeHTTP added in v0.0.5

func (auth Auth) ServeHTTP(res http.ResponseWriter, req *http.Request)

ServeHTTP serves requests to authenticate.

type Authorizer added in v0.0.5

type Authorizer interface {
	NewToken(id string) (string, error)
	Valid(req *http.Request) (bool, string)
}

Authorizer defines a mechanism needed to authorize stuff

type CoapServer

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

CoapServer manages all the coap requests for this platform

func NewCoapServer

func NewCoapServer(port string) *CoapServer

NewCoapServer creates a new coap server

func (*CoapServer) Start

func (cs *CoapServer) Start() error

Start the coap server

type HTTPLogger added in v0.0.5

type HTTPLogger struct {
	*log.Logger
	// contains filtered or unexported fields
}

HTTPLogger can be used to log http requests

func NewHTTPLogger added in v0.0.5

func NewHTTPLogger(prefix string) *HTTPLogger

NewHTTPLogger returns a http logger

func (*HTTPLogger) Handler added in v0.0.5

func (l *HTTPLogger) Handler(next http.Handler) http.Handler

Handler wraps an HTTP handler and logs the request as necessary.

type Key added in v0.0.5

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

Key provides a key for signing authentication tokens.

func NewKey added in v0.0.5

func NewKey(bytes []byte) (key Key, err error)

NewKey returns a new Key of the given size.

func (Key) NewToken added in v0.0.5

func (k Key) NewToken(userID string) (string, error)

NewToken returns a new authentication token signed by the Key.

func (Key) Valid added in v0.0.5

func (k Key) Valid(req *http.Request) (bool, string)

Valid returns whether the given request bears an authorization token signed by the Key.

func (Key) ValidToken added in v0.0.5

func (k Key) ValidToken(str string) (bool, string)

ValidToken returns whether the given string is an authentication token signed by the Key.

type NodeCopy added in v0.0.23

type NodeCopy struct {
	ID        string
	NewParent string
	Duplicate bool
}

NodeCopy is a data structured used in the /node/:id/parents api call

type NodeDelete added in v0.0.23

type NodeDelete struct {
	Parent string
}

NodeDelete is a data structure used with /node/:id DELETE call

type NodeMove added in v0.0.15

type NodeMove struct {
	ID        string
	OldParent string
	NewParent string
}

NodeMove is a data structure used in the /node/:id/parents api call

type Nodes added in v0.0.12

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

Nodes handles node requests

func (*Nodes) ServeHTTP added in v0.0.12

func (h *Nodes) ServeHTTP(res http.ResponseWriter, req *http.Request)

Top level handler for http requests in the coap-server process TODO need to add node auth

type Point added in v0.0.11

type Point struct {
	// Type of point (voltage, current, key, etc)
	Type string `json:"type,omitempty" influx:"type,tag"`

	// Key of the device that provided the point
	Key string `json:"key,omitempty" influx:"key,tag"`

	// Average OR
	// Instantaneous analog or digital value of the point.
	// 0 and 1 are used to represent digital values
	Value float64 `json:"value,omitempty" influx:"value"`

	// Time the point was taken
	Time *time.Time `json:"time,omitempty" boltholdKey:"Time" gob:"-" influx:"time"`

	// Duration over which the point was taken
	Duration time.Duration `json:"duration,omitempty" influx:"duration"`
}

Point is a custom value of data.Point with Time set to a pointer. This allows omitempty to work for zero timestamps to avoid bloating JSON packets.

func NewPoint added in v0.0.11

func NewPoint(s data.Point) Point

NewPoint converts a data.Point to Point and rounds floating point values to 3 dec places.

func NewPoints added in v0.0.11

func NewPoints(points []data.Point) []Point

NewPoints converts []data.Sample to []Sample

type RequestValidator added in v0.0.5

type RequestValidator interface {
	Valid(req *http.Request) (bool, string)
}

RequestValidator validates an HTTP request.

type Server

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

Server represents the HTTP API server

func NewServer added in v0.3.0

func NewServer(args ServerArgs) *Server

NewServer ..

func (*Server) Start added in v0.3.0

func (s *Server) Start() error

Start the api server

func (*Server) Stop added in v0.3.0

func (s *Server) Stop(_ error)

Stop HTTP API

type ServerArgs added in v0.0.5

type ServerArgs struct {
	Port       string
	Filesystem http.FileSystem
	Debug      bool
	JwtAuth    Authorizer
	AuthToken  string
	NatsWSPort int
	Nc         *nats.Conn
}

ServerArgs can be used to pass arguments to the server subsystem

type V1

type V1 struct {
	GroupsHandler http.Handler
	UsersHandler  http.Handler
	NodesHandler  http.Handler
	AuthHandler   http.Handler
	MsgHandler    http.Handler
}

V1 handles v1 api requests

func (*V1) ServeHTTP

func (h *V1) ServeHTTP(res http.ResponseWriter, req *http.Request)

Top level handler for http requests in the coap-server process

Jump to

Keyboard shortcuts

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