24 Commits

Author SHA1 Message Date
Eric Callahan
bb0266f5c4 app: replace dict with UserInfo throughout Moonraker
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-05-21 06:18:46 -04:00
Eric Callahan
eddf47e4a3 authorization: use SQL tables to store user info
Add a UserInfo class which provides type annotations for each member.
This class easily converts to a dict or tuple, simplifying conversion
for usage in SQL statements.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-05-21 06:18:46 -04:00
Eric Callahan
80c762074f database: migrate from lmdb to sqlite
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-05-18 08:03:47 -04:00
Eric Callahan
76704feee4 sensor: add support for parameter configuration
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-05-15 07:31:57 -04:00
Eric Callahan
b6896c7c0a common: add common history tracking implementation
The HistoryDataField class can be instantiated by any
component.  It can then be used to register additional fields
tracked in the job history.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-05-04 08:16:37 -04:00
Eric Callahan
60f4a82873
confighelper: avoid direct import of JinjaTemplate
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-01-15 06:03:35 -05:00
Eric Callahan
a88468eb79
refactor: convert websockets into a component
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2024-01-13 15:15:15 -05:00
Eric Callahan
5585884d26
app: resolve soft restart issues
Clear the API cache when closing to purge stale callbacks.  In addition,
explicitly delte the server object after the eventloop stops.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-12-29 08:22:50 -05:00
Eric Callahan
aa16dd671b
app: add jsonrpc HTTP endpoint
Add a POST /server/jsonrpc endpoint that processes jsonrpc
requests from the body.  This allows developers familiar with
the JSON-RPC API to use it in places where a websocket is not
desiriable.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-12-16 16:21:24 -05:00
Eric Callahan
6dbcdf537f
app: improve endpoint registration logging
Only log registration when verbose (debug) logging is enabled.
In addition, log endpoint removal.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-12-16 16:21:23 -05:00
Eric Callahan
b3b60757aa
authorization: remove "permitted_paths" attribute
Track authentication requirements in the API Definition.  This
eliminates the need to look up the authentication component
to disable auth on an endpoint.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-12-16 16:21:22 -05:00
Eric Callahan
bfeb096f31
jsonrpc: share one instance among all transports
This change refactors the APIDefiniton into a dataclass, allowing
defs to be shared directly among HTTP and RPC requests.  In
addition, all transports now share one instance of JSONRPC,
removing duplicate registration.  API Defintiions are registered
with the RPC Dispatcher, and it validates the Transport type.
In addition tranports may perform their own validation prior
to request execution.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-12-16 16:21:21 -05:00
Eric Callahan
8b2d9b26f5
app: streamline endpoint registration
Refactor endpoint registration to reduce duplicated code.
Rename some APIDefinition attributes for clarity.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-12-16 16:21:21 -05:00
Eric Callahan
7de61eb113
klippy_connection: track connection state with an enum
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-12-16 16:21:21 -05:00
Eric Callahan
6e8b720d17
job_state: combine events into a single handler
Emit a single event where the first argument contains
a "JobEvent" enumeration that describes the particular
event.  This reduces the number of callbacks registered
by JobState consumers and allows them react to multiple
state changes in the same callback.

The individual events remain for compatibility, however
they are deprecated.  Current modules should be updated
to use the "job_state:state_changed" event and new modules
must use this event.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-12-16 16:21:20 -05:00
Eric Callahan
7deb9fac4c
common: add RequestType and TransportType flags
These flags replace strings as constants used to register and
identify Request Types (ie: GET, POST) and API Transport
Types.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-12-16 16:21:19 -05:00
Eric Callahan
27dddd62ac
extensions: support agent method registration
Create a websocket endpoint that allows clients identified as
agents to register remote methods with Klipper.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-11-07 11:27:11 -05:00
Eric Callahan
9b0aec378e
common: fix linter errors
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-10-07 10:29:04 -04:00
Eric Callahan
f99e5b0bea
utils: add support for msgspec with stdlib json fallback
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
2023-10-06 18:20:28 -04:00
Eric Callahan
504a3a76f5
common: reduce jrpc exception spam
When a client repeatedly makes a request that results in an error
the log is spammed with tracebacks that don't provide significant
value.  The method name, code, and error message should be
enough for basic troubleshooting.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-07-09 13:48:01 -04:00
Eric Callahan
b36f5a4eee
common: log method name for JSON RPC Errors
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-06-29 12:20:52 -04:00
Eric Callahan
734351d9a0
common: add get_list method to WebRequest
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-24 07:48:40 -05:00
Eric Callahan
1b9f29db13
websockets: move JsonRPC and BaseSocketClient to common
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-24 07:08:43 -05:00
Eric Callahan
6d73c60a38
moonraker: move common classes to common.py
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2023-02-24 07:08:41 -05:00