|
|
@ -1,16 +1,12 @@ |
|
|
|
mod auth; |
|
|
|
mod auth; |
|
|
|
mod headers; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use std::sync::Arc; |
|
|
|
use std::sync::Arc; |
|
|
|
|
|
|
|
|
|
|
|
use axum::middleware; |
|
|
|
use axum::middleware; |
|
|
|
use axum::routing::get; |
|
|
|
use axum::routing::get; |
|
|
|
use headers::cipwd::CiPwd; |
|
|
|
use axum::Json; |
|
|
|
use headers::cirole::CiRole; |
|
|
|
|
|
|
|
use headers::ciusr::CiUsr; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use axum::routing::Router; |
|
|
|
use axum::routing::Router; |
|
|
|
use axum::TypedHeader; |
|
|
|
|
|
|
|
use clap::Parser; |
|
|
|
use clap::Parser; |
|
|
|
use dotenv::dotenv; |
|
|
|
use dotenv::dotenv; |
|
|
|
use mongodb::options::ClientOptions; |
|
|
|
use mongodb::options::ClientOptions; |
|
|
@ -24,11 +20,18 @@ struct Params { |
|
|
|
|
|
|
|
|
|
|
|
#[clap(short, long, env = "MONGO_URI")] |
|
|
|
#[clap(short, long, env = "MONGO_URI")] |
|
|
|
mongo_addr: String, |
|
|
|
mongo_addr: String, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[clap(long, env = "CIUSR")] |
|
|
|
|
|
|
|
ci_usr: String, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[clap(long, env = "CIPWD")] |
|
|
|
|
|
|
|
ci_pwd: String, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[clap(long, env = "CIROLE")] |
|
|
|
|
|
|
|
ci_role: String, |
|
|
|
|
|
|
|
} |
|
|
|
struct State { |
|
|
|
struct State { |
|
|
|
db: Database, |
|
|
|
db: Database, |
|
|
|
collections: Vec<String>, |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[tokio::main] |
|
|
|
#[tokio::main] |
|
|
@ -45,7 +48,9 @@ async fn main() { |
|
|
|
let collections = db.list_collection_names(None).await.unwrap(); |
|
|
|
let collections = db.list_collection_names(None).await.unwrap(); |
|
|
|
tracing::debug!("Collections = {:?}", &collections); |
|
|
|
tracing::debug!("Collections = {:?}", &collections); |
|
|
|
|
|
|
|
|
|
|
|
let state = Arc::new(State { db, collections }); |
|
|
|
let state = Arc::new(State { |
|
|
|
|
|
|
|
db, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
let app = Router::new().route("/", get(index)).route( |
|
|
|
let app = Router::new().route("/", get(index)).route( |
|
|
|
"/collections", |
|
|
|
"/collections", |
|
|
@ -54,7 +59,11 @@ async fn main() { |
|
|
|
move || get_collections(Arc::clone(&shared_state)) |
|
|
|
move || get_collections(Arc::clone(&shared_state)) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.route_layer(middleware::from_fn(move |req, next| { |
|
|
|
.route_layer(middleware::from_fn(move |req, next| { |
|
|
|
auth::ci_auth(req, next, "A", "A", "A") |
|
|
|
let ci_usr = args.ci_usr.clone(); |
|
|
|
|
|
|
|
let ci_pwd = args.ci_pwd.clone(); |
|
|
|
|
|
|
|
let ci_role = args.ci_role.clone(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auth::ci_auth(req, next, ci_usr, ci_pwd, ci_role) |
|
|
|
})), |
|
|
|
})), |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
@ -65,14 +74,11 @@ async fn main() { |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async fn index( |
|
|
|
async fn index() -> String { |
|
|
|
TypedHeader(usr): TypedHeader<CiUsr>, |
|
|
|
format!("Hellow") |
|
|
|
TypedHeader(_pwd): TypedHeader<CiPwd>, |
|
|
|
|
|
|
|
TypedHeader(_role): TypedHeader<CiRole>, |
|
|
|
|
|
|
|
) -> String { |
|
|
|
|
|
|
|
format!("Hellow {}", usr) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async fn get_collections(state: Arc<State>) -> String { |
|
|
|
async fn get_collections(state: Arc<State>) -> Json<Vec<String>> { |
|
|
|
format!("Collections") |
|
|
|
let collections = state.db.list_collection_names(None).await.unwrap(); |
|
|
|
|
|
|
|
Json(collections) |
|
|
|
} |
|
|
|
} |
|
|
|