To accommodate access to multiple protocols Moonraker will always
require that the "params" field contain a dictionary, so reject any
other type as invalid. There is no need to expand keyword arguments,
simply pass the params dict to the callback.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Add basic support "agents", ie: unmanaged extensions. Connected
agents are granted a limited ability to emit websocket notifications
and process rpc requests from Moonraker.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
HTTP 404 and JSON-RPC -32601 are equivalent, so translate
where necessary. Any other JRPC code received outside of the
HTTP error range should be assigned a 500.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Handle exceptions should the attempt to fetch peer
credentials on the unix socket fail. This isn't a hard
requirement for connection and should not cause
the connection to abort.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This prevents a scenario where a request handler mutates
the arguments of a WebRequest, which could result in
changing the default "request_arguments" in
"InternalTransport.call_method()".
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This is a reimplementation of commit d61540cad5,
however this attempt provides a fallback for legacy configurations
that still have configuration in the server section.
This will change how `/server/config` reports configuration. Options
will always be reported in their respective component's field, even if
they are currently configured in the `[server]` section.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This isn't necessary as we don't add new sections to the
original config object when parsing supplemental data.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This replaces the previous "get_sd_directory()" method, allowing
consumers to get any registered root path.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This isn't necessary as we don't add new sections to the
original config object when parsing supplemental data.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Most core components have default options that allow them to
load without a section specified in moonraker.conf. This resulted
in those options showing up in the [server] section in the
"/server/config" response. These changes will make sure that those
values show up in the correct section.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Use git for-each-ref to retreive tags and their associated commit
hashes. This allows us to limit the amount of tags to 10 and
simplifies the code as the returned objects are already dereferenced.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Don't require the `app_params` argument, instead dynamically
generate the configuration from a dict. This simiplifies AppDeploy
initialization as the internally generated configurations can be
read in the same way as those supplied in moonraker.conf.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
While use of "unofficial" klippy extras an moonraker components
is not officially supported, there is no harm in facilitating
updates for these extensions in the update manager. This adds
configuration which will restart either moonraker or klipper
after an extension is updated.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
If "None" is specified as a separator for getdict and the getlist
variants then strings will split along any whitespace character.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Don't require a config object to instantiate and don't attempt
to wrap database namespace. These changes allow instantation
after the server has started.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
While the curl based client is better in most respects, it requires
that libcurl be against with an asynchronous DNS resolver, such
as c-ares, in order to prevent blocking. As of now it Debian does
not ship with a version of curl with ares enabled. Fall back to the
simple client until this can be resolved.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Its possible for users to have an unstable internet connection. Log
connection errors rather than warn.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The parsed feeds are stored in the DB, so there is no
need to cache the result when 304 is returned.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This adds support for announcements retreived via RSS feed from
the "moonlight" GitHub repo. Announcements may also be procedurally
generated internally.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When using tempfile.TemporaryDirectory it is possible that
exiting the context will block when attempting to delete
the temporary directory. Don't use the context manager,
instead create and cleanup the temp dir using the default
threadpoolexecutor.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This abstracts the tornado http client from the rest of Moonraker,
allowing all components to access the client's most used functionality
without importing tornado modules.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Provide a remote method by which clients may identify their
name, version, and type.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
fix
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
By retreiving and storing the hostname in the websocket
header, it is possible to determine a fully qualified domain
used to reach the instance.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Refactor the PowerDevice initialize() method so that it acquires the
request lock. Always register the "klippy_started" event if the
"restart_klipper" option is set, and always check if Klipper is is
the ready state before performing the restart. Remove stale
PowerDevice methods no longer used.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This method can be used by other components to check if Moonraker has
access to a particular file or folder.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Don't raise an exeption if the config or log paths are invalid,
add warnings instead. This allows the user to see what is wrong
and resolve this issue.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Make sure that paths registered with full access do not overlap one
another, nor that they overlap sensitive folders such as the database,
Moonraker's source, or Klipper's source.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This option was intended for Moonraker developers to live test
changes to write protected namespaces. This can be accomplished
locally with other methods, thus this option has been removed to
prevent users from compromising sections of the database.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This component will be a bridge between moonraker and https://github.com/caronc/apprise. This way users can easily add all kind of notification services to their printer.
Signed-off-by: Pieter Willekens <me@pataar.nl>
Moonraker depends on "future" annotations and uses fstrings, so
versions of Python older than 3.7 will fail to load and never make
it to the version check.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Start tracking the Remote API version separately from the application
version. This allows the API to stick to semantic versioning while
and track the application version separately. This is necessary as
we prepare to release a beta.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rename the "on_when_upload_queued" option to "on_when_job_queued",
deprecate the former. This option now applies to any queued job while
the device is off.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The "wait_connected" method would block indefinitely until a klippy
connection is established. This isn't the behavior we want, we only
want to wait "if" a connection has been established until Klippy
reports that its startup sequence is complete.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This makes the order in which they are reported consistent,
as the namespaces are stored in a set.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It is possible to reduce to a value that is not a dict in "insert_item()"
and "update_item()". Raise a ServerError with a clear description of
what went wrong in these situations.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It is possible that Moonraker can be instantiated while the eventloop
is running during tests. To avoid errors allow synchronous calls until
the server starts.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Since the User DB is not going to be large cache the users
in local memory and sync with the DB when changes are
made to the local user store.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Now that all transactions run in a thread it is possible for them to
interleave. The record based operations allow for batch operations
within a single transaction.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Wrap command implementations in with a _run_command() method. All
database commands now return a Future object. If the command was
run before the eventloop starts its possible to immediately query
the Future's result.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Similar to the update method, however sync will remove any
keys in the database not in the new value.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than creating two wrappers, use a single wrapper whose methods
always return a future or awaitable. If the operation occurs during
the __init__() method of a component it will be syncrhonous, and the
result from the future can be immediately queried.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than reading out the entire database, attempt to pop off
empty keys in each database. This should should speed up
init on platforms with slow disk I/O and prevents reading
large namespaces in memory.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It isn't necessary to read out the entire namespace, just attempt
to fetch the record and reduce the key list.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Since transactions are now threaded we need updating
and clearing a namespace needs to be performed within
one transaction.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Database transactions can perform disk I/O tasks, which at times will
block the eventloop. Run all transactions in threads to prevent this
from occuring.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The read() method will return an empty list if the file specified
does not exist or if the read failed in some fashion.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Moonraker requires that some Klipper objects be configured
and loaded. This check has always been performed and logged,
now track and report missing requirements.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Move the KlippyConnection class into its own module. Refactor
init to use loops rather than callbacks, this reduces complexity
of tracking and cancelling callback handles.
All Klippy state previously tracked by the Server is now in the
KlippyConnection. This improves testing and makes the code
less ambiguous, ie: the `server.make_request()` method is not
as clear as `klippy.request()`.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Move the version check to the top of the module. An older version
of python is unlikely to make it beyond the initial import statements,
so print a message to stdout and stderr.
Move argument parsing out of the main method. This makes it possible
to invoke main without parsing command line arguments, which is useful
for tests.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than instantiate a new version of the event loop wrapper
we can simply reset the internal event loop.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>