| Crates.io | this-env |
| lib.rs | this-env |
| version | 0.1.31 |
| created_at | 2025-06-25 04:39:50.010374+00 |
| updated_at | 2025-07-08 20:02:26.911625+00 |
| description | This.Env Data Formatter |
| homepage | https://neurons.me |
| repository | https://github.com/neurons-me/this.audio |
| max_upload_size | |
| id | 1725315 |
| size | 130,077 |
Light‑weight environment recognition & trust middleware for Rust. It provides a simple, extensible way to determine the origin of requests and their trustworthiness, allowing your application to make informed decisions about how to handle them.
Goal: Let your application decide and learn where it is running (localhost, extensions, remote web, CLI, …) and how much it should trust that origin – before you execute business‑logic.
| Call | What it gives you |
|---|---|
Env::resolve(&EnvRequest) |
Returns EnvStatus (Approved, PendingApproval, Blocked). |
Env::status(&self, db) |
Re‑evaluate status for an existing Env. |
Env::add_endorsement(db, e) |
Add / change a user decision. |
Env::get_endorsements(db, domain) |
List all recorded decisions. |
Env::is_endorsed_by(db, domain, who) |
true / false. |
All data lives in a single .db file next to your executable. No server, no migrations.
A smart middleware system that inspects incoming HTTP requests and evaluates their environment (origin, IP, headers, cookies, etc.) to determine whether the request should be Approved, Blocked, or Pending Approval. It is ideal for building decentralized permission systems and real-time trust evaluation.
EnvResquestInfo - information about the request, such as method, path, host, timestamp, etc. EnvRequestLog - a log entry for a request, including method, path, host, timestamp, and status as minimal data.
use this_env::actixMiddleware; // import
// Inside your Actix `App` builder
App::new()
.wrap(actixMiddleware::default()) // 1‑line, sensible defaults
.configure(routes::config);
Add Port Number to the Middleware.
### Custom rules
use this_env::{actixMiddleware, ActixMwConfig};
let cfg = ActixMwConfig {
allow_pending: true, // let “unknown yet” domains through
prefer_html: true, // serve pretty HTML pages to browsers
..Default::default() // keep the rest as default
};
App::new()
.wrap(actixMiddleware::config(cfg))
.configure(routes::config);
This file defines a status handler using this.env. It responds to HTTP GET requests at the /status endpoint with the current environment status. It uses the this.env crate to read the environment status stored by the middleware. The response includes the status, port, and username in JSON format.
use actix_web::{get, HttpRequest, HttpResponse, Responder, HttpMessage};
use this_env::EnvStatus;
use serde_json::json;
#[get("/status")]
async fn status(req: HttpRequest) -> impl Responder {
let decision = req
.extensions()
.get::<EnvStatus>()
.unwrap(); // Safe in this context; middleware always sets it
HttpResponse::Ok().json(json!({
"status": format!("{decision:?}")
}))
}
Approved – trusted, go ahead.PendingApproval – first time seen, ask the user.Blocked – explicitly forbidden.let env_request = Env::from_request(&req);
This attempts to extract identifying info (e.g., origin, IP, etc.) into an evaluable context.
pub enum EnvStatus {
Approved,
PendingApproval(PendingData),
Blocked(String),
}
• Approved: The request is trusted and allowed to proceed. • PendingApproval(data): The request is not yet decided; it awaits user confirmation or other logic. • Blocked(reason): The request is explicitly denied, with an optional reason string.
let status = match env_request {
Some(env) => Env::resolve(&env).unwrap_or(EnvStatus::Blocked("not-resolved".into())),
None => EnvStatus::Blocked("missing-env".into()),
};
You can use this logic to return a JSON response in your Actix handler:
let status_str = match resolved_status {
EnvStatus::Approved => "approved",
EnvStatus::PendingApproval(_) => "pending",
EnvStatus::Blocked(_) => "blocked",
};
HttpResponse::Ok().json(StatusResponse {
status: status_str.to_string(),
port: 7777,
username: "abellae",
});
Maintained by neurons.me — crafted with ☕ by suiGn.