From 45a6ffcf325c583f7ffeff20e0516e7e7b95d5c5 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 24 May 2023 14:33:56 +0200 Subject: [PATCH] add ee_license endpoint --- backend/src/main.rs | 6 +++--- backend/windmill-api/openapi.yaml | 14 ++++++++++++++ backend/windmill-api/src/lib.rs | 29 +++++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/backend/src/main.rs b/backend/src/main.rs index 727416d694..4dd4a8f312 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -19,6 +19,7 @@ use tokio::{ join, sync::RwLock, }; +use windmill_api::LICENSE_KEY; use windmill_common::{utils::rd_string, METRICS_ADDR}; use windmill_worker::{ DENO_CACHE_DIR, DENO_TMP_CACHE_DIR, GO_CACHE_DIR, GO_TMP_CACHE_DIR, HUB_CACHE_DIR, @@ -270,12 +271,11 @@ pub async fn run_workers, ) -> anyhow::Result<()> { - let license_key = std::env::var("LICENSE_KEY").ok(); #[cfg(feature = "enterprise")] - ee::verify_license_key(license_key)?; + ee::verify_license_key(LICENSE_KEY.clone())?; #[cfg(not(feature = "enterprise"))] - if license_key.is_some() { + if LICENSE_KEY.is_some() { panic!("License key is required ONLY for the enterprise edition"); } diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 78568879b0..fd1f1f335b 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -41,6 +41,20 @@ paths: schema: type: string + /ee_license: + get: + summary: get license id + operationId: getLicenseId + tags: + - settings + responses: + "200": + description: get license id (empty if not ee) + content: + text/plain: + schema: + type: string + /openapi.yaml: get: summary: get openapi yaml spec diff --git a/backend/windmill-api/src/lib.rs b/backend/windmill-api/src/lib.rs index 99a05f3901..7e87fdf8c7 100644 --- a/backend/windmill-api/src/lib.rs +++ b/backend/windmill-api/src/lib.rs @@ -86,6 +86,8 @@ lazy_static::lazy_static! { pub static ref OAUTH_CLIENTS: AllClients = build_oauth_clients(&BASE_URL) .map_err(|e| tracing::error!("Error building oauth clients: {}", e)) .unwrap(); + + pub static ref LICENSE_KEY: Option = std::env::var("LICENSE_KEY").ok(); } pub async fn run_server( @@ -186,6 +188,7 @@ pub async fn run_server( ) .nest("/oauth", oauth2::global_service()) .route("/version", get(git_v)) + .route("/ee_license", get(ee_license)) .route("/openapi.yaml", get(openapi)), ) .fallback(static_assets::static_handler) @@ -207,8 +210,30 @@ pub async fn run_server( Ok(()) } -async fn git_v() -> &'static str { - GIT_VERSION +#[cfg(feature = "enterprise")] +async fn git_v() -> String { + format!("EE {GIT_VERSION}") +} + +#[cfg(not(feature = "enterprise"))] +async fn git_v() -> String { + format!("CE {GIT_VERSION}") +} + +#[cfg(feature = "enterprise")] +async fn ee_license() -> &'static str { + "" +} + +#[cfg(not(feature = "enterprise"))] +async fn ee_license() -> String { + LICENSE_KEY + .as_ref() + .unwrap() + .split(".") + .next() + .unwrap() + .to_string() } async fn openapi() -> &'static str {