use axum::extract::{Path, State};
use axum::response::Html;
use crate::webadmin::AdminState;
use crate::webadmin::error::AdminError;
use crate::webadmin::handlers::misc::profile_row;
use crate::webadmin::pages::auth::PageSession;
use crate::webadmin::pages::error::PageError;
use crate::webadmin::pages::{chrome, respond};
use acme_proxy_policy::filter::explain::policy_json;
pub async fn get_profile_filter(
State(state): State<AdminState>,
Path(name): Path<String>,
session: PageSession,
) -> Result<Html<String>, PageError> {
let profile = state.profiles.get(&name).ok_or_else(|| not_found(&name))?;
let mut context = chrome(
&session,
"profiles",
&format!("Filter policy: {}", profile.name),
);
context.insert("endpoint".to_string(), profile_row(profile));
context.insert(
"policy".to_string(),
policy_json(&profile.name, &profile.filter),
);
respond(
&state,
false,
"profiles/filter.html",
"profiles/filter.html",
context,
)
}
fn not_found(name: &str) -> PageError {
AdminError::not_found(crate::admin::subject::Subject::Profile.missing(name)).into()
}