devicegate

package
v1.11.9 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextKey

type ContextKey string

ContextKey is a custom type for setting keys in a request's context

type FilterGate

type FilterGate struct {
	FilterStore    FilterStore `json:"filters"`
	AllowedFilters Set         `json:"allowedFilters"`
	// contains filtered or unexported fields
}

FilterGate is a concrete implementation of the Interface

func (*FilterGate) AllowConnection

func (f *FilterGate) AllowConnection(d device.Interface) (bool, device.MatchResult)

func (*FilterGate) DeleteFilter

func (f *FilterGate) DeleteFilter(key string) bool

func (*FilterGate) GetAllowedFilters

func (f *FilterGate) GetAllowedFilters() (Set, bool)

func (*FilterGate) GetFilter

func (f *FilterGate) GetFilter(key string) (Set, bool)

func (*FilterGate) SetFilter

func (f *FilterGate) SetFilter(key string, values []interface{}) (Set, bool)

func (*FilterGate) VisitAll

func (f *FilterGate) VisitAll(visit func(string, Set) bool) int

type FilterHandler

type FilterHandler struct {
	Gate Interface
}

FilterHandler is an http.Handler that can get, add, and delete filters from a devicegate Interface

func (*FilterHandler) DeleteFilter

func (fh *FilterHandler) DeleteFilter(response http.ResponseWriter, request *http.Request)

DeleteFilter is a handler function used to delete a particular filter stored in the gate

func (*FilterHandler) GetFilters

func (fh *FilterHandler) GetFilters(response http.ResponseWriter, request *http.Request)

GetFilters is a handler function that gets all of the filters set on a gate

func (*FilterHandler) UpdateFilters

func (fh *FilterHandler) UpdateFilters(response http.ResponseWriter, request *http.Request)

UpdateFilters is a handler function that updates the filters stored in a gate

type FilterRequest

type FilterRequest struct {
	Key    string        `json:"key"`
	Values []interface{} `json:"values"`
}

type FilterSet

type FilterSet struct {
	Set map[interface{}]bool
	// contains filtered or unexported fields
}

FilterSet is a concrete type that implements the Set interface

func (*FilterSet) Has

func (s *FilterSet) Has(key interface{}) bool

func (*FilterSet) MarshalJSON

func (s *FilterSet) MarshalJSON() ([]byte, error)

func (*FilterSet) VisitAll

func (s *FilterSet) VisitAll(f func(interface{}))

type FilterStore

type FilterStore map[string]Set

FilterStore can be used to store filters in the Interface

type GateLogger

type GateLogger struct {
	Logger log.Logger
}

GateLogger is used to log extra details about the gate

func (GateLogger) LogFilters

func (gl GateLogger) LogFilters(next http.Handler) http.Handler

LogFilters is a decorator that logs the updated filters list and writes the updated list in the response body

type Interface

type Interface interface {
	device.Filter

	// VisitAll applies the given visitor function to each set of filter values
	//
	// No methods on this Interface should be called from within the visitor function, or
	// a deadlock will likely occur.
	VisitAll(visit func(string, Set) bool) int

	// GetFilter returns the set of filter values associated with a filter key and a bool
	// that is true if the key was found, false if it doesn't exist.
	GetFilter(key string) (Set, bool)

	// SetFilter saves the filter values and filter key to filter by. It returns a Set of the old values and a
	// bool that is true if the filter key did not previously exist and false if the filter key had existed beforehand.
	SetFilter(key string, values []interface{}) (Set, bool)

	// DeleteFilter deletes a filter key. This completely removes all filter values associated with that key as well.
	// Returns true if key had existed and values actually deleted, and false if key was not found.
	DeleteFilter(key string) bool

	// GetAllowedFilters returns the set of filters that devices are allowed to be filtered by. Also returns a
	// bool that is true if there are allowed filters set, and false if there aren't (meaning that all filters are allowed)
	GetAllowedFilters() (Set, bool)
}

Interface is a gate interface specifically for filtering devices

type Set

type Set interface {
	json.Marshaler
	// Has returns true if a value exists in the set, false if it doesn't.
	Has(interface{}) bool

	// VisitAll applies the visitor function to every value in the set.
	VisitAll(func(interface{}))
}

Set is an interface that represents a read-only hashset

Jump to

Keyboard shortcuts

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