Skip to content

Commit

Permalink
Make mysql storage backend a configurable option rather than the defa…
Browse files Browse the repository at this point in the history
…ult.

To prevent compilation failures for users who do not require mysql.
  • Loading branch information
wa5i committed Apr 7, 2024
1 parent 54572b4 commit 04ba523
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 8 deletions.
44 changes: 40 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@ env:
CARGO_TERM_COLOR: always

jobs:
unix-test:
unix-default-test:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

unix-mysql-test:
strategy:
matrix:
os:
Expand All @@ -32,12 +47,33 @@ jobs:
- name: init database
run: diesel setup --database-url mysql://root:[email protected]:3306/vault
- name: Build
run: cargo build --verbose
run: cargo build --features storage_mysql --verbose
- name: Run tests
run: cargo test --verbose


windows-test:
windows-default-test:
strategy:
matrix:
os:
- windows-latest
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v3
- run: echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: install openssl
run: vcpkg install openssl:x64-windows-static-md
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

windows-mysql-test:
strategy:
matrix:
os:
Expand Down Expand Up @@ -73,6 +109,6 @@ jobs:
- name: init database
run: diesel setup --database-url mysql://root:[email protected]:3306/vault
- name: Build
run: cargo build --verbose
run: cargo build --features storage_mysql --verbose
- name: Run tests
run: cargo test --verbose
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ as-any = "0.3.1"
pem = "3.0"
chrono = "0.4"
zeroize = { version = "1.7.0", features= ["zeroize_derive"] }
diesel = { version = "2.1.4", features = ["mysql", "r2d2"] }
r2d2 = "0.8.9"
r2d2-diesel = "1.0.0"
diesel = { version = "2.1.4", features = ["mysql", "r2d2"], optional = true }
r2d2 = { version = "0.8.9", optional = true }
r2d2-diesel = { version = "1.0.0", optional = true }
bcrypt = "0.15"

[features]
storage_mysql = ["diesel", "r2d2", "r2d2-diesel"]

[target.'cfg(unix)'.dependencies]
daemonize = "0.5"

Expand Down
2 changes: 2 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,15 @@ pub enum RvError {
///
#[error("Database type is not support now. Please try postgressql or mysql again.")]
ErrDatabaseTypeInvalid,
#[cfg(feature = "storage_mysql")]
#[error("Database connection pool ocurrs errors when creating, {:?}", .source)]
ErrConnectionPoolCreate {
#[from]
source: r2d2::Error,
},
#[error("Database connection info is invalid.")]
ErrDatabaseConnectionInfoInvalid,
#[cfg(feature = "storage_mysql")]
#[error("Failed to execute entry with database, {:?}", .source)]
ErrDatabaseExecuteEntry {
#[from]
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[macro_use]
#[cfg(feature = "storage_mysql")]
extern crate diesel;

pub mod cli;
Expand All @@ -15,6 +15,7 @@ pub mod router;
pub mod shamir;
pub mod storage;
pub mod utils;
#[cfg(feature = "storage_mysql")]
pub mod schema;

/// Exit ok
Expand Down
1 change: 1 addition & 0 deletions src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod barrier;
pub mod barrier_aes_gcm;
pub mod barrier_view;
pub mod physical;
#[cfg(feature = "storage_mysql")]
pub mod mysql;

pub trait Storage {
Expand Down
2 changes: 2 additions & 0 deletions src/storage/physical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde_json::Value;

use crate::errors::RvError;

#[cfg(feature = "storage_mysql")]
use super::mysql::mysql_backend::MysqlBackend;


Expand All @@ -31,6 +32,7 @@ pub fn new_backend(t: &str, conf: &HashMap<String, Value>) -> Result<Arc<dyn Bac
let backend = file::FileBackend::new(conf)?;
Ok(Arc::new(backend))
},
#[cfg(feature = "storage_mysql")]
"mysql" => {
let backend = MysqlBackend::new(conf)?;
Ok(Arc::new(backend))
Expand Down

0 comments on commit 04ba523

Please sign in to comment.