Lines
100 %
Functions
Branches
use std::collections::HashMap;
use axum::{http::Method, routing, Router};
use super::super::{
middleware::{AuthService, RoleScopeType},
State,
};
mod api;
mod request;
mod response;
pub use api::{init, new_ctrl_receiver, new_ctrl_sender};
pub fn new_service(scope_path: &str, state: &State) -> Router {
let mut role_scopes_root: HashMap<Method, RoleScopeType> = HashMap::new();
let mut role_scopes_count: HashMap<Method, RoleScopeType> = HashMap::new();
let mut role_scopes_list: HashMap<Method, RoleScopeType> = HashMap::new();
let mut role_scopes_param: HashMap<Method, RoleScopeType> = HashMap::new();
match state.api_scopes.get("application.post") {
None => {
role_scopes_root.insert(Method::POST, (vec![], vec![]));
}
Some(scopes) => {
role_scopes_root.insert(Method::POST, (vec![], scopes.clone()));
match state.api_scopes.get("application.get") {
role_scopes_count.insert(Method::GET, (vec![], vec![]));
role_scopes_list.insert(Method::GET, (vec![], vec![]));
role_scopes_param.insert(Method::GET, (vec![], vec![]));
role_scopes_count.insert(Method::GET, (vec![], scopes.clone()));
role_scopes_list.insert(Method::GET, (vec![], scopes.clone()));
role_scopes_param.insert(Method::GET, (vec![], scopes.clone()));
match state.api_scopes.get("application.patch") {
role_scopes_param.insert(Method::PATCH, (vec![], vec![]));
role_scopes_param.insert(Method::PATCH, (vec![], scopes.clone()));
match state.api_scopes.get("application.delete") {
role_scopes_param.insert(Method::DELETE, (vec![], vec![]));
role_scopes_param.insert(Method::DELETE, (vec![], scopes.clone()));
let auth_uri = format!("{}/api/v1/auth/tokeninfo", state.auth_base.as_str());
Router::new().nest(
scope_path,
Router::new()
.route(
"/",
routing::post(api::post_application)
.layer(AuthService::new(auth_uri.clone(), role_scopes_root)),
)
"/count",
routing::get(api::get_application_count)
.layer(AuthService::new(auth_uri.clone(), role_scopes_count)),
"/list",
routing::get(api::get_application_list)
.layer(AuthService::new(auth_uri.clone(), role_scopes_list)),
"/:application_id",
routing::get(api::get_application)
.patch(api::patch_application)
.delete(api::delete_application)
.layer(AuthService::new(auth_uri.clone(), role_scopes_param)),
.with_state(state.clone()),