Skip to content

[BEEEP] Client side jobs #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ bitwarden-crypto = { path = "crates/bitwarden-crypto", version = "=1.0.0" }
bitwarden-exporters = { path = "crates/bitwarden-exporters", version = "=1.0.0" }
bitwarden-fido = { path = "crates/bitwarden-fido", version = "=1.0.0" }
bitwarden-generators = { path = "crates/bitwarden-generators", version = "=1.0.0" }
bitwarden-jobs = { path = "crates/bitwarden-jobs", version = "=1.0.0" }
bitwarden-send = { path = "crates/bitwarden-send", version = "=1.0.0" }
bitwarden-sm = { path = "bitwarden_license/bitwarden-sm", version = "=1.0.0" }
bitwarden-ssh = { path = "crates/bitwarden-ssh", version = "=1.0.0" }
Expand Down
2 changes: 2 additions & 0 deletions crates/bitwarden-jobs/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.wasm32-unknown-unknown]
runner = 'wasm-bindgen-test-runner'
27 changes: 27 additions & 0 deletions crates/bitwarden-jobs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "bitwarden-jobs"
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
homepage.workspace = true
repository.workspace = true
license-file.workspace = true
keywords.workspace = true

[features]
wasm = ["dep:js-sys", "dep:tsify-next", "dep:wasm-bindgen"]

[dependencies]
js-sys = { workspace = true, optional = true }
tsify-next = { workspace = true, optional = true }
uuid = { workspace = true }
wasm-bindgen = { workspace = true, optional = true }

[lints]
workspace = true

[dev-dependencies]
serde.workspace = true
trybuild = "1.0.101"
wasm-bindgen-test = "0.3.45"
57 changes: 57 additions & 0 deletions crates/bitwarden-jobs/src/job.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use std::future::Future;

pub struct JobInformation {
pub id: uuid::Uuid,
pub name: String,
pub description: String,
pub trigger: JobTrigger,
pub concurrency: JobConcurrencyProtections,
pub enabled: bool,
}

pub enum JobTrigger {
Interval(String),
Event(JobEventTrigger),
Manual,
}

pub enum JobEventTrigger {
/// Triggered whenever the vault is unlocked and all keys are available.
VaultUnlock,
/// Triggered whenever the vault is synced.
VaultSynced,
/// Triggered whenever the vault is synced and decryptable.
VaultSyncedUnlocked,
/// Triggered whenever a user enters the authenticated state. This can be used either after a successfull login
/// or after a session is restored when the application restarts.
UserAuthenticated,
/// Triggered whenever a user is about to be logged out. The job will block the logout until it is finished,
/// so be careful with long running jobs.
UserLogout,
}

pub enum JobConcurrencyProtections {
/// The job will not run if another instance of the job is already running on another device.
/// from running on other devices. This guarantee can only be made if the device is online, meaning that
/// this job will not run if the current device is offline.
///
/// Note that concurrency protection might no be implemented on a per-job basis, meaning that
/// the job might not run even if the trigger is fired and no other device is running it. For example,
/// the system might assign a "current job runner" to a device and only allow that device to run the job.
/// This means that the job will not run on other devices even if the trigger is fired on them.
SingleInstancePerUser,
/// The job will not run if another instance of the job is already running on the current device.
/// Other devices might run the job at the same time. This job will run even if the device is offline.
SingleInstancePerDevice,
/// The job will always run when triggered.
None,
}

pub enum JobRunError {
JobFailed,
}

pub trait Job {
fn get_information(&self) -> JobInformation;
fn run(&self) -> impl Future<Output = Result<(), JobRunError>>;
}
5 changes: 5 additions & 0 deletions crates/bitwarden-jobs/src/job_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::job::Job;

pub struct JobClient {
jobs: Vec<Box<dyn Job>>,
}
2 changes: 2 additions & 0 deletions crates/bitwarden-jobs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod job;
mod job_client;
Loading