Skip to content

Commit

Permalink
Add openapi schema and GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
kklingenberg committed Dec 15, 2023
1 parent df1f72e commit 7c36623
Show file tree
Hide file tree
Showing 4 changed files with 345 additions and 3 deletions.
64 changes: 63 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "k8s-job-dispatcher"
version = "0.4.1"
version = "0.4.2"
edition = "2021"

[dependencies]
Expand All @@ -21,3 +21,4 @@ serde_json = "1.0.108"
sha1 = "0.10.6"
tracing = { version = "0.1.40", features = ["log"] }
tracing-subscriber = { version = "0.3.18", default-features = false, features = ["fmt"] }
utoipa-rapidoc = { version = "2.0.0", features = ["actix-web"] }
18 changes: 17 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ mod jq;
mod k8s_service;
mod state;

use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer, Result as RouteResult};
use actix_web::{
http::header::ContentType, middleware, web, App, Error, HttpResponse, HttpServer,
Result as RouteResult,
};
use clap::Parser;
use k8s_openapi::api::batch::v1::Job;
use kube::{api::Api, Client, Config};
use std::path::PathBuf;
use std::time::Duration;
use tracing::warn;
use utoipa_rapidoc::RapiDoc;

const DEFAULT_FILTER: &str = include_str!("default_filter.jq");

Expand Down Expand Up @@ -39,6 +43,9 @@ async fn no_route() -> RouteResult<HttpResponse> {
Err::<_, Error>(api_error::APIError::not_found("Route not found").into())
}

/// OpenAPI schema
const OPENAPI: &str = include_str!("openapi.json");

#[actix_web::main]
async fn main() -> std::io::Result<()> {
let cli = Cli::parse();
Expand Down Expand Up @@ -80,6 +87,15 @@ async fn main() -> std::io::Result<()> {
.service(health_service::readiness_check)
.service(k8s_service::create_job)
.service(k8s_service::get_job)
.route(
"/openapi.json",
web::get().to(|| async {
HttpResponse::Ok()
.content_type(ContentType::json())
.body(OPENAPI)
}),
)
.service(RapiDoc::new("/openapi.json").path("/docs"))
.default_service(web::route().to(no_route))
})
.bind(("0.0.0.0", cli.port))?
Expand Down
Loading

0 comments on commit 7c36623

Please sign in to comment.