Skip to content

Commit

Permalink
migrate more items to new CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Sep 7, 2024
1 parent 6f0af6b commit cfadf6e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 37 deletions.
2 changes: 2 additions & 0 deletions backend/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 1 addition & 10 deletions backend/windmill-api/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DB>,
authed: ApiAuthed,
_authed: ApiAuthed,
Json(test_s3_bucket): Json<ObjectSettings>,
) -> error::Result<String> {
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())));
Expand Down
7 changes: 4 additions & 3 deletions backend/windmill-common/src/s3_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -380,7 +379,9 @@ pub struct S3Settings {
pub secret_key: Option<String>,
pub endpoint: Option<String>,
pub allow_http: Option<bool>, // default to true
pub path_style: Option<bool>,
pub store_logs: Option<bool>,
pub port: Option<u16>,
}

#[cfg(feature = "parquet")]
Expand Down Expand Up @@ -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,
};

Expand Down
38 changes: 20 additions & 18 deletions cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: npm install -g windmill-cli"
);
}
return isMain;
} else {
//@ts-ignore
return esMain.default(import.meta);
}
}
if (isMain()) {
main();
}

export default command;
30 changes: 24 additions & 6 deletions frontend/src/lib/components/TestConnection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,36 @@
},
s3: {
code: `
import { S3Client } from "https://deno.land/x/[email protected]/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: {
Expand Down

0 comments on commit cfadf6e

Please sign in to comment.