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

Update rustfmt.toml #31

Merged
merged 3 commits into from
Dec 1, 2023
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
27 changes: 25 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,35 @@ env:
CARGO_TERM_COLOR: always

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

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
windows-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
- 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
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ clap = { version = "4.4", features = ["wrap_help", "suggestions"] }
sysexits = { version = "0.7", features = ["std"] }
build-time = "0.1"
hcl-rs = "0.16"
daemonize = "0.5"
actix-web = { version = "4.4", features = ["openssl"] }
actix-tls = "3.1"
actix-rt = "2.9"
Expand All @@ -40,6 +39,9 @@ as-any = "0.3.1"
pem = "3.0"
chrono = "0.4"

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

[dependencies.foreign-types]
version = "0.3.1"

Expand Down
2 changes: 1 addition & 1 deletion bin/rusty_vault.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::process::ExitCode;

use clap::{Command};
use clap::Command;
use rusty_vault::cli;

fn main() -> ExitCode {
Expand Down
27 changes: 12 additions & 15 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
edition = "2021"

# We are going to enable these after switching to nightly tool chain
#comment_width = 100
#binop_separator = "Front"
#format_strings = true
#max_width = 100
#merge_derives = true
#imports_granularity = "Crate"
#newline_style = "Unix"
#merge_imports = true
#normalize_comments = true
#normalize_doc_attributes = true
#reorder_imports = true
#report_fixme = "Always"
#report_todo = "Always"
#trailing_comma = "Vertical"
#use_field_init_shorthand = true
binop_separator = "Front"
format_strings = true
max_width = 120
comment_width = 120
merge_derives = false
reorder_imports = true
use_field_init_shorthand = true
group_imports = "StdExternalCrate"
imports_granularity = "Crate"
newline_style = "Unix"
trailing_comma = "Vertical"
use_small_heuristics = "Max"
38 changes: 16 additions & 22 deletions src/cli/command/server.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
use std::{
env,
fs,
default::Default,
fs::OpenOptions,
env, fs,
path::Path,
sync::{Arc, RwLock}
sync::{Arc, RwLock},
};
use daemonize::Daemonize;
use clap::{ArgMatches};

use actix_web::{middleware, web, App, HttpResponse, HttpServer};
use clap::ArgMatches;
use sysexits::ExitCode;
use actix_web::{
middleware, web, App, HttpResponse, HttpServer
};

use crate::{
http,
errors::RvError,
EXIT_CODE_OK, EXIT_CODE_INSUFFICIENT_PARAMS, EXIT_CODE_LOAD_CONFIG_FAILURE,
cli::config,
storage::{physical, barrier_aes_gcm},
core::Core
core::Core,
errors::RvError,
http,
storage::{barrier_aes_gcm, physical},
EXIT_CODE_INSUFFICIENT_PARAMS, EXIT_CODE_LOAD_CONFIG_FAILURE, EXIT_CODE_OK,
};

pub const WORK_DIR_PATH_DEFAULT: &str = "/tmp/rusty_vault";
Expand Down Expand Up @@ -52,6 +49,7 @@ pub fn main(config_path: &str) -> Result<(), RvError> {
fs::create_dir_all(work_dir.as_str())?;
}

#[cfg(not(windows))]
if config.daemon {
// start daemon
let log_path = format!("{}/rusty_vault.log", work_dir);
Expand All @@ -70,7 +68,7 @@ pub fn main(config_path: &str) -> Result<(), RvError> {
group = config.daemon_group.clone();
}

let log_file = OpenOptions::new()
let log_file = std::fs::OpenOptions::new()
.read(true)
.write(true)
.append(true)
Expand All @@ -79,7 +77,7 @@ pub fn main(config_path: &str) -> Result<(), RvError> {
.open(log_path)
.unwrap();

let daemonize = Daemonize::new()
let daemonize = daemonize::Daemonize::new()
.working_directory(work_dir.as_str())
.user(user.as_str())
.group(group.as_str())
Expand Down Expand Up @@ -108,11 +106,7 @@ pub fn main(config_path: &str) -> Result<(), RvError> {

let barrier = barrier_aes_gcm::AESGCMBarrier::new(Arc::clone(&backend));

let core = Arc::new(RwLock::new(Core {
physical: backend,
barrier: Arc::new(barrier),
..Default::default()
}));
let core = Arc::new(RwLock::new(Core { physical: backend, barrier: Arc::new(barrier), ..Default::default() }));

{
let mut c = core.write()?;
Expand Down Expand Up @@ -149,7 +143,7 @@ pub fn execute(matches: &ArgMatches) -> ExitCode {
println!("server error: {:?}", e);
EXIT_CODE_LOAD_CONFIG_FAILURE
}
}
};
}

return EXIT_CODE_INSUFFICIENT_PARAMS;
Expand Down
6 changes: 3 additions & 3 deletions src/cli/command/status.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::{ArgMatches};
use clap::ArgMatches;
use sysexits::ExitCode;
use crate::{EXIT_CODE_OK, EXIT_CODE_INSUFFICIENT_PARAMS};
use crate::errors::RvError;

use crate::{errors::RvError, EXIT_CODE_INSUFFICIENT_PARAMS, EXIT_CODE_OK};

pub fn main() -> Result<(), RvError> {
println!("status: ok");
Expand Down
94 changes: 45 additions & 49 deletions src/cli/config.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use std::{
fs,
path::Path,
collections::HashMap,
};
use serde::{Serialize, Deserialize, Deserializer};
use serde_json::{Value};
use crate::{
errors::RvError,
};
use std::{collections::HashMap, fs, path::Path};

use serde::{Deserialize, Deserializer, Serialize};
use serde_json::Value;

use crate::errors::RvError;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
Expand Down Expand Up @@ -52,7 +48,7 @@ pub struct Storage {

fn parse_bool_string<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
D: Deserializer<'de>,
D: Deserializer<'de>,
{
let value: Value = Deserialize::deserialize(deserializer)?;
match value {
Expand All @@ -68,7 +64,7 @@ D: Deserializer<'de>,

fn validate_storage<'de, D>(deserializer: D) -> Result<HashMap<String, Storage>, D::Error>
where
D: serde::Deserializer<'de>,
D: serde::Deserializer<'de>,
{
let storage: HashMap<String, Storage> = Deserialize::deserialize(deserializer)?;

Expand All @@ -83,7 +79,7 @@ D: serde::Deserializer<'de>,

fn validate_listener<'de, D>(deserializer: D) -> Result<HashMap<String, Listener>, D::Error>
where
D: serde::Deserializer<'de>,
D: serde::Deserializer<'de>,
{
let listener: HashMap<String, Listener> = Deserialize::deserialize(deserializer)?;

Expand Down Expand Up @@ -191,10 +187,10 @@ fn set_config_type_field(config: &mut Config) -> Result<(), RvError> {

#[cfg(test)]
mod test {
use std::env;
use std::fs;
use std::io::prelude::*;
use std::{env, fs, io::prelude::*};

use go_defer::defer;

use super::*;

fn write_file(path: &str, config: &str) -> Result<(), RvError> {
Expand All @@ -212,8 +208,8 @@ mod test {
let dir = env::temp_dir().join("rusty_vault_config_test");
assert!(fs::create_dir(&dir).is_ok());
defer! (
assert!(fs::remove_dir_all(&dir).is_ok());
);
assert!(fs::remove_dir_all(&dir).is_ok());
);

let file_path = dir.join("config.hcl");
let path = file_path.to_str().unwrap_or("config.hcl");
Expand All @@ -233,14 +229,14 @@ mod test {
pid_file = "/tmp/rusty_vault.pid"
"#;

assert!(write_file(path, hcl_config).is_ok());
assert!(write_file(path, hcl_config).is_ok());

let config = load_config(path);
assert!(config.is_ok());
let hcl_config = config.unwrap();
println!("hcl config: {:?}", hcl_config);
let config = load_config(path);
assert!(config.is_ok());
let hcl_config = config.unwrap();
println!("hcl config: {:?}", hcl_config);

let json_config = r#"{
let json_config = r#"{
"storage": {
"file": {
"path": "./vault/data"
Expand All @@ -257,32 +253,32 @@ mod test {
"pid_file": "/tmp/rusty_vault.pid"
}"#;

let file_path = dir.join("config.json");
let path = file_path.to_str().unwrap_or("config.json");
assert!(write_file(path, json_config).is_ok());
let file_path = dir.join("config.json");
let path = file_path.to_str().unwrap_or("config.json");
assert!(write_file(path, json_config).is_ok());

let config = load_config(path);
assert!(config.is_ok());
let json_config = config.unwrap();
println!("json config: {:?}", json_config);
let config = load_config(path);
assert!(config.is_ok());
let json_config = config.unwrap();
println!("json config: {:?}", json_config);

let hcl_config_value = serde_json::to_value(&hcl_config);
assert!(hcl_config_value.is_ok());
let hcl_config_value: Value = hcl_config_value.unwrap();
let hcl_config_value = serde_json::to_value(&hcl_config);
assert!(hcl_config_value.is_ok());
let hcl_config_value: Value = hcl_config_value.unwrap();

let json_config_value = serde_json::to_value(&json_config);
assert!(json_config_value.is_ok());
let json_config_value: Value = json_config_value.unwrap();
assert_eq!(hcl_config_value, json_config_value);
let json_config_value = serde_json::to_value(&json_config);
assert!(json_config_value.is_ok());
let json_config_value: Value = json_config_value.unwrap();
assert_eq!(hcl_config_value, json_config_value);
}

#[test]
fn test_load_config_dir() {
let dir = env::temp_dir().join("rusty_vault_config_dir_test");
assert!(fs::create_dir(&dir).is_ok());
defer! (
assert!(fs::remove_dir_all(&dir).is_ok());
);
assert!(fs::remove_dir_all(&dir).is_ok());
);

let file_path = dir.join("config1.hcl");
let path = file_path.to_str().unwrap_or("config1.hcl");
Expand All @@ -303,12 +299,12 @@ mod test {
pid_file = "/tmp/rusty_vault.pid"
"#;

assert!(write_file(path, hcl_config).is_ok());
assert!(write_file(path, hcl_config).is_ok());

let file_path = dir.join("config2.hcl");
let path = file_path.to_str().unwrap_or("config2.hcl");
let file_path = dir.join("config2.hcl");
let path = file_path.to_str().unwrap_or("config2.hcl");

let hcl_config = r#"
let hcl_config = r#"
storage "file" {
address = "127.0.0.1:8899"
}
Expand All @@ -321,11 +317,11 @@ mod test {
log_level = "info"
"#;

assert!(write_file(path, hcl_config).is_ok());
assert!(write_file(path, hcl_config).is_ok());

let config = load_config(dir.to_str().unwrap());
assert!(config.is_ok());
let hcl_config = config.unwrap();
println!("hcl config: {:?}", hcl_config);
let config = load_config(dir.to_str().unwrap());
assert!(config.is_ok());
let hcl_config = config.unwrap();
println!("hcl config: {:?}", hcl_config);
}
}
Loading
Loading