mirror of
https://github.com/speatzle/nfsense.git
synced 2025-09-13 15:19:08 +00:00
Improve Session / Auth, APICall
This commit is contained in:
parent
fb70f41fcb
commit
2fe21169bb
11 changed files with 167 additions and 115 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"runtime/debug"
|
||||
|
||||
"golang.org/x/exp/slog"
|
||||
"nfsense.net/nfsense/pkg/session"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
|
@ -25,7 +26,7 @@ func NewHandler(maxRequestSize int64) *Handler {
|
|||
}
|
||||
}
|
||||
|
||||
func (h *Handler) HandleRequest(ctx context.Context, r io.Reader, w io.Writer) error {
|
||||
func (h *Handler) HandleRequest(ctx context.Context, s *session.Session, r io.Reader, w io.Writer) error {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
slog.Error("Recovered Panic Handling JSONRPC Request", fmt.Errorf("%v", r), "stack", debug.Stack())
|
||||
|
@ -52,6 +53,10 @@ func (h *Handler) HandleRequest(ctx context.Context, r io.Reader, w io.Writer) e
|
|||
return respondError(w, req.ID, ErrMethodNotFound, fmt.Errorf("Unsupported Jsonrpc version %v", req.Jsonrpc))
|
||||
}
|
||||
|
||||
if s == nil {
|
||||
return respondError(w, req.ID, 401, fmt.Errorf("Unauthorized"))
|
||||
}
|
||||
|
||||
method, ok := h.methods[req.Method]
|
||||
if !ok {
|
||||
return respondError(w, req.ID, ErrMethodNotFound, fmt.Errorf("Unknown Method %v", req.Method))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue