...

Package webserver

import "github.com/cybertec-postgresql/pgwatch/v3/internal/webserver"
Overview
Index

Overview ▾

Index ▾

Constants
Variables
func corsMiddleware(next http.Handler) http.Handler
func generateJWT(username string) (string, error)
func reader(ws *websocket.Conn)
func validateToken(r *http.Request) (err error)
func writer(ws *websocket.Conn, l log.LoggerHookerIface)
type CmdOpts
type EnsureAuth
    func NewEnsureAuth(handlerToWrap http.HandlerFunc) *EnsureAuth
    func (ea *EnsureAuth) ServeHTTP(w http.ResponseWriter, r *http.Request)
type WebUIServer
    func Init(opts CmdOpts, webuifs fs.FS, mrw metrics.ReaderWriter, srw sources.ReaderWriter, logger log.LoggerIface) *WebUIServer
    func (server *WebUIServer) DeleteMetric(name string) error
    func (server *WebUIServer) DeletePreset(name string) error
    func (server *WebUIServer) DeleteSource(database string) error
    func (server *WebUIServer) GetMetrics() (res string, err error)
    func (server *WebUIServer) GetPresets() (res string, err error)
    func (server *WebUIServer) GetSources() (res string, err error)
    func (Server *WebUIServer) IsCorrectPassword(lr loginReq) bool
    func (server *WebUIServer) TryConnectToDB(params []byte) (err error)
    func (server *WebUIServer) UpdateMetric(name string, params []byte) error
    func (server *WebUIServer) UpdatePreset(name string, params []byte) error
    func (server *WebUIServer) UpdateSource(params []byte) error
    func (Server *WebUIServer) handleLogin(w http.ResponseWriter, r *http.Request)
    func (Server *WebUIServer) handleMetrics(w http.ResponseWriter, r *http.Request)
    func (Server *WebUIServer) handlePresets(w http.ResponseWriter, r *http.Request)
    func (Server *WebUIServer) handleSources(w http.ResponseWriter, r *http.Request)
    func (Server *WebUIServer) handleStatic(w http.ResponseWriter, r *http.Request)
    func (Server *WebUIServer) handleTestConnect(w http.ResponseWriter, r *http.Request)
    func (Server *WebUIServer) serveWsLog(w http.ResponseWriter, r *http.Request)
type loginReq

Package files

api.go cmdopts.go cors.go jwt.go metric.go preset.go source.go webserver.go wslog.go

Constants

const (
    // Time allowed to write the file to the client.
    writeWait = 10 * time.Second

    // Time allowed to read the next pong message from the client.
    pongWait = 60 * time.Second

    // Send pings to client with this period. Must be less than pongWait.
    pingPeriod = (pongWait * 9) / 10
)

Variables

var sampleSecretKey = []byte("5m3R7K4754p4m")
var (
    upgrader = websocket.Upgrader{
        ReadBufferSize:  1024,
        WriteBufferSize: 1024,
    }
)

func corsMiddleware

func corsMiddleware(next http.Handler) http.Handler

func generateJWT

func generateJWT(username string) (string, error)

func reader

func reader(ws *websocket.Conn)

func validateToken

func validateToken(r *http.Request) (err error)

func writer

func writer(ws *websocket.Conn, l log.LoggerHookerIface)

type CmdOpts

CmdOpts specifies the internal web UI server command-line options

type CmdOpts struct {
    WebDisable  bool   `long:"web-disable" mapstructure:"web-disable" description:"Disable the web UI" env:"PW_WEBDISABLE"`
    WebAddr     string `long:"web-addr" mapstructure:"web-addr" description:"TCP address in the form 'host:port' to listen on" default:":8080" env:"PW_WEBADDR"`
    WebUser     string `long:"web-user" mapstructure:"web-user" description:"Admin login" env:"PW_WEBUSER"`
    WebPassword string `long:"web-password" mapstructure:"web-password" description:"Admin password" env:"PW_WEBPASSWORD"`
}

type EnsureAuth

type EnsureAuth struct {
    handler http.HandlerFunc
}

func NewEnsureAuth

func NewEnsureAuth(handlerToWrap http.HandlerFunc) *EnsureAuth

func (*EnsureAuth) ServeHTTP

func (ea *EnsureAuth) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WebUIServer

type WebUIServer struct {
    l log.LoggerIface
    http.Server
    CmdOpts
    uiFS                fs.FS
    metricsReaderWriter metrics.ReaderWriter
    sourcesReaderWriter sources.ReaderWriter
}

func Init

func Init(opts CmdOpts, webuifs fs.FS, mrw metrics.ReaderWriter, srw sources.ReaderWriter, logger log.LoggerIface) *WebUIServer

func (*WebUIServer) DeleteMetric

func (server *WebUIServer) DeleteMetric(name string) error

DeleteMetric removes the metric from the configuration

func (*WebUIServer) DeletePreset

func (server *WebUIServer) DeletePreset(name string) error

DeletePreset removes the preset from the configuration

func (*WebUIServer) DeleteSource

func (server *WebUIServer) DeleteSource(database string) error

DeleteSource removes the source from the list of configured sources

func (*WebUIServer) GetMetrics

func (server *WebUIServer) GetMetrics() (res string, err error)

GetMetrics returns the list of metrics

func (*WebUIServer) GetPresets

func (server *WebUIServer) GetPresets() (res string, err error)

GetPresets ret urns the list of available presets

func (*WebUIServer) GetSources

func (server *WebUIServer) GetSources() (res string, err error)

GetSources returns the list of sources fo find databases for monitoring

func (*WebUIServer) IsCorrectPassword

func (Server *WebUIServer) IsCorrectPassword(lr loginReq) bool

func (*WebUIServer) TryConnectToDB

func (server *WebUIServer) TryConnectToDB(params []byte) (err error)

func (*WebUIServer) UpdateMetric

func (server *WebUIServer) UpdateMetric(name string, params []byte) error

UpdateMetric updates the stored metric information

func (*WebUIServer) UpdatePreset

func (server *WebUIServer) UpdatePreset(name string, params []byte) error

UpdatePreset updates the stored preset

func (*WebUIServer) UpdateSource

func (server *WebUIServer) UpdateSource(params []byte) error

UpdateSource updates the configured source information

func (*WebUIServer) handleLogin

func (Server *WebUIServer) handleLogin(w http.ResponseWriter, r *http.Request)

func (*WebUIServer) handleMetrics

func (Server *WebUIServer) handleMetrics(w http.ResponseWriter, r *http.Request)

func (*WebUIServer) handlePresets

func (Server *WebUIServer) handlePresets(w http.ResponseWriter, r *http.Request)

func (*WebUIServer) handleSources

func (Server *WebUIServer) handleSources(w http.ResponseWriter, r *http.Request)

func (*WebUIServer) handleStatic

func (Server *WebUIServer) handleStatic(w http.ResponseWriter, r *http.Request)

func (*WebUIServer) handleTestConnect

func (Server *WebUIServer) handleTestConnect(w http.ResponseWriter, r *http.Request)

func (*WebUIServer) serveWsLog

func (Server *WebUIServer) serveWsLog(w http.ResponseWriter, r *http.Request)

type loginReq

type loginReq struct {
    Username string `json:"user"`
    Password string `json:"password"`
}