Skip to content
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

Make mysql storage backend a configurable option rather than the default #50

Merged
merged 1 commit into from
Apr 24, 2024
Merged
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
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,16 +39,19 @@ 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"
url = "2.5"
ureq = "2.9"
glob = "0.3"
serde_asn1_der = "0.8"
base64 = "0.22"

[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 @@ -226,13 +226,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
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "storage_mysql")]
extern crate diesel;

pub mod cli;
Expand All @@ -14,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
Loading