dash

package
v0.2.1-pre Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2021 License: MIT Imports: 32 Imported by: 9

Documentation

Index

Constants

View Source
const (
	TLS_KEY_FILENAME  = "dashborg-client.key"
	TLS_CERT_FILENAME = "dashborg-client.crt"
	DEFAULT_PROCNAME  = "default"
	DEFAULT_ZONENAME  = "default"
	DEFAULT_PANELNAME = "default"
)
View Source
const CLIENT_VERSION = "go-0.0.1"
View Source
const EC_ACCACCESS = "ACCACCESS"
View Source
const EC_BADCONNID = "BADCONNID"
View Source
const EC_EOF = "EOF"
View Source
const EC_NOHANDLER = "NOHANDLER"
View Source
const EC_UNAVAILABLE = "UNAVAILABLE"
View Source
const EC_UNKNOWN = "UNKNOWN"
View Source
const MAX_AUTH_EXP = 24 * time.Hour

Variables

This section is empty.

Functions

func RegisterDataHandler

func RegisterDataHandler(panelName string, path string, handlerFn func(*PanelRequest) (interface{}, error))

RegisterDataHandler registers a data handler.

func RegisterDataHandlerEx

func RegisterDataHandlerEx(panelName string, path string, handlerFn interface{}) error

RegisterPanelDataEx registers a panel handler using reflection. The handler function must return exactly two values (interface{}, error). It must also take between 1-3 arguments. The first parameter must be a *dash.PanelRequest. The second (optional) parameter is PanelState, and the third (optional) parameter is Data. Dashborg will attempt to unmarshal the raw JSON of PanelState and Data to the types in the handler signature using the standard Go json.Unmarshal() function. If an error occurs during unmarshalling it will be returned to the Dashborg service (and your handler function will never run).

func RegisterPanelHandler

func RegisterPanelHandler(panelName string, path string, handlerFn func(*PanelRequest) error)

RegisterPanelHandler registers a panel handler. All panels require a root handler (path = "/").

func RegisterPanelHandlerEx

func RegisterPanelHandlerEx(panelName string, path string, handlerFn interface{}) error

RegisterPanelHandlerEx registers a panel handler using reflection. The handler function must return exactly one error value. It must also take between 1-3 arguments. The first parameter must be a *dash.PanelRequest. The second (optional) parameter is PanelState, and the third (optional) parameter is Data. Dashborg will attempt to unmarshal the raw JSON of PanelState and Data to the types in the handler signature using the standard Go json.Unmarshal() function. If an error occurs during unmarshalling it will be returned to the Dashborg service (and your handler function will never run).

func StartProcClient

func StartProcClient(config *Config)

Starts the Dashborg Client

func WaitForClear

func WaitForClear()

WaitForClear closes the gRPC connection to the server and shuts down the Dashborg client. Usually called at the end of main() using defer.

Types

type AllowedAuth

type AllowedAuth interface {
	// contains filtered or unexported methods
}

type AuthDashborg

type AuthDashborg struct{}

type AuthNone

type AuthNone struct{}

type AuthPassword

type AuthPassword struct {
	Password string
}

type AuthSimpleJwt

type AuthSimpleJwt struct {
	Key string
}

type Config

type Config struct {
	// DASHBORG_ACCID, set to force an AccountId (must match certificate).  If not set, AccountId is set from certificate file.
	// If AccId is given and AutoKeygen is true, and key/cert files are not found, Dashborg will create a new self-signed
	//     keypair using the AccId given.
	// If AccId is given, and the certificate does not match, this will cause a panic.
	AccId string

	// Set to true for unregistered accounts
	AnonAcc bool

	// DASHBORG_ZONE defaults to "default"
	ZoneName string

	// Process Name Attributes.  Only ProcName is required
	ProcName string // DASHBORG_PROCNAME (set from executable filename if not set)
	ProcTags map[string]string

	KeyFileName  string // DASHBORG_KEYFILE private key file (defaults to dashborg-client.key)
	CertFileName string // DASHBORG_CERTFILE certificate file, CN must be set to your Dashborg Account Id.  (defaults to dashborg-client.crt)

	// Create a self-signed key/cert if they do not exist.  This will also create a random Account Id.
	// Should only be used with AnonAcc is true.  If AccId is set, will create a key with that AccId
	AutoKeygen bool

	// The minimum amount of time to wait for all events to complete processing before shutting down after calling WaitForClear()
	// Defaults to 1 second.
	MinClearTimeout time.Duration

	// DASHBORG_VERBOSE, set to true for extra debugging information
	Verbose bool

	// These are for internal testing, should not normally be set by clients.
	Env             string // DASHBORG_ENV
	DashborgSrvHost string // DASHBORG_PROCHOST
	DashborgSrvPort int    // DASHBORG_PROCPORT
}

type PanelRequest

type PanelRequest struct {
	PanelName      string      // panel name
	ReqId          string      // unique request id
	RequestType    string      // "data" or "handler"
	Path           string      // handler or data path
	Data           interface{} // json-unmarshaled data attached to this request
	PanelState     interface{} // json-unmarshaled panel state for this request
	PanelStateJson string      // Raw JSON for PanelState (used for manual unmarshalling into custom struct)
	DataJson       string      // Raw JSON for Data (used for manual unmarshalling into custom struct)

	// The following fields are internal and subject to change.  Not for normal client usage.
	Ctx        context.Context       // gRPC context
	FeClientId string                // unique id for client (currently unused)
	Lock       *sync.Mutex           // synchronizes RRActions
	AuthData   []*authAtom           // authentication tokens associated with this request
	RRActions  []*dashproto.RRAction // output, these are the actions that will be returned
	Err        error                 // set if an error occured (when set, RRActions are not sent)
	IsDone     bool                  // set after Done() is called and response has been sent to server
	AuthImpl   bool                  // if not set, will default NoAuth() on Done()
	Info       []string              // debugging information
}

PanelRequest encapsulates all the data about a Dashborg request. Normally the only fields that a handler needs to access are "Data" and "PanelState" in order to read the parameters and UI state associated with this request. The other fields are exported, but subject to change and should not be used except in advanced use cases.

func (*PanelRequest) CheckAuth

func (req *PanelRequest) CheckAuth(allowedAuths ...AllowedAuth) bool

If AllowedAuth impelementations return an error they will be logged into req.Info. They will not stop the execution of the function since other auth methods might succeed.

func (*PanelRequest) Done

func (req *PanelRequest) Done() error

Done() ends a request and sends the results back to the client. It is automatically called after a handler/data-handler is run. Only needs to be called explicitly if you'd like to return your result earlier.

func (*PanelRequest) InvalidateData

func (req *PanelRequest) InvalidateData(path string) error

Call from a handler to force the client to invalidate and re-pull data that matches path. Path is a regular expression.

func (*PanelRequest) IsAuthenticated

func (req *PanelRequest) IsAuthenticated() bool

func (*PanelRequest) SetData

func (req *PanelRequest) SetData(path string, data interface{}) error

SetData is used to return data to the client. Will replace the contents of path with data.

func (*PanelRequest) SetHtml

func (req *PanelRequest) SetHtml(html string) error

SetHtml returns html to be rendered by the client. Only valid for root handler requests (path = "/")

func (*PanelRequest) SetHtmlFromFile

func (req *PanelRequest) SetHtmlFromFile(fileName string) error

Convience wrapper over SetHtml that returns the contents of a file.

Jump to

Keyboard shortcuts

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