From 3998ecbf7b5c1c1e4ed9f6fb8911e1e18317f815 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sat, 7 Sep 2024 21:21:52 +0200 Subject: [PATCH] fix(cli): guide users to migrate to node version of the CLI --- backend/src/monitor.rs | 2 + backend/windmill-api/src/settings.rs | 11 +----- backend/windmill-common/src/s3_helpers.rs | 7 ++-- cli/main.ts | 38 ++++++++++--------- .../src/lib/components/TestConnection.svelte | 30 ++++++++++++--- 5 files changed, 51 insertions(+), 37 deletions(-) diff --git a/backend/src/monitor.rs b/backend/src/monitor.rs index b664e93ae2e51..57fd9f62dbfb1 100644 --- a/backend/src/monitor.rs +++ b/backend/src/monitor.rs @@ -802,7 +802,9 @@ pub async fn reload_s3_cache_setting(db: &DB) { secret_key: None, endpoint: None, store_logs: None, + path_style: None, allow_http: None, + port: None, }) .await .ok(); diff --git a/backend/windmill-api/src/settings.rs b/backend/windmill-api/src/settings.rs index b26ee8bab07cc..7f4e7dfdcc702 100644 --- a/backend/windmill-api/src/settings.rs +++ b/backend/windmill-api/src/settings.rs @@ -104,21 +104,12 @@ use windmill_common::s3_helpers::build_object_store_from_settings; #[cfg(feature = "parquet")] pub async fn test_s3_bucket( - Extension(db): Extension, - authed: ApiAuthed, + _authed: ApiAuthed, Json(test_s3_bucket): Json, ) -> error::Result { use bytes::Bytes; use futures::StreamExt; - use windmill_common::ee::{get_license_plan, LicensePlan}; - if matches!(get_license_plan().await, LicensePlan::Pro) { - return Err(error::Error::InternalErr( - "This feature is only available in Enterprise, not Pro".to_string(), - )); - } - - require_super_admin(&db, &authed.email).await?; let client = build_object_store_from_settings(test_s3_bucket).await?; let mut list = client.list(Some(&object_store::path::Path::from("".to_string()))); diff --git a/backend/windmill-common/src/s3_helpers.rs b/backend/windmill-common/src/s3_helpers.rs index c9c2db30dbb78..198283db2de03 100644 --- a/backend/windmill-common/src/s3_helpers.rs +++ b/backend/windmill-common/src/s3_helpers.rs @@ -64,7 +64,6 @@ pub enum StorageResourceType { #[derive(Debug, Deserialize, Serialize, Clone)] pub struct S3Resource { - #[serde(rename = "bucket")] pub bucket: String, pub region: String, #[serde(rename = "endPoint")] @@ -380,7 +379,9 @@ pub struct S3Settings { pub secret_key: Option, pub endpoint: Option, pub allow_http: Option, // default to true + pub path_style: Option, pub store_logs: Option, + pub port: Option, } #[cfg(feature = "parquet")] @@ -421,8 +422,8 @@ pub async fn build_s3_client_from_settings( access_key, secret_key, use_ssl: !settings.allow_http.unwrap_or(true), - path_style: None, - port: None, + path_style: settings.path_style, + port: settings.port, token: None, }; diff --git a/cli/main.ts b/cli/main.ts index ac9739c044c17..20bad301c0d6c 100644 --- a/cli/main.ts +++ b/cli/main.ts @@ -187,25 +187,27 @@ async function main() { } } -//@ts-ignore -if (esMain.default(import.meta)) { - main(); - // test1(); - // test2(); - // module was not imported but called directly -} - -// function test1() { -// // dnt-shim-ignore deno-lint-ignore no-explicit-any -// const { Deno, process } = globalThis as any; +function isMain() { + // dnt-shim-ignore + const { Deno } = globalThis as any; -// console.log(Deno); -// } + const isDeno = Deno != undefined; -// function test2() { -// const { Deno, process } = globalThis as any; - -// console.log(Deno); -// } + if (isDeno) { + const isMain = import.meta.main; + if (isMain) { + log.warn( + "Using the deno runtime for the Windmill CLI is deprecated, you can now use node: deno uninstall wmill && npm install -g windmill-cli" + ); + } + return isMain; + } else { + //@ts-ignore + return esMain.default(import.meta); + } +} +if (isMain()) { + main(); +} export default command; diff --git a/frontend/src/lib/components/TestConnection.svelte b/frontend/src/lib/components/TestConnection.svelte index 511af5e04809c..ceb7e99987280 100644 --- a/frontend/src/lib/components/TestConnection.svelte +++ b/frontend/src/lib/components/TestConnection.svelte @@ -47,18 +47,36 @@ }, s3: { code: ` -import { S3Client } from "https://deno.land/x/s3_lite_client@0.6.1/mod.ts"; +import * as wmill from "windmill-client" type S3 = object export async function main(s3: S3) { - const s3client = new S3Client(s3); - for await (const obj of s3client.listObjects({ prefix: "/" })) { - console.log(obj); - } + return fetch(process.env["BASE_URL"] + '/api/settings/test_object_storage_config', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + process.env["WM_TOKEN"], + }, + body: JSON.stringify({ + type: "S3", + bucket: s3.bucket, + endpoint: s3.endPoint, + port: s3.port, + allow_http: !s3.useSSL, + access_key: s3.accessKey, + secret_key: s3.secretKey, + path_style: s3.pathStyle, + }), + }).then(async (res) => { + if (!res.ok) { + throw new Error(await res.text()) + } + return res.text() + }) } `, - lang: 'deno', + lang: 'bun', argName: 's3' }, graphql: {