mirror of
https://github.com/CloudNebulaProject/barycenter.git
synced 2026-04-10 13:10:42 +00:00
chore: formatting
Signed-off-by: Till Wegmueller <toasterson@gmail.com>
This commit is contained in:
parent
06bff60122
commit
e8a060d7c3
6 changed files with 35 additions and 43 deletions
|
|
@ -64,10 +64,7 @@ async fn seaography_handler(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Jobs GraphQL POST handler for job management
|
/// Jobs GraphQL POST handler for job management
|
||||||
async fn jobs_handler(
|
async fn jobs_handler(State(state): State<Arc<JobsState>>, req: GraphQLRequest) -> GraphQLResponse {
|
||||||
State(state): State<Arc<JobsState>>,
|
|
||||||
req: GraphQLRequest,
|
|
||||||
) -> GraphQLResponse {
|
|
||||||
state.schema.execute(req.into_inner()).await.into()
|
state.schema.execute(req.into_inner()).await.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
38
src/jobs.rs
38
src/jobs.rs
|
|
@ -2,7 +2,10 @@ use crate::entities;
|
||||||
use crate::errors::CrabError;
|
use crate::errors::CrabError;
|
||||||
use crate::storage;
|
use crate::storage;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use sea_orm::{ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, Set};
|
use sea_orm::{
|
||||||
|
ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter,
|
||||||
|
Set,
|
||||||
|
};
|
||||||
use tokio_cron_scheduler::{Job, JobScheduler};
|
use tokio_cron_scheduler::{Job, JobScheduler};
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
|
|
||||||
|
|
@ -27,21 +30,15 @@ pub async fn init_scheduler(db: DatabaseConnection) -> Result<JobScheduler, Crab
|
||||||
Ok(count) => {
|
Ok(count) => {
|
||||||
info!("Cleaned up {} expired sessions", count);
|
info!("Cleaned up {} expired sessions", count);
|
||||||
if let Some(id) = execution_id {
|
if let Some(id) = execution_id {
|
||||||
let _ = complete_job_execution(&db, id, true, None, Some(count as i64))
|
let _ =
|
||||||
.await;
|
complete_job_execution(&db, id, true, None, Some(count as i64)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to cleanup expired sessions: {}", e);
|
error!("Failed to cleanup expired sessions: {}", e);
|
||||||
if let Some(id) = execution_id {
|
if let Some(id) = execution_id {
|
||||||
let _ = complete_job_execution(
|
let _ =
|
||||||
&db,
|
complete_job_execution(&db, id, false, Some(e.to_string()), None).await;
|
||||||
id,
|
|
||||||
false,
|
|
||||||
Some(e.to_string()),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -69,21 +66,15 @@ pub async fn init_scheduler(db: DatabaseConnection) -> Result<JobScheduler, Crab
|
||||||
Ok(count) => {
|
Ok(count) => {
|
||||||
info!("Cleaned up {} expired refresh tokens", count);
|
info!("Cleaned up {} expired refresh tokens", count);
|
||||||
if let Some(id) = execution_id {
|
if let Some(id) = execution_id {
|
||||||
let _ = complete_job_execution(&db, id, true, None, Some(count as i64))
|
let _ =
|
||||||
.await;
|
complete_job_execution(&db, id, true, None, Some(count as i64)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to cleanup expired refresh tokens: {}", e);
|
error!("Failed to cleanup expired refresh tokens: {}", e);
|
||||||
if let Some(id) = execution_id {
|
if let Some(id) = execution_id {
|
||||||
let _ = complete_job_execution(
|
let _ =
|
||||||
&db,
|
complete_job_execution(&db, id, false, Some(e.to_string()), None).await;
|
||||||
id,
|
|
||||||
false,
|
|
||||||
Some(e.to_string()),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +167,10 @@ pub async fn trigger_job_manually(
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(count) => {
|
Ok(count) => {
|
||||||
info!("Manually triggered job {} completed: {} records", job_name, count);
|
info!(
|
||||||
|
"Manually triggered job {} completed: {} records",
|
||||||
|
job_name, count
|
||||||
|
);
|
||||||
complete_job_execution(db, execution_id, true, None, Some(count as i64)).await?;
|
complete_job_execution(db, execution_id, true, None, Some(count as i64)).await?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,8 @@ impl Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Environment overrides: BARYCENTER__SERVER__PORT=9090, etc.
|
// Environment overrides: BARYCENTER__SERVER__PORT=9090, etc.
|
||||||
builder = builder.add_source(config::Environment::with_prefix("BARYCENTER").separator("__"));
|
builder =
|
||||||
|
builder.add_source(config::Environment::with_prefix("BARYCENTER").separator("__"));
|
||||||
|
|
||||||
let cfg = builder.build().into_diagnostic()?;
|
let cfg = builder.build().into_diagnostic()?;
|
||||||
let mut s: Settings = cfg.try_deserialize().into_diagnostic()?;
|
let mut s: Settings = cfg.try_deserialize().into_diagnostic()?;
|
||||||
|
|
|
||||||
|
|
@ -423,11 +423,7 @@ pub async fn consume_auth_code(
|
||||||
) -> Result<Option<AuthCode>, CrabError> {
|
) -> Result<Option<AuthCode>, CrabError> {
|
||||||
use entities::auth_code::{Column, Entity};
|
use entities::auth_code::{Column, Entity};
|
||||||
|
|
||||||
if let Some(model) = Entity::find()
|
if let Some(model) = Entity::find().filter(Column::Code.eq(code)).one(db).await? {
|
||||||
.filter(Column::Code.eq(code))
|
|
||||||
.one(db)
|
|
||||||
.await?
|
|
||||||
{
|
|
||||||
let now = Utc::now().timestamp();
|
let now = Utc::now().timestamp();
|
||||||
if model.consumed != 0 || now > model.expires_at {
|
if model.consumed != 0 || now > model.expires_at {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
|
|
|
||||||
|
|
@ -45,13 +45,7 @@ pub async fn sync_users_from_file(db: &DatabaseConnection, file_path: &str) -> R
|
||||||
// Read and parse JSON file
|
// Read and parse JSON file
|
||||||
let content = fs::read_to_string(file_path)
|
let content = fs::read_to_string(file_path)
|
||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
.map_err(|e| {
|
.map_err(|e| miette::miette!("Failed to read users file at '{}': {}", file_path, e))?;
|
||||||
miette::miette!(
|
|
||||||
"Failed to read users file at '{}': {}",
|
|
||||||
file_path,
|
|
||||||
e
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let users_file: UsersFile = serde_json::from_str(&content)
|
let users_file: UsersFile = serde_json::from_str(&content)
|
||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
|
|
@ -165,7 +159,9 @@ async fn sync_user(db: &DatabaseConnection, user_def: &UserDefinition) -> Result
|
||||||
let user = storage::get_user_by_username(db, &user_def.username)
|
let user = storage::get_user_by_username(db, &user_def.username)
|
||||||
.await
|
.await
|
||||||
.into_diagnostic()?
|
.into_diagnostic()?
|
||||||
.ok_or_else(|| miette::miette!("User not found after creation: {}", user_def.username))?;
|
.ok_or_else(|| {
|
||||||
|
miette::miette!("User not found after creation: {}", user_def.username)
|
||||||
|
})?;
|
||||||
|
|
||||||
storage::set_property(db, &user.subject, key, value)
|
storage::set_property(db, &user.subject, key, value)
|
||||||
.await
|
.await
|
||||||
|
|
|
||||||
14
src/web.rs
14
src/web.rs
|
|
@ -105,7 +105,10 @@ pub async fn serve(
|
||||||
.route("/.well-known/openid-configuration", get(discovery))
|
.route("/.well-known/openid-configuration", get(discovery))
|
||||||
.route("/.well-known/jwks.json", get(jwks_handler))
|
.route("/.well-known/jwks.json", get(jwks_handler))
|
||||||
.route("/connect/register", post(register_client))
|
.route("/connect/register", post(register_client))
|
||||||
.route("/properties/{owner}/{key}", get(get_property).put(set_property))
|
.route(
|
||||||
|
"/properties/{owner}/{key}",
|
||||||
|
get(get_property).put(set_property),
|
||||||
|
)
|
||||||
.route("/federation/trust-anchors", get(trust_anchors))
|
.route("/federation/trust-anchors", get(trust_anchors))
|
||||||
.route("/login", get(login_page).post(login_submit))
|
.route("/login", get(login_page).post(login_submit))
|
||||||
.route("/logout", get(logout))
|
.route("/logout", get(logout))
|
||||||
|
|
@ -149,7 +152,10 @@ pub async fn serve(
|
||||||
.await
|
.await
|
||||||
.into_diagnostic()?;
|
.into_diagnostic()?;
|
||||||
tracing::info!(%admin_addr, "Admin GraphQL API listening");
|
tracing::info!(%admin_addr, "Admin GraphQL API listening");
|
||||||
tracing::info!("GraphQL Playground available at http://{}/admin/playground", admin_addr);
|
tracing::info!(
|
||||||
|
"GraphQL Playground available at http://{}/admin/playground",
|
||||||
|
admin_addr
|
||||||
|
);
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
axum::serve(admin_listener, admin_router)
|
axum::serve(admin_listener, admin_router)
|
||||||
|
|
@ -1191,7 +1197,9 @@ async fn set_property(
|
||||||
None => {
|
None => {
|
||||||
return (
|
return (
|
||||||
StatusCode::UNAUTHORIZED,
|
StatusCode::UNAUTHORIZED,
|
||||||
Json(json!({"error": "missing_token", "error_description": "Bearer token required"})),
|
Json(
|
||||||
|
json!({"error": "missing_token", "error_description": "Bearer token required"}),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.into_response();
|
.into_response();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue