Skip to content

Commit

Permalink
adapt websocket triggers to multi-tenant cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Oct 17, 2024
1 parent 8807e99 commit ba5539a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
6 changes: 4 additions & 2 deletions backend/windmill-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use tower_http::{
trace::TraceLayer,
};
use windmill_common::db::UserDB;
use windmill_common::worker::ALL_TAGS;
use windmill_common::worker::{ALL_TAGS, CLOUD_HOSTED};
use windmill_common::{BASE_URL, INSTANCE_NAME};

use crate::scim_ee::has_scim_token;
Expand Down Expand Up @@ -246,7 +246,9 @@ pub async fn run_server(
}
};

websocket_triggers::start_websockets(db.clone(), rsmq).await;
if !*CLOUD_HOSTED {
websocket_triggers::start_websockets(db.clone(), rsmq).await;
}

// build our application with a route
let app = Router::new()
Expand Down
7 changes: 6 additions & 1 deletion backend/windmill-api/src/websocket_triggers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use windmill_common::{
db::UserDB,
error::{self, JsonResult},
utils::{not_found_if_none, paginate, require_admin, Pagination, StripPath},
worker::to_raw_value,
worker::{to_raw_value, CLOUD_HOSTED},
INSTANCE_NAME,
};
use windmill_queue::PushArgsOwned;
Expand Down Expand Up @@ -156,6 +156,11 @@ async fn create_websocket_trigger(
Path(w_id): Path<String>,
Json(ct): Json<NewWebsocketTrigger>,
) -> error::Result<(StatusCode, String)> {
if *CLOUD_HOSTED {
return Err(error::Error::BadRequest(
"Websocket triggers are not supported on multi-tenant cloud, use dedicated cloud or self-host".to_string(),
));
}
require_admin(authed.is_admin, &authed.username)?;

let mut tx = user_db.begin(&authed).await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import type { TriggerContext } from '../triggers'
import { getContext } from 'svelte'
import WebsocketTriggerEditor from './WebsocketTriggerEditor.svelte'
import { isCloudHosted } from '$lib/cloud'
export let isFlow: boolean
export let path: string
Expand Down Expand Up @@ -49,7 +50,11 @@

<div class="flex flex-col gap-4">
{#if !newItem}
{#if $userStore?.is_admin || $userStore?.is_super_admin}
{#if isCloudHosted()}
<Alert title="Not compatible with multi-tenant cloud" type="warning">
Websocket triggers are disabled in the multi-tenant cloud.
</Alert>
{:else if $userStore?.is_admin || $userStore?.is_super_admin}
<Button
on:click={() => wsTriggerEditor?.openNew(isFlow, path)}
variant="border"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
} from '$lib/utils'
import { base } from '$app/paths'
import CenteredPage from '$lib/components/CenteredPage.svelte'
import { Button, Skeleton } from '$lib/components/common'
import { Alert, Button, Skeleton } from '$lib/components/common'
import Dropdown from '$lib/components/DropdownV2.svelte'
import PageHeader from '$lib/components/PageHeader.svelte'
import SharedBadge from '$lib/components/SharedBadge.svelte'
Expand All @@ -28,6 +28,7 @@
import { onDestroy, onMount } from 'svelte'
import WebsocketTriggerEditor from '$lib/components/triggers/WebsocketTriggerEditor.svelte'
import Popover from '$lib/components/Popover.svelte'
import { isCloudHosted } from '$lib/cloud'
type TriggerW = WebsocketTrigger & { canWrite: boolean }
Expand Down Expand Up @@ -216,6 +217,13 @@
New&nbsp;WS trigger
</Button>
</PageHeader>

{#if isCloudHosted()}
<Alert title="Not compatible with multi-tenant cloud" type="warning">
Websocket triggers are disabled in the multi-tenant cloud.
</Alert>
<div class="py-4" />
{/if}
<div class="w-full h-full flex flex-col">
<div class="w-full pb-4 pt-6">
<input type="text" placeholder="Search WS triggers" bind:value={filter} class="search-item" />
Expand Down

0 comments on commit ba5539a

Please sign in to comment.