Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/db_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ impl SqliteScanPathService {
.collect())
}

pub async fn insert_configurations(
&self,
configs: &[InstrumentConfiguration],
) -> Result<(), ()> {
todo!()
}

pub async fn next_scan_configuration(
&self,
instrument: &str,
Expand Down
11 changes: 10 additions & 1 deletion src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use async_graphql::{
};
use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
use auth::{AuthError, PolicyCheck};
use axum::extract::State;
use axum::http::StatusCode;
use axum::response::{Html, IntoResponse};
use axum::routing::{get, post};
Expand Down Expand Up @@ -67,14 +68,16 @@ pub async fn serve_graphql(opts: ServeOptions) {
let schema = Schema::build(Query, Mutation, EmptySubscription)
.extension(Tracing)
.limit_directives(32)
.data(db)
.data(db.clone())
.data(directory_numtracker)
.data(opts.policy.map(PolicyCheck::new))
.finish();
let app = Router::new()
// status check endpoint allows external processes to monitor status of server without
// making graphql queries
.route("/status", get(server_status))
.route("/admin/export", get(export_handler))
// .route("/admin/restore", post(restore_handler))
.route("/graphql", post(graphql_handler))
// make it obvious that /graphql isn't expected to work when visiting from a browser
.route(
Expand All @@ -88,6 +91,7 @@ pub async fn serve_graphql(opts: ServeOptions) {
// Interactive graphiql playground
.route("/graphiql", get(graphiql))
// Make it look less like something is broken when going to any other page
.with_state(db)
.fallback((
StatusCode::NOT_FOUND,
Html(include_str!("../../static/404.html")),
Expand All @@ -102,6 +106,11 @@ pub async fn serve_graphql(opts: ServeOptions) {
.expect("Can't serve graphql endpoint");
}

async fn export_handler(State(db): State<SqliteScanPathService>) -> String {
let configs = db.all_configurations().await;
return format!("{configs:?}");
}

async fn create_signal_handler() {
let mut term = signal(SignalKind::terminate()).expect("Failed to create SIGTERM listener");
let mut int = signal(SignalKind::interrupt()).expect("Failed to create SIGINT listener");
Expand Down
Loading