api

package
v0.0.0-...-94bc3c9 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2025 License: Apache-2.0 Imports: 22 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

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

NewNodesHandler returns a new node handler

func NewSendPoints

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

type AlwaysValid struct{}

AlwaysValid is used to disable authentication

func (AlwaysValid) NewToken

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

NewToken stub

func (AlwaysValid) Valid

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

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

Auth handles user authentication requests.

func NewAuthHandler

func NewAuthHandler(nc *nats.Conn) Auth

NewAuthHandler returns a new authentication handler using the given key.

func (Auth) ServeHTTP

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

ServeHTTP serves requests to authenticate.

type Authorizer

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

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

HTTPLogger can be used to log http requests

func NewHTTPLogger

func NewHTTPLogger(prefix string) *HTTPLogger

NewHTTPLogger returns a http logger

func (*HTTPLogger) Handler

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

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

type Key

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

Key provides a key for signing authentication tokens.

func NewKey

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

NewKey returns a new Key of the given size.

func (Key) NewToken

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

NewToken returns a new authentication token signed by the Key.

func (Key) Valid

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

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

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

type NodeCopy

type NodeCopy struct {
	ID        string
	NewParent string
	Duplicate bool
}

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

type NodeDelete

type NodeDelete struct {
	Parent string
}

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

type NodeMove

type NodeMove struct {
	ID        string
	OldParent string
	NewParent string
}

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

type Nodes

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

Nodes handles node requests

func (*Nodes) ServeHTTP

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

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" 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

func NewPoint(s data.Point) Point

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

func NewPoints

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

NewPoints converts []data.Sample to []Sample

type RequestValidator

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

func NewServer(args ServerArgs) *Server

NewServer ..

func (*Server) Start

func (s *Server) Start() error

Start the api server

func (*Server) Stop

func (s *Server) Stop(_ error)

Stop HTTP API

type ServerArgs

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