pub struct DevtoolsServiceProvider { /* private fields */ }Expand description
Turns the developer tools on in an application that registers it.
They run only in a build with debug assertions, with APP_ENV=local, and unless
DEVTOOLS_ENABLED=false: there the provider records every request, console command, queued
job and scheduled task into storage/devtools, which belongs in the application’s
.gitignore. Everywhere else, in its tests too, the provider adds nothing. A build without
debug assertions, as Cargo’s release profile is by default, has nothing of the developer tools
compiled in but DevtoolsConfig, so that an application’s configuration of it builds either
way. What decides is debug-assertions, not the profile’s name.
Who sees them: a browser on the application’s own machine, unless DEVTOOLS_LOCAL=false, and
anyone else who entered DEVTOOLS_KEY; of those, only whom a DevtoolsGate lets in, if the
application sets one with with_gate. A gate set with
with_admitting_gate lets in whom it allows besides them. Everyone
else gets neither the toolbar nor its routes, which answer 404.
use laravel_rust_devtools::DevtoolsServiceProvider;
laravel::Application::configure().with_providers(|providers| {
providers.add(DevtoolsServiceProvider::new());
});Implementations§
Source§impl DevtoolsServiceProvider
impl DevtoolsServiceProvider
Sourcepub fn new() -> Self
pub fn new() -> Self
The provider, letting in whom the rules above let in.
let provider = laravel_rust_devtools::DevtoolsServiceProvider::new();Sourcepub fn with_gate(self, gate: impl DevtoolsGate) -> Self
pub fn with_gate(self, gate: impl DevtoolsGate) -> Self
Let in only whom gate allows, of those the rules above let in. It replaces a gate set
before. A build without debug assertions has no developer tools, and drops the gate.
use laravel::http::Request;
use laravel_rust_devtools::{DevtoolsGate, DevtoolsServiceProvider};
struct Nobody;
impl DevtoolsGate for Nobody {
async fn allows(&self, _request: &Request) -> laravel::Result<bool> {
Ok(false)
}
}
let provider = DevtoolsServiceProvider::new().with_gate(Nobody);Sourcepub fn with_admitting_gate(self, gate: impl DevtoolsGate) -> Self
pub fn with_admitting_gate(self, gate: impl DevtoolsGate) -> Self
Let in whom gate allows as well as whom the rules above let in, such as the application’s
administrators in a browser behind a proxy, without the key. It replaces a gate set before.
The gate is asked for every request the rules keep out, after the session has started.
Before then, the developer tools can’t tell whom it will let in, so their routes take
everyone’s requests for the methods they have, and answer 404 to whom the gate turns away:
the answer the application gives a path that doesn’t exist, as long as its fallback
answers with laravel::abort(404), as new applications’ fallback does. With APP_DEBUG=true,
the error page of an error before the gate, or in it, names the route it was meant for. A
build without debug assertions has no developer tools, and drops the gate.
use laravel::http::Request;
use laravel_rust_devtools::{DevtoolsGate, DevtoolsServiceProvider};
/// Those logged in, wherever their browser is.
struct LoggedIn;
impl DevtoolsGate for LoggedIn {
async fn allows(&self, request: &Request) -> laravel::Result<bool> {
request.authenticated().await
}
}
let provider = DevtoolsServiceProvider::new().with_admitting_gate(LoggedIn);Sourcepub fn with_crates<I>(self, crates: I) -> Self
pub fn with_crates<I>(self, crates: I) -> Self
Also record the spans and lines of these downloaded crates, such as packages the
application installed from crates.io. Without them, the developer tools record the
framework and the application’s own crates, and the packages it builds from a path. Names
may be written with - or _.
A line belongs to a crate by its target’s first part, which is the crate’s name unless the crate sets targets of its own: name those instead.
A named crate’s lines are recorded by the same rules as the application’s: a field whose
name suggests a secret, such as password, token or session_id, as [masked], and
everything else as it was written, the line’s message and every field with an ordinary
name. Name only crates whose lines don’t carry values that everyone who can read the traces
may not see. Libraries whose lines carry values stay out even when named: sqlx and every
crate named sqlx_*, lettre and aws_smithy_runtime. A build without debug assertions has
no developer tools, and drops the names.
use laravel_rust_devtools::DevtoolsServiceProvider;
let provider = DevtoolsServiceProvider::new().with_crates(["laravel-rust-permissions"]);