|
|
|
@ -1,16 +1,12 @@
|
|
|
|
|
mod auth; |
|
|
|
|
mod headers; |
|
|
|
|
|
|
|
|
|
use std::sync::Arc; |
|
|
|
|
|
|
|
|
|
use axum::middleware; |
|
|
|
|
use axum::routing::get; |
|
|
|
|
use headers::cipwd::CiPwd; |
|
|
|
|
use headers::cirole::CiRole; |
|
|
|
|
use headers::ciusr::CiUsr; |
|
|
|
|
use axum::Json; |
|
|
|
|
|
|
|
|
|
use axum::routing::Router; |
|
|
|
|
use axum::TypedHeader; |
|
|
|
|
use clap::Parser; |
|
|
|
|
use dotenv::dotenv; |
|
|
|
|
use mongodb::options::ClientOptions; |
|
|
|
@ -24,11 +20,18 @@ struct Params {
|
|
|
|
|
|
|
|
|
|
#[clap(short, long, env = "MONGO_URI")] |
|
|
|
|
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 { |
|
|
|
|
db: Database, |
|
|
|
|
collections: Vec<String>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[tokio::main] |
|
|
|
@ -45,7 +48,9 @@ async fn main() {
|
|
|
|
|
let collections = db.list_collection_names(None).await.unwrap(); |
|
|
|
|
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( |
|
|
|
|
"/collections", |
|
|
|
@ -54,7 +59,11 @@ async fn main() {
|
|
|
|
|
move || get_collections(Arc::clone(&shared_state)) |
|
|
|
|
}) |
|
|
|
|
.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(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async fn index( |
|
|
|
|
TypedHeader(usr): TypedHeader<CiUsr>, |
|
|
|
|
TypedHeader(_pwd): TypedHeader<CiPwd>, |
|
|
|
|
TypedHeader(_role): TypedHeader<CiRole>, |
|
|
|
|
) -> String { |
|
|
|
|
format!("Hellow {}", usr) |
|
|
|
|
async fn index() -> String { |
|
|
|
|
format!("Hellow") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async fn get_collections(state: Arc<State>) -> String { |
|
|
|
|
format!("Collections") |
|
|
|
|
async fn get_collections(state: Arc<State>) -> Json<Vec<String>> { |
|
|
|
|
let collections = state.db.list_collection_names(None).await.unwrap(); |
|
|
|
|
Json(collections) |
|
|
|
|
} |
|
|
|
|